Skip to content

Commit b547f16

Browse files
committed
chore(release): avoid checkout in create-release-branch
This change refactors the create-release-branch subcommand to push the commit SHA directly to the remote branch reference, avoiding checking out the branch locally and changing the working directory state. Tests are updated to match.
1 parent 3ab60b5 commit b547f16

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

tests/tools/private/release/release_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,9 +1241,10 @@ def test_create_release_branch_success(self):
12411241
# Assert
12421242
self.assertEqual(result, 0)
12431243
self.mock_git.fetch.assert_called_once_with("my-remote")
1244-
self.mock_git.checkout.assert_any_call("abcdef12")
1245-
self.mock_git.checkout.assert_any_call("release/2.0", create_branch=True)
1246-
self.mock_git.push.assert_called_once_with("my-remote", "release/2.0")
1244+
self.mock_git.checkout.assert_not_called()
1245+
self.mock_git.push.assert_called_once_with(
1246+
"my-remote", "abcdef12:refs/heads/release/2.0"
1247+
)
12471248

12481249
self.mock_gh.update_issue_body.assert_called_once()
12491250
call_args = self.mock_gh.update_issue_body.call_args[0]

tools/private/release/create_release_branch.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,13 @@ def cmd_create_release_branch(args):
4242
commit_sha = state["prepare_release"]["commit"]
4343
print(f"Cutting branch {branch_name} from commit {commit_sha}...")
4444

45-
# Create and push branch
45+
# Create and push branch without affecting local checkout
4646
git.fetch(args.remote)
47-
git.checkout(commit_sha)
48-
49-
if not git.branch_exists(branch_name):
50-
git.checkout(branch_name, create_branch=True)
51-
else:
52-
git.checkout(branch_name)
53-
git.merge(commit_sha, ff_only=True)
54-
55-
git.push(args.remote, branch_name)
56-
print(f"Successfully pushed branch {branch_name} to {args.remote}")
47+
ref_spec = f"{commit_sha}:refs/heads/{branch_name}"
48+
git.push(args.remote, ref_spec)
49+
print(
50+
f"Successfully pushed branch {branch_name} pointing to {commit_sha} to {args.remote}"
51+
)
5752

5853
# Update tracking issue checklist
5954
print("Updating tracking issue checklist...")

0 commit comments

Comments
 (0)