Skip to content

Instantly share code, notes, and snippets.

@gf3
Forked from mislav/description.txt
Created December 18, 2009 07:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gf3/259338 to your computer and use it in GitHub Desktop.
Save gf3/259338 to your computer and use it in GitHub Desktop.
Git Workflow
so my workflow is that each ticket gets a branch. Before merging the branch to master
it needs to be peer-reviewed. So sometimes I have a bunch of branches that are off
being reviewed while I work on something else.
Currently when I run "git branch" I see:
[branch 1]
[branch 2]
[branch 3]
*[branch 4]
[branch 5]
So in the case where [branch 1] and [branch 2] are in review I want to be able to mark
them as such. So that I see:
✔[branch 1]
✔[branch 2]
[branch 3]
*[branch 4]
[branch 5]
That way I have a quick overview of the state of each branch I'm working on.
#!/usr/bin/env ruby -wKU
# Usage:
# $ git rbranch [args]
#
# Branches with peer review in progress are rendered with '✔' prefix.
#
args = ARGV.dup
args << '--color' unless args.include?('--no-color')
`git branch #{args.join(' ')}`.split("\n").each do |line|
if line =~ /^ (?:\e\[(?:\d;)?\d{2}m)?([\w-]+)/
branch= $1
`git config --bool branch.#{branch}.peer-review`
prefix = $?.success?? '✔ ' : ' '
puts line.gsub(/^ /, prefix)
else
puts line
end
end
#!/usr/bin/env ruby -wKU
# Usage:
# $ git review [action] [branch]
#
# Action defaults to "start" and branch to current branch.
#
# Examples:
# $ git review
# $ git review end
# $ git review start topic-1
# $ git review end topic-1
#
action, branch = ARGV
action ||= 'start'
branch ||= `git name-rev HEAD`.chomp.sub('HEAD ', '') # current branch
case action
when 'start'
`git config --bool branch.#{branch}.peer-review true`
puts "Marked '#{branch}' for peer review."
when 'end'
`git config --unset branch.#{branch}.peer-review`
puts "Peer review is done on '#{branch}'."
else
$stderr.puts "unknown action #{action}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment