Skip to content

Commit 76ce4aa

Browse files
authored
Fix handling of workflow branch (#581)
1 parent 2fc7de9 commit 76ce4aa

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

jupyter_releaser/lib.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,24 @@ def prep_git(ref, branch, repo, auth, username, url):
514514
if not checkout_exists:
515515
util.run(f"git remote add origin {url}")
516516

517-
branch = branch or util.get_default_branch()
518-
ref = ref or ""
519-
520517
# Make sure we have *all* tags
521518
util.run(f"{util.GIT_FETCH_CMD} --tags --force")
522519

523520
# Handle the ref
521+
ref = ref or ""
524522
if ref.startswith("refs/pull/"):
525523
pull = ref[len("refs/pull/") :]
526524
ref_alias = f"refs/pull/{pull}"
525+
elif ref.startswith("refs/heads/") and not branch:
526+
branch = ref[len("refs/heads/") :]
527+
util.run(f"git fetch origin {branch}")
528+
ref = None
527529
else:
528530
ref = None
529531

532+
# Handle the branch.
533+
branch = branch or util.get_default_branch()
534+
530535
# Reuse existing branch if possible
531536
if ref:
532537
util.run(f"{util.GIT_FETCH_CMD} +{ref}:{ref_alias}")

tests/test_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ def test_prep_git_tag(py_package, runner):
6060
assert util.get_branch() == tag, util.get_branch()
6161

6262

63+
def test_prep_git_ref_branch(py_package, runner):
64+
branch = "ref-branch"
65+
util.run(f"git checkout -b {branch} origin/foo")
66+
result = runner(
67+
["prep-git", "--git-url", py_package],
68+
env=dict(GITHUB_ACTIONS="", RH_REF=f"refs/heads/{branch}"),
69+
)
70+
71+
log = get_log()
72+
assert "before-prep-git" not in log
73+
assert "after-prep-git" in log
74+
75+
os.chdir(util.CHECKOUT_NAME)
76+
assert util.get_branch() == branch, util.get_branch()
77+
78+
6379
def test_prep_git_slashes(py_package, runner):
6480
branch = "a/b/c"
6581
util.run(f"git checkout -b {branch} foo")

0 commit comments

Comments
 (0)