Skip to content

Commit 57b3401

Browse files
committed
fix: only show show-branch when commits are truly unpushed
The previous implementation blocked deletion whenever the branch wasn't an ancestor of the default branch, even if all commits were pushed to origin/feature-branch. This forced users to use --force unnecessarily. Now we: 1. First check git log --branches --not --remotes (original behavior) 2. Only if that finds unpushed commits, show the enhanced error This maintains the original safety check (only block truly unpushed commits) while providing better error messaging when it matters.
1 parent 37a58e2 commit 57b3401

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

src/runtime/SSHRuntime.ts

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -985,46 +985,34 @@ 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-
# Get current branch
989-
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
990-
991-
# Get default branch (try origin/HEAD, fallback to main, then master)
992-
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
993-
if [ -z "$DEFAULT" ]; then
994-
if git rev-parse --verify origin/main >/dev/null 2>&1; then
995-
DEFAULT="main"
996-
elif git rev-parse --verify origin/master >/dev/null 2>&1; then
997-
DEFAULT="master"
998-
fi
999-
fi
1000-
1001-
# If we have both branch and default, use show-branch for better output
1002-
if [ -n "$BRANCH" ] && [ -n "$DEFAULT" ]; then
1003-
if git show-branch "$BRANCH" "origin/$DEFAULT" >/dev/null 2>&1; then
1004-
# Check if there are commits not in the default branch
1005-
if ! git merge-base --is-ancestor "$BRANCH" "origin/$DEFAULT" 2>/dev/null; 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-
exit 2
1012-
fi
1013-
else
1014-
# Fallback to git log if show-branch fails
1015-
unpushed=$(git log --branches --not --remotes --oneline)
1016-
if [ -n "$unpushed" ]; then
1017-
echo "$unpushed" | head -10 >&2
1018-
exit 2
988+
# First, check the original condition: any commits not in any remote
989+
unpushed=$(git log --branches --not --remotes --oneline)
990+
if [ -n "$unpushed" ]; then
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"
10191001
fi
10201002
fi
1021-
else
1022-
# Fallback to git log if we can't determine branches
1023-
unpushed=$(git log --branches --not --remotes --oneline)
1024-
if [ -n "$unpushed" ]; then
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
10251013
echo "$unpushed" | head -10 >&2
1026-
exit 2
10271014
fi
1015+
exit 2
10281016
fi
10291017
fi
10301018
exit 0

0 commit comments

Comments
 (0)