@@ -14,41 +14,46 @@ def cherry_pick(commit_sha1, branches): |
14 | 14 | if not branches: |
15 | 15 | raise ValueError("at least one branch is required") |
16 | 16 |
|
17 | | - for b in branches: |
18 | | - click.echo(f"branch to backport: '{b}'") |
19 | | - click.echo(f"checkout the branch sha {commit_sha1[:7]}") |
| 17 | + for branch in branches: |
| 18 | + click.echo(f"Now backporting '{commit_sha1}' into '{branch}'") |
20 | 19 |
|
21 | 20 | # git checkout -b 61e2bc7-3.5 upstream/3.5 |
22 | | - cmd = f"git checkout -b {commit_sha1[:7]}-{b} {upstream}/{b}" |
| 21 | + cmd = f"git checkout -b {commit_sha1[:7]}-{branch} {upstream}/{branch}" |
23 | 22 | run_cmd(cmd) |
24 | 23 |
|
25 | 24 | cmd = f"git cherry-pick -x {commit_sha1}" |
26 | | - run_cmd(cmd) |
27 | | - |
28 | | - cmd = f"git push origin {commit_sha1[:7]}-{b}" |
29 | | - run_cmd(cmd) |
| 25 | + if run_cmd(cmd): |
| 26 | + cmd = f"git push origin {commit_sha1[:7]}-{branch}" |
| 27 | + if not run_cmd(cmd): |
| 28 | + click.echo(f"Failed to push to origin :(") |
| 29 | + else: |
| 30 | + click.echo(f"Failed to cherry-pick {commit_sha1} into {branch} :(") |
30 | 31 |
|
31 | 32 | cmd = "git checkout master" |
32 | 33 | run_cmd(cmd) |
33 | 34 |
|
34 | | - cmd = f"git branch -D {commit_sha1[:7]}-{b}" |
| 35 | + cmd = f"git branch -D {commit_sha1[:7]}-{branch}" |
35 | 36 | run_cmd(cmd) |
| 37 | + click.echo(f"branch {commit_sha1[:7]}-{branch} has been deleted.") |
36 | 38 |
|
37 | 39 |
|
38 | 40 | def get_git_upstream_remote(): |
39 | 41 | """Get the remote name to use for upstream branches |
40 | 42 | Uses "upstream" if it exists, "origin" otherwise |
41 | 43 | """ |
42 | 44 | cmd = "git remote get-url upstream" |
43 | | - try: |
44 | | - run_cmd(cmd) |
45 | | - except subprocess.CalledProcessError: |
| 45 | + if run_cmd(cmd): |
46 | 46 | return "origin" |
47 | | - return "upstream" |
| 47 | + else: |
| 48 | + return "upstream" |
48 | 49 |
|
49 | 50 |
|
50 | 51 | def run_cmd(cmd): |
51 | | - subprocess.check_output(cmd.split()) |
| 52 | + try: |
| 53 | + subprocess.check_output(cmd.split()) |
| 54 | + except subprocess.CalledProcessError: |
| 55 | + return False |
| 56 | + return True |
52 | 57 |
|
53 | 58 |
|
54 | 59 | if __name__ == '__main__': |
|