Skip to content

Commit 1aec053

Browse files
authored
🤖 fix: use git show-branch for clearer SSH workspace force delete errors (#530)
## Problem When attempting to delete SSH workspaces with unpushed commits, the current error message uses `git log --branches --not --remotes` which just lists commits without context. This is especially confusing in squash-merge workflows where feature branch commits never appear in main, so they always show as "unpushed" even after the PR is merged. ## Solution Replace the git log command with `git show-branch <current-branch> origin/<default-branch>` to show the relationship between branches visually. **Before:** ``` 5d307e9 feat: add feature work 2 5e195dd feat: add feature work 1 ``` **After:** ``` Branch status compared to origin/main: * [feature-branch] feat: add feature work 2 ! [origin/main] feat: add all feature work (squashed) -- * [origin/main] feat: add all feature work (squashed) + [feature-branch] feat: add feature work 2 + [feature-branch^] feat: add feature work 1 +* [origin/main^] Initial commit Note: If your PR was squash-merged, these commits are already in origin/main and safe to delete. ``` The `+`, `*`, and `+*` markers clearly show which commits are in which branch, making it immediately obvious when dealing with a squash-merge scenario. ## Implementation - Detects default branch using `git symbolic-ref refs/remotes/origin/HEAD` with fallbacks to main/master - Uses `git show-branch` to display branch relationships - Falls back to original `git log` command when: - No remote branches exist - Default branch cannot be determined - show-branch fails for any reason This ensures backward compatibility while providing better UX in the common case. ## Testing All existing integration tests pass, including the test that validates error messages contain commit information. _Generated with `cmux`_
1 parent eb177d4 commit 1aec053

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

‎src/runtime/SSHRuntime.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,33 @@ export class SSHRuntime implements Runtime {
985985
cd ${shescape.quote(deletedPath)} || exit 1
986986
git diff --quiet --exit-code && git diff --quiet --cached --exit-code || exit 1
987987
if git remote | grep -q .; then
988+
# First, check the original condition: any commits not in any remote
988989
unpushed=$(git log --branches --not --remotes --oneline)
989990
if [ -n "$unpushed" ]; then
990-
echo "$unpushed" | head -10 >&2
991+
# Get current branch for better error messaging
992+
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
993+
994+
# Get default branch (try origin/HEAD, fallback to main, then master)
995+
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
996+
if [ -z "$DEFAULT" ]; then
997+
if git rev-parse --verify origin/main >/dev/null 2>&1; then
998+
DEFAULT="main"
999+
elif git rev-parse --verify origin/master >/dev/null 2>&1; then
1000+
DEFAULT="master"
1001+
fi
1002+
fi
1003+
1004+
# If we have both branch and default, use show-branch for better output
1005+
if [ -n "$BRANCH" ] && [ -n "$DEFAULT" ] && git show-branch "$BRANCH" "origin/$DEFAULT" >/dev/null 2>&1; then
1006+
echo "Branch status compared to origin/$DEFAULT:" >&2
1007+
echo "" >&2
1008+
git show-branch "$BRANCH" "origin/$DEFAULT" 2>&1 | head -20 >&2
1009+
echo "" >&2
1010+
echo "Note: If your PR was squash-merged, these commits are already in origin/$DEFAULT and safe to delete." >&2
1011+
else
1012+
# Fallback to just showing the commit list
1013+
echo "$unpushed" | head -10 >&2
1014+
fi
9911015
exit 2
9921016
fi
9931017
fi

0 commit comments

Comments
 (0)