git-branchless icon indicating copy to clipboard operation
git-branchless copied to clipboard

`.git/branchless/config` "defaults" override config set with `git config`.

Open kevincox opened this issue 3 years ago • 5 comments

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

kevincox avatar Apr 06 '22 12:04 kevincox

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.

kevincox avatar Apr 06 '22 12:04 kevincox

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.

arxanas avatar Apr 08 '22 07:04 arxanas

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.

kevincox avatar Apr 08 '22 10:04 kevincox

That seems sensible. I guess the flow should be:

  1. If a branchless.core.mainBranch is already set, don't prompt for it as part of git 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.
  2. If a main branch was provided, it should be installed to .git/config in 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.

arxanas avatar Apr 10 '22 23:04 arxanas

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.

kevincox avatar Apr 11 '22 00:04 kevincox

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.

arxanas avatar Dec 07 '22 19:12 arxanas