Skip to content

Instantly share code, notes, and snippets.

@mislav
Forked from sprsquish/gist:259067
Created December 17, 2009 23:01
Show Gist options
  • Save mislav/259113 to your computer and use it in GitHub Desktop.
Save mislav/259113 to your computer and use it in GitHub Desktop.
git workflow with peer review on topic branches
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 =~ /^ ([\w-]+)/
branch, rest = $1, $'
`git config --bool branch.#{branch}.peer-review`
prefix = $?.success?? '- ' : ' '
puts prefix + branch + rest
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