Skip to content

Instantly share code, notes, and snippets.

@blendsdk
Created July 28, 2017 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blendsdk/5e313a9988aa502223b457ee109580fb to your computer and use it in GitHub Desktop.
Save blendsdk/5e313a9988aa502223b457ee109580fb to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
if(count($argv) !== 2) {
die("Need a new branch name\n");
}
$info = pathinfo($argv[0]);
$command = str_replace("git-","",$info["basename"]);
$new_branch = str_replace(array(' ',"\\","\"","\t","\n","\r","-"),'-',$argv[1]);
$current_branch=trim(`git symbolic-ref --short HEAD 2>/dev/null`);
$configFile=getenv("HOME")."/.custom-git-config";
$config = array();
if($current_branch !== "devel" && $current_branch !== "master") {
die("You are not on devel or master branch\n");
}
if(file_exists($configFile)) {
$config = json_decode(file_get_contents($configFile),true);
}
if(!isset($config[$command])) {
$config[$command] = 100;
} else {
$config[$command] = $config[$command] + 1;
}
$branch_name = "$command/{$config[$command]}-{$new_branch}";
file_put_contents($configFile,json_encode($config));
`git checkout -b "$branch_name"`;
echo(`git branch -l`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment