Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of workflow branch #581

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,19 +514,24 @@ def prep_git(ref, branch, repo, auth, username, url):
if not checkout_exists:
util.run(f"git remote add origin {url}")

branch = branch or util.get_default_branch()
ref = ref or ""

# Make sure we have *all* tags
util.run(f"{util.GIT_FETCH_CMD} --tags --force")

# Handle the ref
ref = ref or ""
if ref.startswith("refs/pull/"):
pull = ref[len("refs/pull/") :]
ref_alias = f"refs/pull/{pull}"
elif ref.startswith("refs/heads/") and not branch:
branch = ref[len("refs/heads/") :]
util.run(f"git fetch origin {branch}")
ref = None
else:
ref = None

# Handle the branch.
branch = branch or util.get_default_branch()

# Reuse existing branch if possible
if ref:
util.run(f"{util.GIT_FETCH_CMD} +{ref}:{ref_alias}")
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ def test_prep_git_tag(py_package, runner):
assert util.get_branch() == tag, util.get_branch()


def test_prep_git_ref_branch(py_package, runner):
branch = "ref-branch"
util.run(f"git checkout -b {branch} origin/foo")
result = runner(
["prep-git", "--git-url", py_package],
env=dict(GITHUB_ACTIONS="", RH_REF=f"refs/heads/{branch}"),
)

log = get_log()
assert "before-prep-git" not in log
assert "after-prep-git" in log

os.chdir(util.CHECKOUT_NAME)
assert util.get_branch() == branch, util.get_branch()


def test_prep_git_slashes(py_package, runner):
branch = "a/b/c"
util.run(f"git checkout -b {branch} foo")
Expand Down
Loading