git-codereview: allow changing to a CL

Now 'git change NNNN/PP' can be used to checkout (detached) the git
commit corresponding to the patchset PP of the change NNNN. If the
patchset is omitted, the current (latest) will be used.

Branch names that are only numbers or numbers separated by a slash will
always be understood as refering to CL. This break workflows that were
using numbers as branch names, but this is expected to be uncommon. The
workaround in this case is to use checkout directly.

It gets the commit fetching the specific reference inside origin's
refs/changes/ and check it out. It uses the gerrit API only if
querying the current patchset is needed.

Given that it's easy to mistype the number, change to a CL will show the
subject of the commit it just checked out.

Fixes golang/go#9255.

Change-Id: I01b98f4672051a52b8b9110a41d93f3ffefebaf1
Reviewed-by: Andrew Gerrand <>
Run-TryBot: Andrew Gerrand <>
TryBot-Result: Gobot Gobot <>
3 files changed