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

remote.<name>.push without dst doesn't behave as documented

From
Yuri Kanivetsky <yuri.kanivetsky@gmail.com>
Date
Dec 16, 2024, 16:47 UTC
Message-ID
<CAMhVC3b+1TWLkKGYVb6VyBRyQjsDpbKRQQNT8SUXSmrWHfPnEQ@mail.gmail.com>
Hi,
> 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>.
https://git-scm.com/docs/git-push#Documentation/git-push.txt-ltrefspecgt82308203

The only case I can think of where refspec is not passed via command line and it updates a non-matching branch is when push.default = upstream. But with remote.<repository>.push without dst it starts updating a matching branch. Either I don't understand what's meant, or it doesn't behave as documented.

The second test fails:
@test "normally a non-matching ref updates" {
    start_cloned_repo
    git config push.default upstream
    git checkout -b bb
    git branch -u origin/ba
    git commit --allow-empty -m b
    git push
    assert_equal_refs origin/ba bb
}
@test "with remote.<name>.push without dst happens what happens normally" {
    start_cloned_repo
    git config push.default upstream
    git config remote.origin.push 'refs/heads/*'
    git checkout -b bb
    git branch -u origin/ba
    git commit --allow-empty -m b
    git push
    assert_equal_refs origin/ba bb
}
start_cloned_repo() {
    (mkrepo)
    cd "$BATS_TEST_TMPDIR"
    git clone --bare a a.git
    git clone a.git b
    cd b
    git config push.default upstream
    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)
}

More details in a gist: https://gist.github.com/x-yuri/943fd13704b38551da36c8363d7852e1

Regards, Yuri

Next: Junio C Hamano
Message 1 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.