-
Notifications
You must be signed in to change notification settings - Fork 63
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
stg branch --create
sets up remote tracking information incorrectly
#522
Comments
stg branch --create
sets up remote tracking branch incorrectlystg branch --create
sets up remote tracking information incorrectly
This is amazing analysis @fbenkstein! Thank you for working through all these differences between StGit and Git. I learned some things about git's behavior from this. Tagging @Byron since he may be interested in these details in the context of gitoxide. For StGit, agreed that punting to |
Thanks so much for digging into this and sharing your analysis, it's will be very helpful in fixing this upstream and it's now on my list to fix with priority, hoping to get it done this weekend. Meanwhile, I wouldn't mind if this was fixed by shelling this out to |
…-git#522) Previously assumptions were made about how shortened tracking branches would relate to remote names, and partial names would be set as `merge` field of local branch configuration. The latter could lead to Git being unable to perform certain operations. Now the correct full reference name is set.
…-git#522) Previously assumptions were made about how shortened tracking branches would relate to remote names, and partial names would be set as `merge` field of local branch configuration. The latter could lead to Git being unable to perform certain operations. Now the correct full reference name is set.
…-git#522) Previously assumptions were made about how shortened tracking branches would relate to remote names, and partial names would be set as `merge` field of local branch configuration. The latter could lead to Git being unable to perform certain operations. Now the correct full reference name is set.
…-git#522) Previously assumptions were made about how shortened tracking branches would relate to remote names, and partial names would be set as `merge` field of local branch configuration. The latter could lead to Git being unable to perform certain operations. Now the correct full reference name is set.
Previously assumptions were made about how shortened tracking branches would relate to remote names, and partial names would be set as `merge` field of local branch configuration. The latter could lead to Git being unable to perform certain operations. Now the correct full reference name is set.
This is fixed as of 20fbdcc. Thank you @fbenkstein for the great issue report and @Byron for the quick and effective fix. |
When creating a new branch from a remote reference
stg branch --create
sets up the remote differently from git:Creating the branch with
git
Creating branch with
stg
Note that the remote tracking ref is unqualified:
master
vsrefs/heads/master
. It is also unresolved because technically the fetch refspec of the remote could rename the branch and the remote to something else.Actual bug
Unfortunately, this means that
stg rebase
andgit rebase
both fail when called without an argument on such a branch:Git behaves correctly
They do work correctly on the branches set up with git:
Weird remote branch example
Even though remote branches like
refs/heads/<branch name>
are conventionally fetched torefs/remotes/<remote name>/<branch name>
this isn't a requirement. Whatgit
actually does internally is resolingyet-another-origin/main
torefs/remotes/yet-another-origin/main
and then walking through theremote.<name>.fetch
refspecs of all remotes until it finds exactly one match by reverse applying the refspec which results inrefs/heads/master
of theanother-origin
remote:stg
doesn't do this and simply splits the shortened input ref by/
and treats the first part as the remote name and the second part as the branch name:This means
git rebase
andstg rebase
still work on the branch set up bygit
:They break on
stg-branch2
with an error similar to the one already shown above:git pull
/stg pull
git pull
andstg pull
don't have a problem with the unqualified remote branch at least when the remote name matches. They interpretbranch.<name>.merge
as a refspec and then merge or rebase fromFETCH_HEAD
.git rebase
/stg rebase
on the other hand, need to forward translate thebranch.<name>.merge
name back to the remote tracking branch name, i.e. by convention something likerefs/remotes/<remote name>/<branch name>
so they can find the ref to rebase to.Running
git pull
on thestg-branch
created like above works but it fails on thestg-branch2
because the remote name is incorrect:Conclusion
I tried fixing this myself by looking at what git does. The logic is actually quite complicated and there doesn't appear to be an simple API in Gitoxide. Correctly implementing it would mean duplicating the
git
logic instg
. (IIUC it would involve building agix_refspec::MatchGroup
for each remote and then callingmatch_remotes
on each of them, handling the case where there is no match or multiple matches as errors.) I think this is better implemented upstream in Gitoxide itself instead. The easy way out is likely just creating the branch without tracking and then callinggit branch --set-upstream
on it. I've run out of time working on this for now but wanted to record my findings in case someone else might pick it up. Otherwise, I'll try to have a go at it at some point.Finally, I think the setting
branch.<name>.stgit.parentbranch
should also be resolved to a fully qualified ref (and maybe only set if the source branch actually has an StackedGit stack). I haven't run into a case where this is an issue yet, though.The text was updated successfully, but these errors were encountered: