Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Alright, after extensive digging I've found enough docs to create my own script, and here it is:</p> <p>PHP</p> <pre><code> error_reporting(E_ALL); ignore_user_abort(true); function syscall ($cmd, $cwd) { $descriptorspec = array( 1 =&gt; array('pipe', 'w') // stdout is a pipe that the child will write to ); $resource = proc_open($cmd, $descriptorspec, $pipes, $cwd); if (is_resource($resource)) { $output = stream_get_contents($pipes[1]); fclose($pipes[1]); proc_close($resource); return $output; } } if( $HTTP_RAW_POST_DATA &amp;&amp; !empty( $HTTP_RAW_POST_DATA['ref'] ) ){ // pull from master if( preg_match( '(master)', $HTTP_RAW_POST_DATA['ref'] ) ) $result = syscall('git pull origin master', '/var/www/website/directory'); } </code></pre> <p>So, this works perfectly for its purpose. But now I need to rethink the logic and potentially even the philosophy. This methodology will automatically keep the /var/www/website/directory up-to-date with master; however, what about various other branches? I need some methodology in place to be able to view other branches through my web server, so the dev teams can view their work...</p> <p>Here is what I'm thinking:</p> <p>Rather than my code just looking for "master" within the ref section of the post string, I split the post string on the "/" delimiter and pop off the end element:</p> <pre><code> $branch = array_pop( split("/", $HTTP_RAW_POST_DATA['ref']) ); //this will return which branch the post data was sent from </code></pre> <p>Then I check to see if this branch has a working directory within the /var/www/website/directory/, like <code>/var/www/website/directory/master</code>:</p> <pre><code>if( is_dir( "/var/www/website/directory/$branch" ) ){ //check if branch dir exists $result = syscall("git pull origin $branch", "/var/www/website/directory/$branch"); } else { //if branch dir doesn't exist, create it with a clone $result = syscall("git clone ssh://git@git.mydomain.com/sadmicrowave/someproject.git $branch", "/var/www/website/directory"); //change dir to the clone dir, and checkout the branch $result = syscall("git checkout $branch", "/var/www/website/directory/$branch"); } </code></pre> <p>This logic seems relatively solid, just posting it on here to see people's opinions. With this method, a developer can create a new remote branch, and push to it, then the branch will get pulled into the /var/www web directory for viewing.</p> <p>Can anyone think of another way to allow developers to view their dev branches or any recommendations as to how to make this script better?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload