Skip to content

Commit 499a44e

Browse files
committed
fix: prefer main/master over origin/HEAD for squash detection
When a bare repo is cloned from a feature branch, origin/HEAD points to that feature branch. This caused the squash-merge detection to compare against the wrong branch. Now we prefer origin/main or origin/master over origin/HEAD since those are almost always the actual default branches for squash merges.
1 parent 0ef5f48 commit 499a44e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/node/runtime/SSHRuntime.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,14 +1087,15 @@ export class SSHRuntime implements Runtime {
10871087
# Get current branch for better error messaging
10881088
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
10891089
1090-
# Get default branch (try origin/HEAD, fallback to main, then master)
1091-
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
1092-
if [ -z "$DEFAULT" ]; then
1093-
if git rev-parse --verify origin/main >/dev/null 2>&1; then
1094-
DEFAULT="main"
1095-
elif git rev-parse --verify origin/master >/dev/null 2>&1; then
1096-
DEFAULT="master"
1097-
fi
1090+
# Get default branch (prefer main/master over origin/HEAD since origin/HEAD
1091+
# might point to a feature branch in some setups)
1092+
if git rev-parse --verify origin/main >/dev/null 2>&1; then
1093+
DEFAULT="main"
1094+
elif git rev-parse --verify origin/master >/dev/null 2>&1; then
1095+
DEFAULT="master"
1096+
else
1097+
# Fallback to origin/HEAD if main/master don't exist
1098+
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
10981099
fi
10991100
11001101
# Check for squash-merge: if all changed files match origin/$DEFAULT, content is merged

tests/ipcMain/removeWorkspace.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,8 @@ describeIntegration("Workspace deletion integration tests", () => {
862862
`git config user.name "Test User" && ` +
863863
// Checkout main (or master, depending on git version)
864864
`(git checkout main 2>/dev/null || git checkout master) && ` +
865-
// Create squash commit with same content
866-
`printf '%s' '${featureContent.output.trim().replace(/'/g, "'\\''")}' > feature.txt && ` +
865+
// Create squash commit with same content (use printf '%s\n' to match echo's newline)
866+
`printf '%s\\n' '${featureContent.output.trim().replace(/'/g, "'\\''")}' > feature.txt && ` +
867867
`git add feature.txt && ` +
868868
`git commit -m "Squash: Feature commits" && ` +
869869
`git push origin HEAD`

0 commit comments

Comments
 (0)