Skip to content
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
10 changes: 7 additions & 3 deletions tests/tools/private/release/release_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ def setUp(self):
self.mock_get_latest_version = patch(
"tools.private.release.utils.get_latest_version"
).start()
self.mock_get_current_branch = patch(
"tools.private.release.git.get_current_branch"
).start()
self.mock_get_current_branch.return_value = "main"
self.addCleanup(patch.stopall)

def test_no_markers(self):
Expand Down Expand Up @@ -825,7 +829,7 @@ def test_prepare_use_associated_pr_from_tracking_issue(
self.mock_git.checkout.assert_called_once_with("prepare-2.0.0")
self.mock_git.commit.assert_not_called()
self.mock_git.push.assert_called_once_with(
"origin", "prepare-2.0.0", set_upstream=True
"origin", "prepare-2.0.0", set_upstream=True, force=True
)
self.mock_gh.get_open_pr.assert_called_once_with("prepare-2.0.0")
self.mock_gh.create_pr.assert_not_called() # Should NOT create a new PR
Expand Down Expand Up @@ -855,7 +859,7 @@ def test_prepare_create_pr_when_none_associated(self, mock_replace, mock_changel
self.mock_git.checkout.assert_called_once_with("prepare-2.0.0")
self.mock_git.commit.assert_not_called()
self.mock_git.push.assert_called_once_with(
"origin", "prepare-2.0.0", set_upstream=True
"origin", "prepare-2.0.0", set_upstream=True, force=True
)
self.mock_gh.get_open_pr.assert_called_once_with("prepare-2.0.0")
self.mock_gh.create_pr.assert_called_once_with("2.0.0", 123)
Expand Down Expand Up @@ -886,7 +890,7 @@ def test_prepare_reuse_existing_pr(self, mock_replace, mock_changelog):
self.mock_git.checkout.assert_called_once_with("prepare-2.0.0")
self.mock_git.commit.assert_not_called()
self.mock_git.push.assert_called_once_with(
"origin", "prepare-2.0.0", set_upstream=True
"origin", "prepare-2.0.0", set_upstream=True, force=True
)
self.mock_gh.get_open_pr.assert_called_once_with("prepare-2.0.0")
self.mock_gh.create_pr.assert_not_called()
Expand Down
13 changes: 6 additions & 7 deletions tools/private/release/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ def commit(message, amend=False, no_edit=False):
run_cmd(*cmd, capture_output=False)


def push(remote, ref, set_upstream=False):
def push(remote, ref, set_upstream=False, force=False):
"""Pushes a reference to a remote repository."""
cmd = ["git", "push"]
if set_upstream:
cmd.append("-u")
cmd.append("--set-upstream")
if force:
cmd.append("--force")
Comment thread
rickeylev marked this conversation as resolved.
cmd.extend([remote, ref])
run_cmd(*cmd, capture_output=False)

Expand Down Expand Up @@ -128,8 +130,5 @@ def get_tags_at_head():


def get_current_branch():
"""Returns the current git branch name, or None if not in a git repo."""
try:
return run_cmd("git", "rev-parse", "--abbrev-ref", "HEAD")
except subprocess.CalledProcessError:
return None
"""Returns the current git branch name."""
return run_cmd("git", "rev-parse", "--abbrev-ref", "HEAD")
Comment thread
rickeylev marked this conversation as resolved.
3 changes: 2 additions & 1 deletion tools/private/release/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def cmd_prepare(args):
print("No files modified by the release tool. Nothing to commit.")

print(f"Pushing branch {branch_name} to origin...")
git.push("origin", branch_name, set_upstream=True)
# Force push to overwrite the remote branch if it already exists (e.g. from a previous run)
git.push("origin", branch_name, set_upstream=True, force=True)

# --- Create PR ---
# Determine if we need to create a PR or reuse an existing one
Expand Down