{"thread":{"id":"30965","subject":"The order of multiple remote.xx.fetch is significant for some operations","startedAt":"2012-07-06T02:06:58Z","lastAt":"2012-07-06T02:06:58Z","messageCount":1,"participants":["Jiang Xin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"194692","messageId":"CANYiYbEH_qxj40SiVeYgLT_fYiRSh7O+wwSim1u=dBDfoZMiFA@mail.gmail.com","threadId":"30965","inReplyTo":null,"subject":"The order of multiple remote.xx.fetch is significant for some operations","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2012-07-06T02:06:58Z","receivedAt":"2012-07-06T02:06:58Z","isPatch":false,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"Someone asked me how to remove obsolete topgit feature branches from\nthe remote topgit controlled git repo. I found we can not run\n\"git fetch --prune\" directly to delete stale remote branches from\nlocal, because of the wrong order of multiple \"remote.XX.fetch\" config\nvariable.\n\nFor example, config variables for remote \"origin\":\n\n    [remote \"origin\"]\n          fetch = +refs/heads/*:refs/remotes/origin/*\n          url = git@github.com:ossxp-com/topgit.git\n          fetch = +refs/top-bases/*:refs/remotes/origin/top-bases/*\n\nWhen running \"git fetch --prune\", will check all local refs, and delete\nstale remote branches from local if their conterparts do not exist in\nremote repo. But in this case, all remote branches under\n\"refs/remotes/origin/top-bases/\" namespace will be deleted, even their\nremote conterparts \"refs/top-bases/*\" still exist in remote repo.\n\nHow does this happen? e.g. a local ref:\n\"refs/remotes/origin/top-bases/t/featureX\"\n\n * First make a reverse look up according to the remote.origin.fetch\n   config variables;\n\n * The first remote.origin.fetch matches, and this local ref is mapped\n   as \"refs/heads/top-bases/t/featureX\";\n\n * The remote repo does not have ref \"refs/heads/top-bases/t/featureX\",\n   (it should be \"refs/top-bases/t/featureX\"), then this local refs is\n   deleted as a stale remote branch.\n\n * While if we change the order of remote.origin.fetch config variables,\n   The result is different. This local ref will map to\n   \"refs/top-bases/t/featureX\", and won't be deleted.\n\nSo, it's not a bug of git, but a flaw of user generated config variables.\nThe hacks for Topgit are simple, see:\n\n * https://github.com/ossxp-com/topgit/blob/master/debian/patches/t/delete-remote-branch.diff\n * https://github.com/ossxp-com/topgit/blob/master/debian/patches/t/prune-stale-remote-branch.diff\n\n--\nJiang Xin\n"}]}