Created
November 7, 2014 12:16
-
-
Save stefanv/daa8fc7bae6dc002ad62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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'): | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two things:
print
calls in parens for Python 3 compatibility.upstream
.