threads / bug / 24862

[BUG] git fetch --prune --tags origin deletes all remote branches origin/*

Subject: [BUG] git fetch --prune --tags origin deletes all remote branches origin/*

## tl;dr

3 messages between Aug 25, 2010 and Aug 26, 2010.

replies: 2people: 3as markdown or json

Kevin Ballard· Aug 25, 2010, 22:30 UTC · lore
Running the simple command `git fetch --prune --tags origin` will delete every single remote branch refs/remotes/origin/*, with the sole exception of refs/remotes/origin/HEAD. This is wildly unexpected behavior. This was reproduced on the tip of the next branch, with version git version 1.7.2.2.440.g49ea7.
> git fetch --prune --tags origin
 x [deleted]         (none)     -> origin/ahaney/login_problem_debug
 x [deleted]         (none)     -> origin/ahaney/tocfixes
 x [deleted]         (none)     -> origin/develop
   (refs/remotes/origin/HEAD has become dangling)
 x [deleted]         (none)     -> origin/jon/contentupdates
 x [deleted]         (none)     -> origin/jon/ingest_safety
 x [deleted]         (none)     -> origin/jon/overview
 x [deleted]         (none)     -> origin/master
 x [deleted]         (none)     -> origin/v1_rejection/plan_a
> git fetch origin
From [redacted]
 * [new branch]      ahaney/login_problem_debug -> origin/ahaney/login_problem_debug
 * [new branch]      ahaney/tocfixes -> origin/ahaney/tocfixes
 * [new branch]      develop    -> origin/develop
 * [new branch]      jon/contentupdates -> origin/jon/contentupdates
 * [new branch]      jon/ingest_safety -> origin/jon/ingest_safety
 * [new branch]      jon/overview -> origin/jon/overview
 * [new branch]      master     -> origin/master
 * [new branch]      v1_rejection/plan_a -> origin/v1_rejection/plan_a
-Kevin Ballard
Junio C Hamano· Aug 25, 2010, 23:52 UTC · re: Kevin Ballard · lore

Re: [BUG] git fetch --prune --tags origin deletes all remote branches origin/*

Kevin Ballard <kevin@sb.org> writes:
Show 5 quoted lines
> Running the simple command `git fetch --prune --tags origin` will delete
> every single remote branch refs/remotes/origin/*, with the sole
> exception of refs/remotes/origin/HEAD. This is wildly unexpected
> behavior. This was reproduced on the tip of the next branch, with
> version git version 1.7.2.2.440.g49ea7.

I suspect "--prune --tags" behaved like that from the very beginning of the appearance of "--prune", and also it is not limited to --tags. With this:

    [remote "origin"]
        url = $over_there
        fetch = refs/heads/master:refs/heads/origin
        fetch = refs/heads/next:refs/heads/next
"git fetch --prune origin master" would probably remove your local next.

get_stale_heads() seems to assume that it has the list of all existing refs from the remote side available to make its decision. Unless the fetch is done using a list of refs configured with remote.<name>.fetch, I do not think that assumption holds.

  f2ef607 (remote: refactor some logic into get_stale_heads(), 2009-11-10)
  f360d84 (builtin-fetch: add --prune option, 2009-11-10)
Jay Soffian· Aug 26, 2010, 02:26 UTC · re: Junio C Hamano · lore

Re: [BUG] git fetch --prune --tags origin deletes all remote branches origin/*

On Wed, Aug 25, 2010 at 7:52 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 10 quoted lines
> Kevin Ballard <kevin@sb.org> writes:
>
>> Running the simple command `git fetch --prune --tags origin` will delete
>> every single remote branch refs/remotes/origin/*, with the sole
>> exception of refs/remotes/origin/HEAD. This is wildly unexpected
>> behavior. This was reproduced on the tip of the next branch, with
>> version git version 1.7.2.2.440.g49ea7.
>
> I suspect "--prune --tags" behaved like that from the very beginning of
> the appearance of "--prune",

Indeed. The logic was refactored from "git remote prune" which doesn't support --tags. The quick fix would be to make --prune --tags and unsupported combination. However:

Show 9 quoted lines
> and also it is not limited to --tags.  With
> this:
>
>    [remote "origin"]
>        url = $over_there
>        fetch = refs/heads/master:refs/heads/origin
>        fetch = refs/heads/next:refs/heads/next
>
> "git fetch --prune origin master" would probably remove your local next.
I would think "remote prune" suffered the same fate in that situation.
Show 7 quoted lines
> get_stale_heads() seems to assume that it has the list of all existing
> refs from the remote side available to make its decision.  Unless the
> fetch is done using a list of refs configured with remote.<name>.fetch, I
> do not think that assumption holds.
>
>  f2ef607 (remote: refactor some logic into get_stale_heads(), 2009-11-10)
>  f360d84 (builtin-fetch: add --prune option, 2009-11-10)

I'm not sure what the best fix here is. It would seem prune should obey the user's fetch spec.

j.

← back to recent threads