Skip to content

fix(but): improve error message when branch collides by path prefix#14153

Merged
slarse merged 1 commit into
masterfrom
GB-1591/better-error-on-prefix-path-collision
Jun 12, 2026
Merged

fix(but): improve error message when branch collides by path prefix#14153
slarse merged 1 commit into
masterfrom
GB-1591/better-error-on-prefix-path-collision

Conversation

@slarse

@slarse slarse commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

If a branch exists at <path>, and you create a new branch <path>/name, then that collides with the existing branch at <path> due to the need to now create a directory at <path>. The error message generated in that situation used to be very obtuse, and this commit improves upon it to be more clear.

There is an underlying issue in gix where if you do repo.try_find_reference("<path>/name") in that same situation, an error is returned with a NotADirectory kind. This is explicitly asserted inside gix so need to sync with @Byron if this should be changed in gix or if we just work around it here.

We want this nice error message regardless so the code here will probably change minimally regardless.

Edit: I realised this is also a problem for the GUI so we probably need a lower-level fix than this.

Copilot AI review requested due to automatic review settings June 10, 2026 08:17
@linear-code

linear-code Bot commented Jun 10, 2026

Copy link
Copy Markdown

GB-1591

@github-actions github-actions Bot added rust Pull requests that update Rust code CLI The command-line program `but` labels Jun 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves the but branch new UX when a requested branch name collides with an existing branch due to a path-prefix conflict (e.g. A exists and user attempts to create A/new), turning a previously obtuse low-level error into a clear, user-facing message and adding regression coverage.

Changes:

  • Detect NotADirectory from gix reference lookup and convert it into a targeted “collides with existing branch” error.
  • Add a helper to identify the colliding prefix branch for display purposes.
  • Add a CLI test asserting the improved error message for path-prefix collisions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/but/src/args/atoms/branch_arg.rs Adds NotADirectory handling for prefix collisions and computes a display name for the colliding prefix branch.
crates/but/tests/but/command/branch/new.rs Adds a regression test verifying the new collision error message.

Comment thread crates/but/src/args/atoms/branch_arg.rs
Comment thread crates/but/tests/but/command/branch/new.rs
@slarse
slarse force-pushed the GB-1591/better-error-on-prefix-path-collision branch from ea6d870 to d5436ef Compare June 10, 2026 08:20
Copilot AI review requested due to automatic review settings June 10, 2026 08:35
@slarse
slarse force-pushed the GB-1591/better-error-on-prefix-path-collision branch from d5436ef to 71654af Compare June 10, 2026 08:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread crates/but/tests/but/command/branch/new.rs
@slarse
slarse force-pushed the GB-1591/better-error-on-prefix-path-collision branch from 71654af to 86b05d0 Compare June 10, 2026 11:19
Copilot AI review requested due to automatic review settings June 11, 2026 06:10
@slarse
slarse force-pushed the GB-1591/better-error-on-prefix-path-collision branch from 86b05d0 to 2f19334 Compare June 11, 2026 06:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread crates/but/src/args/atoms/branch_arg.rs
Comment thread crates/but/tests/but/command/branch/new.rs
@slarse
slarse force-pushed the GB-1591/better-error-on-prefix-path-collision branch from 2f19334 to ab6cecd Compare June 12, 2026 09:04
If a branch exists at `<path>`, and you create a new branch `<path>/name`, then
that collides with the existing branch at `<path>` due to the need to now
create a directory at `<path>`. The error message generated in that situation
used to be very obtuse, and this commit improves upon it to be more clear.
Copilot AI review requested due to automatic review settings June 12, 2026 09:09
@slarse
slarse force-pushed the GB-1591/better-error-on-prefix-path-collision branch from ab6cecd to 7ec7a4a Compare June 12, 2026 09:09
@slarse
slarse enabled auto-merge June 12, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread crates/but/src/args/atoms/branch_arg.rs
Comment thread crates/but/tests/but/command/branch/new.rs
@slarse
slarse merged commit 0d49ac1 into master Jun 12, 2026
40 checks passed
@slarse
slarse deleted the GB-1591/better-error-on-prefix-path-collision branch June 12, 2026 09:29
@Byron

Byron commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the ping! Indeed, this issue should be fixed in gitoxide and I'm working on it.
When it's available I will make sure the fix here is removed (but not the test).

Byron added a commit to Byron/gitbutler that referenced this pull request Jun 16, 2026
This is also the bases for reverting most of gitbutlerapp#14153
Byron added a commit to Byron/gitbutler that referenced this pull request Jun 16, 2026
The fix now comes from `gix`.
It's clearly a worse error message as it's not tuned in any way,
which makes me wish the `gix-error` crate was already used everywhere
which would have made that easy.
Byron added a commit to Byron/gitbutler that referenced this pull request Jun 16, 2026
The fix now comes from `gix`.
To keep the error message, additional work is needed, but it's
also working on Windows.

In future, `gix` should provide such an error message, it already
saw the conflicting ref and thus could avoid duplicate work (and
reduce complexity here).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI The command-line program `but` rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants