Skip to content

Instantly share code, notes, and snippets.

@stefanv
Created November 7, 2014 12:16
Show Gist options
  • Save stefanv/daa8fc7bae6dc002ad62 to your computer and use it in GitHub Desktop.
Save stefanv/daa8fc7bae6dc002ad62 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""git-pr: fetch a pull request
git pr NR
git pr NR0 NR1 NR2
git pr NR0 NR1 NR2 -args -to -git-fetch
Adds a new branch "pr/NR"
"""
import subprocess
import sys
if len(sys.argv) < 2:
print "Usage: git-pr NR"
print "Usage: git-pr NR0 NR1 NR2 NR3"
print "Usage: git-pr NR0 NR1 NR2 -args -to -git-fetch"
sys.exit(-1)
opts = [arg for arg in sys.argv[1:] if arg.startswith('-')]
nrs = [int(arg) for arg in sys.argv[1:] if not arg.startswith('-')]
for i, nr in enumerate(nrs):
print "Fetching PR #{0} into branch 'pr/{0}'".format(nr)
cmd = "git fetch origin pull/{0}/head:pr/{0}".format(nr)
out = subprocess.check_output(cmd.split() + opts)
if i != len(nrs) - 1 and not out.endswith('\n'):
print
@blink1073
Copy link

Two things:

  • You need to wrap all your print calls in parens for Python 3 compatibility.
  • According to the scikit-image development-process, the remote name should be upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment