Skip to content

Instantly share code, notes, and snippets.

@forthxu
Created August 14, 2015 10:22
Show Gist options
  • Select an option

  • Save forthxu/70b8b11435b1cf4e2806 to your computer and use it in GitHub Desktop.

Select an option

Save forthxu/70b8b11435b1cf4e2806 to your computer and use it in GitHub Desktop.
git自助切换项目分支
<?php
// http://hostname:82/gitbranch.php
$root_path = '/workspace/www/';
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="keywords" content="">
<meta name="description" content="">
<title>项目分支管理</title>
<style>
</style>
</head>
<body>
<div id="wrapper">
<div id="container">
<div id="header">
<div id="top">
</div>
<div id="head">
</div>
<div id="nav">
</div>
</div>
<div id="body">
<div class="wp">
<?php
if(isset($_POST['repo']) && isset($_POST['branch'])){
echo "处理结果:";
exec('ls -F -t '.$root_path.' | grep "/$"',$output,$retval);
if(in_array($_POST['repo'].'/',$output)){
exec('cd '.$root_path.$_POST['repo'].'/ && git branch',$git_branchs,$r);
if(in_array($_POST['branch'],$git_branchs)){
system('cd '.$root_path.$_POST['repo'].'/ && git checkout '.$_POST['branch'].' && git fetch && git pull',$retval);
}
}
}
exec('ls -F -t '.$root_path.' | grep "/$"',$output,$retval);
if($retval==0):
foreach($output as $repo):
$git_branchs=array();
exec('cd '.$root_path.$repo.' && git branch -v',$git_branchs,$r);
if($r==0):
?>
<p>
<form action="" method="post">
<fieldset>
<legend><?php echo trim($repo,'/'); ?> 项目</legend>
<br />
当前分支:
<select name="branch">
<?php foreach($git_branchs as $git_branch): ?>
<option value="<?php echo strstr(trim($git_branch," *"),' ',true); ?>"<?php if(0===strpos($git_branch,'*'))echo ' selected=selected' ;?>><?php echo $git_branch; ?></option>
<?php endforeach; ?>
</select>
<br /><br />
<input type="hidden" name="repo" value="<?php echo trim($repo,'/'); ?>" />
<input type="submit" value="更改分支" />
</fieldset>
</form>
</p>
<?php
endif;
endforeach;
endif;
?>
</div>
</div>
<div id="footer">
<div class="wp">
</div>
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment