git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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 b
    git 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 b
    git 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 b
    git 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 b
    git 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)
}
Previous: Junio C HamanoNext: Yuri Kanivetsky
Message 3 of 4 in “remote.<name>.push without dst doesn't behave as documented”
  1. Yuri KanivetskyDec 16, 2024
  2. Junio C HamanoDec 16, 2024
  3. Yuri KanivetskyDec 17, 2024
  4. Yuri KanivetskyDec 19, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.