Skip to content

Branch with name x/y cannot be created if branch with name x exists #12707

@shunichironomura

Description

@shunichironomura

Version

0.19.5

Operating System

macOS

Distribution Method

dmg (Mac OS - Apple Silicon)

Describe the issue

If there is already a branch with name x and you try to create a branch with name x/y with but branch new x/y, it outputs the following error and the branch creation fails:

❯ but branch new x
✓ Created branch x

❯ but branch new x/y
Error: The ref file "/Users/nomura/tmp/gb-fs-in-branch/.git/refs/heads/x/y" could not be read in full

Caused by:
    Not a directory (os error 20)

I see the same error when creating the branch x/y from GitButler UI.

Note that the branch creation is successful if branch x does not exist:

# Branch `xx` does not exist so it succeeds
❯ but branch new xx/yy
✓ Created branch xx/yy

If you run but teardown and try to create branch x/y with git, it also fails:

❯ git switch -c x/y
fatal: cannot lock ref 'refs/heads/x/y': 'refs/heads/x' exists; cannot create 'refs/heads/x/y'

If you don't create branch x via GitButler, you can create branch x/y:

❯ git init
Initialized empty Git repository in /Users/nomura/tmp/gb-fs-in-branch-git/.git/

❯ git switch -c b
Switched to a new branch 'b'

❯ git switch -c b/a
Switched to a new branch 'b/a'

(Git version 2.53.0)

So I suspect the way GitButler create a branch whose name contains a forward slash / is different from Git, and that causes this difference in behavior.

A similar issue can be found here:

How to reproduce (Optional)

No response

Expected behavior (Optional)

No response

Relevant log output (Optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working🦀gitoxide🦀`gitoxide` might help here

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions