{"thread":{"id":"9218","subject":"bug: update hook failure doesn't prevent local deletion of a branch","startedAt":"2007-07-25T11:50:06Z","lastAt":"2007-07-27T05:00:41Z","messageCount":4,"participants":["Andy Parkins","Junio C Hamano","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"48557","messageId":"200707251250.08166.andyparkins@gmail.com","threadId":"9218","inReplyTo":null,"subject":"bug: update hook failure doesn't prevent local deletion of a branch","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-07-25T11:50:06Z","receivedAt":"2007-07-25T11:50:06Z","isPatch":false,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Hello,\n\nI wanted to delete a branch (let's call it \"deleted-branch\") from my public \nrepository.  I ran this:\n\n$ git push origin :deleted-branch\ndeleting 'refs/heads/deleted-branch'\n Also local refs/remotes/up/deleted-branch\n*** Update hook: aborting\nerror: hooks/update exited with error code 1\nerror: hook declined to update refs/heads/deleted-branch\nng refs/heads/deleted-branch hook declined\nerror: failed to push to '/path/to/git/repo.git'\n\nCoincidentally, my update hook happened to have a bug in it that prevented me \nfrom running the operation.\n\nHowever, when I run the operation again...\n\n$ git push origin :deleted-branch\ndeleting 'refs/heads/deleted-branch'\n Also local refs/remotes/up/deleted-branch\nerror: unlink(.git/refs/remotes/up/deleted-branch) failed: No such file or \ndirectory\nerror: Failed to delete\n\nIf the remote didn't get deleted, then it seems wrong that the local copy does \nget deleted.\n\nSummary: when using git-push to delete a remote branch, and that deletion is \ndisallowed by the update hook, the local tracking branch _is_ deleted.\n\nObviously, this isn't _that_ serious because it could be recovered again with \na git-fetch; but it does make some scary looking errors.\n\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIET\nandyparkins@gmail.com\n"},{"id":"48752","messageId":"7vk5sm5vrd.fsf@assigned-by-dhcp.cox.net","threadId":"9218","inReplyTo":"200707251250.08166.andyparkins@gmail.com","subject":"Re: bug: update hook failure doesn't prevent local deletion of a branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-27T04:13:42Z","receivedAt":"2007-07-27T04:13:42Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> writes:\n\n> I wanted to delete a branch (let's call it \"deleted-branch\") from my public \n> repository.  I ran this:\n>\n> $ git push origin :deleted-branch\n> deleting 'refs/heads/deleted-branch'\n>  Also local refs/remotes/up/deleted-branch\n> *** Update hook: aborting\n> error: hooks/update exited with error code 1\n> error: hook declined to update refs/heads/deleted-branch\n> ng refs/heads/deleted-branch hook declined\n> error: failed to push to '/path/to/git/repo.git'\n> ...\n> Summary: when using git-push to delete a remote branch, and that deletion is \n> disallowed by the update hook, the local tracking branch _is_ deleted.\n\nYes, a few months ago with b516968f, \"send-pack\" started to\npretend that it turned around and fetched immediately after it\nattempted to push.\n\nThere are two problems with it.  One is this exact problem Andy\nreported.  Newer receive-pack reports the status (if an update\nof the ref was successful), and the sender _could_ try to detect\na failure and refrain from making the local side update (but if\nthe receive-pack running on the other end is old enough there is\nno indication of an error); the code does not bother to do this\ncorrectly.  I think this is correctable without major changes.\nIf the remote end refused to update only one of the refs, and\nsend-pack as a whole fails, we could refrain from updating\nanything local.\n\nBut another more fundamental issue is that post-update hook on\nthe receiving end could do anything it pleases (for example, it\ncould try to rebase what was pushed), and at the protocol level\nthere is no way to say \"you tried to push this SHA-1 but we\nreplaced it with this other SHA-1 instead\".\n"},{"id":"48753","messageId":"20070727042606.GE20052@spearce.org","threadId":"9218","inReplyTo":"7vk5sm5vrd.fsf@assigned-by-dhcp.cox.net","subject":"Re: bug: update hook failure doesn't prevent local deletion of a branch","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-07-27T04:26:06Z","receivedAt":"2007-07-27T04:26:06Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> Andy Parkins <andyparkins@gmail.com> writes:\n> > Summary: when using git-push to delete a remote branch, and that deletion is \n> > disallowed by the update hook, the local tracking branch _is_ deleted.\n> \n> Yes, a few months ago with b516968f, \"send-pack\" started to\n> pretend that it turned around and fetched immediately after it\n> attempted to push.\n> \n> There are two problems with it.  One is this exact problem Andy\n> reported.\n...\n> I think this is correctable without major changes.\n> If the remote end refused to update only one of the refs, and\n> send-pack as a whole fails, we could refrain from updating\n> anything local.\n\nReasonable.  Probably pretty simple too.\n\n> But another more fundamental issue is that post-update hook on\n> the receiving end could do anything it pleases (for example, it\n> could try to rebase what was pushed), and at the protocol level\n> there is no way to say \"you tried to push this SHA-1 but we\n> replaced it with this other SHA-1 instead\".\n\nYou keep raising this argument against the \"git-push updates local\nrefs\" feature.  Its not just the post-update hook that could alter\nthe ref.  Another user could just push behind you (and I mean right\nbehind you) and either force an update, delete the ref entirely, or\njust fast-forward it.  (Its entirely possible that the other user\ndoes have the commit you just pushed, because you had previously\nsupplied it to them.)  So its actually possible for the ref to have\nchanged again before you even see the successful update message on\nyour console.\n\nI don't think it really matters.  Based on the output you see from\ngit-push on screen you have good reason to believe that the ref\nyou just pushed to is now at the commit SHA-1 displayed.  For that\nreason alone I think it is correct to update the corresponding\ntracking branch, because an immediate git-fetch just wastes the\nuser's time and will (usually) fetch the SHA-1 just pushed.\n\nWe should make our repository state reflect the user's internal\nmental view of what just happened, especially here, because the\nuser's mental view is probably correct.\n\n-- \nShawn.\n"},{"id":"48758","messageId":"7v3aza5tl2.fsf@assigned-by-dhcp.cox.net","threadId":"9218","inReplyTo":"20070727042606.GE20052@spearce.org","subject":"Re: bug: update hook failure doesn't prevent local deletion of a branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-27T05:00:41Z","receivedAt":"2007-07-27T05:00:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> We should make our repository state reflect the user's internal\n> mental view of what just happened, especially here, because the\n> user's mental view is probably correct.\n\nFair enough.  At least if we correct git-push so that when it\nexits with failure it would not touch the local refs, I would\nthink that would make what happens to match user's mental model\nmuch better.  The user would be _told_ that it failed, and then\ncan fetch back if he cares where the remote heads are too\ndeeply.\n"}]}