Bug
When creating a session targeting a git repository that has been initialized (git init) but has no commits yet, the session creation fails with:
Checking out master...
Branch "master" does not exist. Pass createBranch to create it.
Root Cause
In server/git-utils.ts, checkoutOrCreateBranch() runs git checkout <branch> which fails on empty repos because the branch doesn't technically exist yet (it's an "unborn" branch — HEAD points to refs/heads/master symbolically, but no commit backs it).
Additionally, getRepoInfo() uses git rev-parse --abbrev-ref HEAD which fails on unborn branches and falls back to "HEAD", causing the currentBranch !== body.branch check to always be true — so it always attempts the checkout even though we're already on the intended branch.
Steps to Reproduce
- Create an empty git repo:
mkdir test && cd test && git init
- Open Companion and create a session pointing to this directory
- Session creation fails at the "Checking out master..." step
Proposed Fix
getRepoInfo(): Fall back to git symbolic-ref --short HEAD when rev-parse --abbrev-ref HEAD fails — this correctly returns the unborn branch name (e.g. master or main)
checkoutOrCreateBranch(): Detect empty repos (no commits) early. If the requested branch matches the current unborn branch, return successfully. If a different branch is requested, use git checkout --orphan <branch> instead of regular checkout.
Environment
- Companion v0.72.0
- Repo:
git init with files but zero commits
- Branch:
master (default from git init)
Bug
When creating a session targeting a git repository that has been initialized (
git init) but has no commits yet, the session creation fails with:Root Cause
In
server/git-utils.ts,checkoutOrCreateBranch()runsgit checkout <branch>which fails on empty repos because the branch doesn't technically exist yet (it's an "unborn" branch — HEAD points torefs/heads/mastersymbolically, but no commit backs it).Additionally,
getRepoInfo()usesgit rev-parse --abbrev-ref HEADwhich fails on unborn branches and falls back to"HEAD", causing thecurrentBranch !== body.branchcheck to always be true — so it always attempts the checkout even though we're already on the intended branch.Steps to Reproduce
mkdir test && cd test && git initProposed Fix
getRepoInfo(): Fall back togit symbolic-ref --short HEADwhenrev-parse --abbrev-ref HEADfails — this correctly returns the unborn branch name (e.g.masterormain)checkoutOrCreateBranch(): Detect empty repos (no commits) early. If the requested branch matches the current unborn branch, return successfully. If a different branch is requested, usegit checkout --orphan <branch>instead of regular checkout.Environment
git initwith files but zero commitsmaster(default fromgit init)