GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — push to origin when cherry-pick succeeded (#7) · python/core-workflow@ffeb832

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cherry_picker.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cherry_picker.py‎

Copy file name to clipboardExpand all lines: cherry_picker.py
+19-14Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,46 @@ def cherry_pick(commit_sha1, branches):
1414
if not branches:
1515
raise ValueError("at least one branch is required")
1616

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}'")
2019

2120
# 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}"
2322
run_cmd(cmd)
2423

2524
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} :(")
3031

3132
cmd = "git checkout master"
3233
run_cmd(cmd)
3334

34-
cmd = f"git branch -D {commit_sha1[:7]}-{b}"
35+
cmd = f"git branch -D {commit_sha1[:7]}-{branch}"
3536
run_cmd(cmd)
37+
click.echo(f"branch {commit_sha1[:7]}-{branch} has been deleted.")
3638

3739

3840
def get_git_upstream_remote():
3941
"""Get the remote name to use for upstream branches
4042
Uses "upstream" if it exists, "origin" otherwise
4143
"""
4244
cmd = "git remote get-url upstream"
43-
try:
44-
run_cmd(cmd)
45-
except subprocess.CalledProcessError:
45+
if run_cmd(cmd):
4646
return "origin"
47-
return "upstream"
47+
else:
48+
return "upstream"
4849

4950

5051
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
5257

5358

5459
if __name__ == '__main__':

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.