Handling of local branches if a remote branch with the same name exists
Subdirectories
Branches with slashes
Remotes
Overview:
If there is only one remote, this is implicitly used as the "default"
If there is a remote defined as default (via default_remote), this is the "default"
If there is more than one remote and no default, well, there is no default remote
In case we have default remote, everything is easy: That's the remote we use to set up remote tracking branches and pull/push/fetch from.
If there are multiple remotes without a default, the remote will always have to be specified for push/pull/fetch and tracking branches. I guess this is a very rare setup, so it will be fine to emit warnings and point users to default_remote.
[x] Verify the above with e2e tests
[x] Document the behaviour
Remote tracking branches
The desired behaviour is:
The remote tracking branch is always the same name as the local name, except when either:
There is an explicit override with --track
There is a default prefix in the configuration file
When we create a worktree, there are a few different cases to handle:
A local branch exists => use it. If it is set to track a remote branch that does not match the naming, emit a warning, but leave the remote tracking branch alone.
A local branch does not exist, but a remote branch does => use it and set tracking
Neither => Create a new local branch without tracking, except when tracking is configured (track.default = true)
[x] Verify the above with e2e tests
[x] Document the behaviour
Worktrees & Subdirectories
The rule is: Branch name == Worktree name. As a branch name can contain a slash, we cannot really handle subdirectories, as there would be no way to tell a subdirectory and a branch prefix apart. So subdirectories need to be removed.
[x] Remove subdirectory handling from worktrees
[x] Document the behaviour
[x] Make sure that subdirectories are removed together with the subdirectory
Currently, some things are a bit hit-and-miss:
Remotes
Overview:
default_remote
), this is the "default"In case we have default remote, everything is easy: That's the remote we use to set up remote tracking branches and pull/push/fetch from.
If there are multiple remotes without a default, the remote will always have to be specified for push/pull/fetch and tracking branches. I guess this is a very rare setup, so it will be fine to emit warnings and point users to
default_remote
.Remote tracking branches
The desired behaviour is:
--track
When we create a worktree, there are a few different cases to handle:
A local branch exists => use it. If it is set to track a remote branch that does not match the naming, emit a warning, but leave the remote tracking branch alone.
A local branch does not exist, but a remote branch does => use it and set tracking
Neither => Create a new local branch without tracking, except when tracking is configured (
track.default = true
)[x] Verify the above with e2e tests
[x] Document the behaviour
Worktrees & Subdirectories
The rule is: Branch name == Worktree name. As a branch name can contain a slash, we cannot really handle subdirectories, as there would be no way to tell a subdirectory and a branch prefix apart. So subdirectories need to be removed.