Re: remote.<name>.push without dst doesn't behave as documented
- From
Yuri Kanivetsky <yuri.kanivetsky@gmail.com>
- Date
- Dec 17, 2024, 08:12 UTC
- Message-ID
- <CAMhVC3byz89UP_DJq+c6UVUNoFW0oRRSwbR7v=uUBAdBMLwqMg@mail.gmail.com>
- In-Reply-To
- <xmqqr0674hvq.fsf@gitster.g>
So it was your doing :) (no offense meant)
https://github.com/git/git/commit/ca02465b41311fe7634acb9bb5b5c61975ef5f38
> If git push [<repository>] without any <refspec> argument is set to update some ref at the destination with <src> with remote.<repository>.push configuration variable, :<dst> part can be omitted—such a push will update a ref that <src> normally updates without any <refspec> on the command line. Otherwise, missing :<dst> means to update the same ref as the <src>.
My understanding of this was (the only phrasing that made some sense to me):
> If git push [<repository>] without any <refspec> argument __is invoked__ to update some ref at the destination with <src> __and remote.<repository>.push is set__, :<dst> part can be omitted __in remote.<repository>.push__ -- such a push will update a ref that <src> normally updates without any <refspec> on the command line. Otherwise, missing :<dst> means to update the same ref as the <src>.
As such I chose `push.default = upstream` because that's the only mode which allows non-matching refs. I expected it to allow me to discriminate between having and not having :dst in remote.<repository>.push. But without :dst in remote.<repository>.push it updated the matching ref (the second test failed).
Now I understand that what was really meant:
> If remote.<repository>.push is set and the refspec on the command line doesn't have the :dst part, then the former (remote.<repository>.push) is used as a refmap. Otherwise (if remote.<repository>.push is not set), then missing :dst makes it push to the matching branch.
I believe the phrasing in the documentation calls for being changed.
But also I can't confirm the "otherwise" part. Below the last test fails. Either you have to (unless I'm missing something) say:
> If remote.<repository>.push is not set, then it falls back to the `push.default` behavior.
Or make it really push to the matching branch even if `push.default = upstream` and the upstream is a non-matching branch.
Regards, Yuri
--
The whole file is in a gist: https://gist.github.com/x-yuri/943fd13704b38551da36c8363d7852e1#file-b-md
# the state of the cloned repository (1 commit, 1 local branch ba) # a (HEAD -> ba, origin/ba)
@test "normally it acts according to push.default" {
start_cloned_repo
git commit --allow-empty -m bgit push
assert_equal_refs origin/ba ba }
@test "but remote.<repository>.push changes the destination when the
refspec on the command line doesn't have :dst" {
start_cloned_repo
git config remote.origin.push 'refs/heads/ba:refs/heads/bb'
git commit --allow-empty -m bgit push origin ba
assert_equal_refs origin/bb ba }
@test "specifying :dst overrides remote.<repository>.push" {
start_cloned_repo
git config remote.origin.push 'refs/heads/*:refs/heads/*'
git commit --allow-empty -m bgit push origin ba:bb
assert_equal_refs origin/bb ba }
@test "if remote.<repository>.push is not set, it pushes to the
matching branch" {
start_cloned_repo
git config push.default upstream
git push origin ba:bb
git branch -u origin/bb
git commit --allow-empty -m bgit push origin ba
assert_equal_refs origin/ba ba }
start_cloned_repo() {
(mkrepo)
cd "$BATS_TEST_TMPDIR"
git clone --bare a a.git
git clone a.git b
cd b
git config user.email you@example.com
git config user.name "Your Name"
}mkrepo() {
cd "$BATS_TEST_TMPDIR"
mkdir a
(cd a
git init
git branch -m ba
git config user.email you@example.com
git config user.name "Your Name"
git commit --allow-empty -m a)
}