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 init --main-branch <branch> does not set main branch if set in .git/config #901

Open
mlcui-corp opened this issue Apr 17, 2023 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@mlcui-corp
Copy link
Collaborator

Description of the bug

This is a pretty obscure bug:

Command log
$ git sl
The application panicked (crashed).
Message:  A fatal error occurred: 
   0: Could not find repository main branch

Location:
   git-branchless-lib/src/core/repo_ext.rs:79

Suggestion: 
The main branch "stable" could not be found in your repository
at path: "~/chromiumos/.repo/projects/src/third_party/chromiumos-overlay.git/".
These branches exist: ["ReferenceName(\"refs/heads/main\")"]
Either create it, or update the main branch setting by running:

    git branchless init --main-branch <branch>

Note that remote main branches are no longer supported as of v0.6.0. See
https://github.com/arxanas/git-branchless/discussions/595 for more details.

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Location: git-branchless/src/commands/mod.rs:221

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

$ git branchless init --main-branch main
Created config file at ~/chromiumos/.repo/projects/src/third_party/chromiumos-overlay.git/branchless/config
Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
Successfully installed git-branchless.
To uninstall, run: git branchless init --uninstall

$ git sl
The application panicked (crashed).
Message:  A fatal error occurred: 
   0: Could not find repository main branch

Location:
   git-branchless-lib/src/core/repo_ext.rs:79

Suggestion: 
The main branch "stable" could not be found in your repository
at path: "~/chromiumos/.repo/projects/src/third_party/chromiumos-overlay.git/".
These branches exist: ["ReferenceName(\"refs/heads/main\")"]
Either create it, or update the main branch setting by running:

    git branchless init --main-branch <branch>

Note that remote main branches are no longer supported as of v0.6.0. See
https://github.com/arxanas/git-branchless/discussions/595 for more details.

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Location: git-branchless/src/commands/mod.rs:221

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

$ cat .git/config
# snip...
[include]
        path = branchless/config
# snip...
[branchless "core"]
        mainBranch = stable

If a user set the main branch using git config branchless.core.mainBranch <branch>, then that branch gets deleted, git-branchless suggests running git branchless init --main-branch <branch> to set it... but that updates the branch in .git/branchless/config, which is then overridden by the branch set in .git/config.

Expected behavior

The .git/config entry below should be deleted upon running git branchless init --main-branch main:

[branchless "core"]
        mainBranch = stable

Alternatively, the config entry should be updated with the new main branch name. This might be more reasonable as all other config options set in .git/branchless/config are typically never changed by the user (aliases, excluding refs/branchless/* from log, and removing the detached HEAD advice).

Actual behavior

The .git/config entry wasn't deleted or updated, resulting in the same "missing main branch" error.

Version of rustc

No response

Automated bug report

No response

Version of git-branchless

b66f76c (patched on top of f25babf)

Version of git

git version 2.40.0.634.g4ca3ef3211-goog

@mlcui-corp mlcui-corp added the bug Something isn't working label Apr 17, 2023
@arxanas
Copy link
Owner

arxanas commented Apr 18, 2023

Thanks for reporting. This is similar to #338 and #694. I commented in #338:

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. [...] 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.

This might just be a documentation issue (it looks like https://github.com/arxanas/git-branchless/wiki/Configuration suggests using git config to configure the main branch, which is "wrong"), but it would probably be best to delete or use the existing .git/config entry.

@arxanas arxanas added the good first issue Good for newcomers label Apr 18, 2023
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