Skip to content

Commit

Permalink
Merge pull request #7044 from freedomofpress/backport-remote
Browse files Browse the repository at this point in the history
added 'remote' option to backport script
  • Loading branch information
legoktm authored Oct 27, 2023
2 parents bf90206 + b3ffb22 commit f484448
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions utils/backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import sys

parser = argparse.ArgumentParser(description="Backport a PR")
parser.add_argument("pr", type=int)
parser.add_argument("version")
parser.add_argument("pr", type=int, help="the # of the PR to backport")
parser.add_argument("version", help="the release version to target with the backport")
parser.add_argument("remote", default="origin", help="the git remote to use (defaults to origin)")
args = parser.parse_args()

title = json.loads(
Expand All @@ -27,12 +28,13 @@
print(f'Backporting {len(commits)} commits from "{title}"')
branch = f"backport-{args.pr}"
base = f"release/{args.version}"
subprocess.check_call(["git", "fetch", "origin"])
subprocess.check_call(["git", "checkout", "-b", branch, f"origin/{base}"])
remote = args.remote
subprocess.check_call(["git", "fetch", remote])
subprocess.check_call(["git", "checkout", "-b", branch, f"{remote}/{base}"])
subprocess.check_call(["git", "cherry-pick", "-x"] + [commit["sha"] for commit in commits])
if input("OK to push and create PR? [y/N]").lower() != "y":
sys.exit()
subprocess.check_call(["git", "push", "-u", "origin", branch])
subprocess.check_call(["git", "push", "-u", remote, branch])
body = f"""\
## Status
Expand Down

0 comments on commit f484448

Please sign in to comment.