Introducing Git-Goggles

Git-Goggles: A series of Git utilities to streamline working with remote branches and reviewing code.

The development team I am in at PBS has adopted a new methodology over the last few months that includes using Git, frequent (2 weeks) release cycles and rigorous code reviews. We spend a reasonable amount of time reviewing every iteration since every line of code gets critiqued by at least 2 members of the team before it gets pushed to production.

We also have a lot of branches. Since git makes branching so inexpensive and easy to manage, we use them to group tasks by functional area. We generally have in between 10 to 15 branches at once that regularly get merged into our master repo, which is the production code.

What is tricky in all this is keeping track of what code still needs to be reviewed versus what is good to go. We wanted a way to get both a nice visual, tabulated view of the state of our branches along with their status from a code review standpoint. It was to scratch that itch that our team lead, Nowell Strite, created git-goggles. The project was open sourced last week under the MIT license.

Here's a demonstration of git-goggles using a basic scenario that utilizes this type of workflow. The goal here is to push a new piece of code to a production repository, while making sure that it has been reviewed and that the branches are merged in.

First I create a new repo, a test file, and push it to github.

$ mkdir demo
$ cd demo
$ git init
$ echo "file1" > file1
$ git add file1
$ git commit -m "initial"
$ git remote add origin git@github.com:teebes/demo.git
$ git push origin master
$ git push origin master:refs/heads/staging
$ git branch --track staging origin/staging
$ git co staging
$ git goggles

I then introduce a code change and commit. The table shows that 1 commit has not been reviewed, and that I need to push the change to origin.

$ echo "file2" > file2
$ git add file2
$ git commit -m "added second file"
$ git goggles

$ git push
$ git goggles

After pushing, the 'Push' column now has a green checkmark instead of the red X.

I start the code review, which brings up a diff between the development branch (staging) and the production branch (master). Once the review is complete, running git-goggles again shows that there is now no unreviewed code. Also, the status of the staging branch has changed to 'MERGE', which indicates that those changes still need to be merged back into the production branch.

$ git goggles codereview
diff --git a/file2 b/file2
new file mode 100644
index 0000000..6c493ff
--- /dev/null
+++ b/file2
@@ -0,0 +1 @@
+file2

[ … code changes happen …]

$ git goggles codereview complete
Counting objects: 1, done.
Writing objects: 100% (1/1), 194 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@github.com:teebes/demo.git
 * [new tag]         codereview--staging -> codereview--staging
Created tag codereview--staging
Already on 'staging'
Switched back to staging branch.

$ git goggles

Now staging is ready for production and therefore gets merged back into master.

$ git co master
$ git merge staging
$ git push

The status column now reads 'DONE', showing that no further action needs to be taken.

Any subsequent pushed changes to the staging branch will change its status to 'REVIEW', and the codereview command will bring up the diff since the last review.

blog comments powered by Disqus

Twitter

Jan 25 - Registered for PyCon 2012. Woot! #fb

Jan 09 - @bsirach I identified myself to Siri as "Teebow Morel Lorset", it's what gets my name butchered the least

Jan 07 - @justincbeck @bsirach @andrewroycarter One more intern joke for Andrew! In a couple years you can have a stand-up routine for every new hire