git-branchless
git-branchless copied to clipboard
`.git/branchless/config` "defaults" override config set with `git config`.
Description of the bug
% git config branchless.core.mainBranch origin/HEAD
% git config branchless.core.mainBranch
master
% git config --show-origin --show-scope branchless.core.mainBranch
local file:.git/branchless/config master
Expected behavior
When I ran branchless I got the warning:
The main branch "master" could not be found in your repository at path: "/home/kevincox/p/feedmail/.git/". These branches exist: [...] Either create it, or update the main branch setting by running:
git config branchless.core.mainBranch <branch>
I expected running that command would fix the issue.
Actual behavior
The git config command is effectively ignored because the extra config file overrides it.
Version of git-branchless
git-branchless 0.3.10
Version of git
git version 2.35.1
Version of rustc
No response
Automated bug report
Events
Error: Could not find repository main branch
The workaround is to delete the undesired entries from .git/branchless/config. IDK if this will have undesired effects long term or if they will get added back at some point.
Thanks for reporting. I was able to reproduce this. It's safe to delete those entries from .git/branchless/config.
This is an artifact of the solution for #219. The best solution is probably to not install the branchless.core.mainBranch setting to the same config file where we install aliases, and instead indiscriminately install it to .git/config.
Would it be possible not to explicitly set that option at all? That way I can have a global default. Then branchless can have an internal default at the lowest priority.
That seems sensible. I guess the flow should be:
- If a
branchless.core.mainBranchis already set, don't prompt for it as part ofgit branchless init. (If it was explicitly provided via--main-branch, then it should still be respected). I suppose it should print a message saying that it used an already-configured main branch setting. - If a main branch was provided, it should be installed to
.git/configin the repository directory, rather than to.git/branchless/config(which is where new alias definitions go).
Currently, git-branchless does not establish an internal default, but I think in the above flow, it doesn't really matter.
That makes sense. I agree that if you are going to prompt than no global default is needed. This way you always have a value, the global default just skips the prompt.
One slight edge case to handle is if someone creates a repo with a global default set but then removes it. In that case you may end up with know value and need a sensible behavior. Maybe just prompt at that point? Or just provide an example command to set something.
For this specific issue, we can probably close this issue due to https://github.com/arxanas/git-branchless/pull/588, because the recommended way of setting the main branch is now git branchless init --main-branch <main>, which will install the main branch configuration in the right place.