Created
October 13, 2009 23:50
-
-
Save lox/209677 to your computer and use it in GitHub Desktop.
git-recent-branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
## git-recent-branches: shows all branches, sorted by the most recently updated | |
## git-recent-branches Copyright 2009 Lachlan Donald <[email protected]>. | |
$verbose = in_array('-v',$argv); | |
$arg = in_array('-a',$argv) ? '-a' : ''; | |
$branches = array(); | |
// build list of branches | |
foreach(explode("\n",`git branch $arg -v`) as $branchline) | |
{ | |
if($tokens = array_filter(preg_split("/\s+/",trim($branchline,' *'),3))) | |
{ | |
$tokens[] = trim(`git show --pretty=format:"%ct" $tokens[1] | head -n1`); | |
$branches[] = $tokens; | |
} | |
} | |
// sort by timestamp | |
usort($branches, create_function('$a,$b','return strcmp($b[3], $a[3]);')); | |
// print out | |
foreach($branches as $branch) | |
{ | |
if($verbose) | |
{ | |
printf(" %-50s %s %s %s\n", $branch[0], $branch[1], date('Y-m-d', $branch[3]), $branch[2]); | |
} | |
else | |
{ | |
printf(" %-50s\n", $branch[0]); | |
} | |
} | |
// and llamas... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment