Open greg7mdp opened 2 years ago
Hi @greg7mdp, thanks for reporting. This situation should definitely be improved. It's worth noting that some git-branchless commands should work even without having run git branchless init
if it can infer your main branch, like git move
.
When raising this error, we can check to see if init
has been run, and, if not, include something in the error message suggesting to run it. We can infer that init
has been run by checking to see if the config value branchless.core.mainBranch
has a value or not. There might be a small amount of refactoring in config.rs
to make that query.
This probably deserves its own issue if it's doable/well-received, but a possibly related feature that I'd love to see is a configuration option to lazily/automatically init
the first time it's needed. Perhaps a branchless.core.autoInit
or something of the sort. I'd set this globally in a heartbeat and it would save me from quite a number of errors related to not having run init
yet!
@zachallaun feel free to open a separate issue. I don't personally plan to work on that in the near future, but I'd accept a PR implementing it.
I'm just starting to use git branchless
, it seems excellent.
Could I ask — why the need to run git branchless init
in each repo for commands like git sync
? Assuming that refs/remotes/origin/HEAD
is set, don't we already know the default branch?
Could I ask — why the need to run git branchless init in each repo for commands like git sync?
@max-sixty There are a lot of implicit dependencies in the rest of the code. For example:
main
/master
locally, and we might need to explicitly prompt the user/save the result.post-rewrite
hook for correctness reasons.It's possible that certain commands under certain circumstances can run without explicit initialization, but it would be difficult to write the existing code in a way that can run without assuming that git branchless init
has been run.
Assuming that refs/remotes/origin/HEAD is set, don't we already know the default branch?
There might be some metadata I'm not familiar with; how does refs/remotes/origin/HEAD
tell us the local main branch? (Also, it assumes that origin
is the remote that we want to sync from — for example, in a two-remote GitHub setup, one often has origin
and upstream
remotes, where upstream
is the pull-remote and origin
is the push-remote — although it wouldn't be unreasonable to assume that origin
is the default remote in many cases).
It's possible that certain commands under certain circumstances can run without explicit initialization, but it would be difficult to write the existing code in a way that can run without assuming that
git branchless init
has been run.
Yes, this makes sense.
Plausibly the main thing I came here for is actually quite a small feature — update all my local branches based on any remote updates — such that the full operation does require the setup...
There might be some metadata I'm not familiar with; how does
refs/remotes/origin/HEAD
tell us the local main branch?
IIUC, refs/remotes/origin/HEAD
is the default branch (i.e. HEAD
) of the default remote (i.e. origin
). Running git remote set-head origin -a
will update it.
It would be really helpful if there was a way to completely disable git-branchless if init hasn't been run. I'm trying to get a shell working with Crane/Nix and as part of that some git repos are being pulled in the background, which git-branchless is choking on.
@tshakah not sure I understand; why is git-branchless invoked if it hasn't been initialized and you're not invoking it (presumably if the repos are in the background)?
Description of the bug
As I tried a macos build of my software, I forgot to run
git-branchless init
on the repo, and I was mistified for a moment as to why git-branchless was not working. Even got a crash:After doing a
git-branchless init
, all issues went away.BTW I love git-branchless. This is what git should be :-).
Expected behavior
A friendly message, like
Looks like you forgot to run "git-branchless init"
Actual behavior
Version of
rustc
rustc 1.62.1 (e092d0b6b 2022-07-16)
Automated bug report
No response
Version of
git-branchless
git-branchless 0.3.12
Version of
git
git version 2.35.1