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

Bug: `git fetch --prune origin master:refs/foo` incorrectly prunes refs/foo

From
LBLily Ballard <lily@sb.org>
Date
Aug 21, 2019, 00:50 UTC
Message-ID
<3927bdd8-5641-4ade-aea5-e843c3bbf612@www.fastmail.com>
When using the --prune flag (or fetch.prune=true), a `git fetch` command that uses a refspec to update a ref that doesn’t exist remotely will behave incorrectly if the ref already exists locally. For example:
> git fetch --prune master:refs/foo
If refs/foo doesn’t exist, this command will create it with the contents of origin’s master. If refs/foo does exist, it will be pruned immediately. If the `git fetch` doesn’t actually fetch anything (because the commits exist locally) then it will exit with success, despite the ref not existing locally. If it does fetch commits, it will fail with a “cannot lock ref” error.
Here’s the flow for fetching twice:
> git fetch --prune origin master:refs/foo
From <url>
 * [new branch]            master     -> refs/foo
> git fetch --prune origin master:refs/foo
From <url>
 - [deleted]               (none)     -> refs/foo
> git rev-parse --verify refs/foo
fatal: Needed a single revision
And here’s what I get if the ref already exists and the fetch actually downloads commits (in this case I’m using --force but that’s not necessary for the bug):
> git fetch --prune --force origin pull/7267/head:refs/foo
From <url>
 - [deleted]               (none)     -> refs/foo
error: cannot lock ref 'refs/foo': unable to resolve reference 'refs/foo'
 ! e090924c71...ca5f06da05 refs/pull/7267/head -> refs/foo  (unable to update local ref)
This was reproduced using git version 2.22.0.
-Lily Ballard
Message 1 of 1 in “Bug: `git fetch --prune origin master:refs/foo` incorrectly prunes refs/foo”
  1. Lily BallardAug 21, 2019

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.