Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.git/branchless/config "defaults" override config set with git config. #338

Closed
kevincox opened this issue Apr 6, 2022 · 6 comments
Closed
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@kevincox
Copy link

kevincox commented Apr 6, 2022

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 kevincox added the bug Something isn't working label Apr 6, 2022
@kevincox
Copy link
Author

kevincox commented Apr 6, 2022

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.

@arxanas
Copy link
Owner

arxanas commented Apr 8, 2022

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 arxanas added the good first issue Good for newcomers label Apr 8, 2022
@kevincox
Copy link
Author

kevincox commented Apr 8, 2022 via email

@arxanas
Copy link
Owner

arxanas commented Apr 10, 2022

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.

@kevincox
Copy link
Author

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.

arxanas added a commit that referenced this issue Oct 5, 2022
Due to #338, the suggestion as provided may not actually work.
arxanas added a commit that referenced this issue Oct 5, 2022
Due to #338, the suggestion as provided may not actually work.
arxanas added a commit that referenced this issue Oct 6, 2022
Due to #338, the suggestion as provided may not actually work.
@arxanas
Copy link
Owner

arxanas commented Dec 7, 2022

For this specific issue, we can probably close this issue due to #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants