Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

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

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Replace 'git log --branches --not --remotes' with 'git show-branch' to
provide clearer context when attempting to delete SSH workspaces with
unpushed commits.

The new output shows the relationship between the feature branch and
the default branch (main/master), making it immediately clear when
commits have been squash-merged. This addresses confusion in
squash-merge workflows where commits appear 'unpushed' even after
the PR is merged.

**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 implementation falls back to the 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.

_Generated with `cmux`_
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.
@ammar-agent ammar-agent force-pushed the feat-force-delete-error branch from 2fc34e9 to 57b3401 Compare November 7, 2025 16:24
@ammario ammario enabled auto-merge November 7, 2025 16:28
@ammario ammario added this pull request to the merge queue Nov 7, 2025
Merged via the queue into main with commit 1aec053 Nov 7, 2025
13 checks passed
@ammario ammario deleted the feat-force-delete-error branch November 7, 2025 16:42
ibetitsmike pushed a commit that referenced this pull request Nov 7, 2025
…ors (#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`_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants