{"thread":{"id":"42793","subject":"git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","startedAt":"2016-07-07T18:44:58Z","lastAt":"2016-07-09T05:34:00Z","messageCount":8,"participants":["Erik Johnson","Jacob Keller","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"290970","messageId":"20160707184408.GA1916@gmail.com","threadId":"42793","inReplyTo":null,"subject":"git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","fromName":"Erik Johnson","fromEmail":"palehose@gmail.com","sentAt":"2016-07-07T18:44:08Z","receivedAt":"2016-07-07T18:44:58Z","isPatch":false,"sender":{"key":"palehose@gmail.com","avatar":"https://gravatar.com/avatar/d40ae5da002709d63d829af7b7259223f303618e22af5a75960201f48780c091?d=mp&s=160"},"body":"% git branch -D archive-extracted-xz\nerror: Cannot delete branch 'archive-extracted-xz' checked out at '/home/erik/git/salt/archive-extracted-xz'\n% test -d /home/erik/git/salt/archive-extracted-xz || echo \"directory doesn't exist\"\ndirectory doesn't exist\n% git --version\ngit version 2.9.0\n\nI know that I can just get rid of this error by pruning the worktrees,\nbut this still seems like incorrect behavior on the part of git branch.\nIt shouldn't be telling me that the branch is checked out in a directory\nthat does not exist, that is just factually incorrect.\n\n--\n\n-Erik\n\n\"For me, it is far better to grasp the universe as it really is than to\npersist in delusion, however satisfying and reassuring.\"  --Carl Sagan\n\n"},{"id":"291000","messageId":"CA+P7+xoM=-=sokA_+WDuY7KYUwSa=Qu8Y9U1aPHOgSH3n-VZnA@mail.gmail.com","threadId":"42793","inReplyTo":"20160707184408.GA1916@gmail.com","subject":"Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2016-07-07T23:39:26Z","receivedAt":"2016-07-07T23:46:29Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Thu, Jul 7, 2016 at 11:44 AM, Erik Johnson <palehose@gmail.com> wrote:\n> % git branch -D archive-extracted-xz\n> error: Cannot delete branch 'archive-extracted-xz' checked out at\n> '/home/erik/git/salt/archive-extracted-xz'\n> % test -d /home/erik/git/salt/archive-extracted-xz || echo \"directory\n> doesn't exist\"\n> directory doesn't exist\n> % git --version\n> git version 2.9.0\n>\n> I know that I can just get rid of this error by pruning the worktrees,\n> but this still seems like incorrect behavior on the part of git branch.\n> It shouldn't be telling me that the branch is checked out in a directory\n> that does not exist, that is just factually incorrect.\n>\n\nUntil the worktree status is updated git branch probably isn't\nchecking itself. It might be worth triggering a worktree prune when\ndoing branch work. Note that some worktrees may be on removable media\nor similar, and thus even if the directory doesn't exist right now,\nthat does not mean it's no longer checked out. There is already\nsupport for setting a worktree as \"persistent\", but this means git\nbranch definitely shouldn't just do its own check for non existent\ndirectory.\n\nThanks,\nJake\n\n> --\n>\n> -Erik\n>\n> \"For me, it is far better to grasp the universe as it really is than to\n> persist in delusion, however satisfying and reassuring.\"  --Carl Sagan\n>\n"},{"id":"291001","messageId":"20160708003646.GB1916@gmail.com","threadId":"42793","inReplyTo":"CA+P7+xoM=-=sokA_+WDuY7KYUwSa=Qu8Y9U1aPHOgSH3n-VZnA@mail.gmail.com","subject":"Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","fromName":"Erik Johnson","fromEmail":"palehose@gmail.com","sentAt":"2016-07-08T00:36:46Z","receivedAt":"2016-07-08T00:36:55Z","isPatch":false,"sender":{"key":"palehose@gmail.com","avatar":"https://gravatar.com/avatar/d40ae5da002709d63d829af7b7259223f303618e22af5a75960201f48780c091?d=mp&s=160"},"body":"On Thu, Jul 07, 2016 at 04:39:26PM -0700, Jacob Keller wrote:\n>On Thu, Jul 7, 2016 at 11:44 AM, Erik Johnson <palehose@gmail.com> wrote:\n>> % git branch -D archive-extracted-xz\n>> error: Cannot delete branch 'archive-extracted-xz' checked out at\n>> '/home/erik/git/salt/archive-extracted-xz'\n>> % test -d /home/erik/git/salt/archive-extracted-xz || echo \"directory\n>> doesn't exist\"\n>> directory doesn't exist\n>> % git --version\n>> git version 2.9.0\n>>\n>> I know that I can just get rid of this error by pruning the worktrees,\n>> but this still seems like incorrect behavior on the part of git branch.\n>> It shouldn't be telling me that the branch is checked out in a directory\n>> that does not exist, that is just factually incorrect.\n>>\n>\n>Until the worktree status is updated git branch probably isn't\n>checking itself. It might be worth triggering a worktree prune when\n>doing branch work. Note that some worktrees may be on removable media\n>or similar, and thus even if the directory doesn't exist right now,\n>that does not mean it's no longer checked out. There is already\n>support for setting a worktree as \"persistent\", but this means git\n>branch definitely shouldn't just do its own check for non existent\n>directory.\n>\n>Thanks,\n>Jake\n>\n\nI'm not expecting _any_ git branch command to prune worktrees, but a\nbranch _deletion_ shouldn't fail because git thinks the branch is\nchecked out in a worktree that doesn't exist anymore. Even in the\nscenario where the worktree corresponding to that branch is on removable\nmedia, does it really matter? You're trying to delete the branch.\n\nI feel like this is a recent change in behavior, too. I've been using\nworktrees since they were first available in 2.5, and I don't remember\nhaving to prune to be able to delete the branch until recently.\n\n\n--\n\n-Erik\n\n\"For me, it is far better to grasp the universe as it really is than to\npersist in delusion, however satisfying and reassuring.\"  --Carl Sagan\n\n"},{"id":"291079","messageId":"CA+P7+xr_dYbno+JsTmaG+WWrgwsAXXGTyA6HL4A4A34ahHMD=Q@mail.gmail.com","threadId":"42793","inReplyTo":"20160708003646.GB1916@gmail.com","subject":"Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2016-07-09T00:41:17Z","receivedAt":"2016-07-09T00:41:43Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Thu, Jul 7, 2016 at 5:36 PM, Erik Johnson <palehose@gmail.com> wrote:\n> I'm not expecting _any_ git branch command to prune worktrees, but a\n> branch _deletion_ shouldn't fail because git thinks the branch is\n> checked out in a worktree that doesn't exist anymore. Even in the\n> scenario where the worktree corresponding to that branch is on removable\n> media, does it really matter? You're trying to delete the branch.\n\nI disagree. git branch -d (should) fail to delete a branch when it is\nchecked out in a worktree. If the worktree is a persistent (ie: not\nthere due to removable media etc)  directory then it *definitely*\nshouldn't allow you to delete.\n\nIt is possible we should update \"git branch -d\" should perform a\nworktree prune first, since that would enable it to determine that you\ndeleted the directory, and any worktree which is removable should be\nmarked as persistent.\n\nGiven that there is a known workaround (git worktree prune) and that\nit is expected behavior for a branch checked out to prevent deletion,\nI think the best coarse of action would be to patch git branch -d to\ndo a prune before attempting to delete.\n\nThanks,\nJake\n"},{"id":"291081","messageId":"20160709022223.GC1916@gmail.com","threadId":"42793","inReplyTo":"CA+P7+xr_dYbno+JsTmaG+WWrgwsAXXGTyA6HL4A4A34ahHMD=Q@mail.gmail.com","subject":"Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","fromName":"Erik Johnson","fromEmail":"palehose@gmail.com","sentAt":"2016-07-09T02:22:23Z","receivedAt":"2016-07-09T02:22:33Z","isPatch":false,"sender":{"key":"palehose@gmail.com","avatar":"https://gravatar.com/avatar/d40ae5da002709d63d829af7b7259223f303618e22af5a75960201f48780c091?d=mp&s=160"},"body":"On Fri, Jul 08, 2016 at 05:41:17PM -0700, Jacob Keller wrote:\n>On Thu, Jul 7, 2016 at 5:36 PM, Erik Johnson <palehose@gmail.com> wrote:\n>> I'm not expecting _any_ git branch command to prune worktrees, but a\n>> branch _deletion_ shouldn't fail because git thinks the branch is\n>> checked out in a worktree that doesn't exist anymore. Even in the\n>> scenario where the worktree corresponding to that branch is on removable\n>> media, does it really matter? You're trying to delete the branch.\n>\n>I disagree. git branch -d (should) fail to delete a branch when it is\n>checked out in a worktree. If the worktree is a persistent (ie: not\n>there due to removable media etc)  directory then it *definitely*\n>shouldn't allow you to delete.\n>\n>It is possible we should update \"git branch -d\" should perform a\n>worktree prune first, since that would enable it to determine that you\n>deleted the directory, and any worktree which is removable should be\n>marked as persistent.\n>\n>Given that there is a known workaround (git worktree prune) and that\n>it is expected behavior for a branch checked out to prevent deletion,\n>I think the best coarse of action would be to patch git branch -d to\n>do a prune before attempting to delete.\n>\n>Thanks,\n>Jake\n\nWell, I never mentioned -d (I was using -D), but I think we're both in\nagreement.\n\n--\n\n-Erik\n\n\"For me, it is far better to grasp the universe as it really is than to\npersist in delusion, however satisfying and reassuring.\"  --Carl Sagan\n\n"},{"id":"291083","messageId":"CA+P7+xoLKmUaJ9f1obVVDyjBTBe=XvSACvL8uiJWYf+2MTMN8w@mail.gmail.com","threadId":"42793","inReplyTo":"20160709022223.GC1916@gmail.com","subject":"Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2016-07-09T04:58:26Z","receivedAt":"2016-07-09T04:58:50Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Fri, Jul 8, 2016 at 7:22 PM, Erik Johnson <palehose@gmail.com> wrote:\n> On Fri, Jul 08, 2016 at 05:41:17PM -0700, Jacob Keller wrote:\n>> It is possible we should update \"git branch -d\" should perform a\n>> worktree prune first, since that would enable it to determine that you\n>> deleted the directory, and any worktree which is removable should be\n>> marked as persistent.\n>>\n>> Given that there is a known workaround (git worktree prune) and that\n>> it is expected behavior for a branch checked out to prevent deletion,\n>> I think the best coarse of action would be to patch git branch -d to\n>> do a prune before attempting to delete.\n>>\n>> Thanks,\n>> Jake\n>\n>\n> Well, I never mentioned -d (I was using -D), but I think we're both in\n> agreement.\n>\n>\n\nOut of curiosity, what is git branch -D behavior when the worktree does exist?\n\nThanks,\nJake\n"},{"id":"291084","messageId":"20160709050500.GD1916@gmail.com","threadId":"42793","inReplyTo":"CA+P7+xoLKmUaJ9f1obVVDyjBTBe=XvSACvL8uiJWYf+2MTMN8w@mail.gmail.com","subject":"Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","fromName":"Erik Johnson","fromEmail":"palehose@gmail.com","sentAt":"2016-07-09T05:05:00Z","receivedAt":"2016-07-09T05:05:09Z","isPatch":false,"sender":{"key":"palehose@gmail.com","avatar":"https://gravatar.com/avatar/d40ae5da002709d63d829af7b7259223f303618e22af5a75960201f48780c091?d=mp&s=160"},"body":"On Fri, Jul 08, 2016 at 09:58:26PM -0700, Jacob Keller wrote:\n>On Fri, Jul 8, 2016 at 7:22 PM, Erik Johnson <palehose@gmail.com> wrote:\n>> On Fri, Jul 08, 2016 at 05:41:17PM -0700, Jacob Keller wrote:\n>>> It is possible we should update \"git branch -d\" should perform a\n>>> worktree prune first, since that would enable it to determine that you\n>>> deleted the directory, and any worktree which is removable should be\n>>> marked as persistent.\n>>>\n>>> Given that there is a known workaround (git worktree prune) and that\n>>> it is expected behavior for a branch checked out to prevent deletion,\n>>> I think the best coarse of action would be to patch git branch -d to\n>>> do a prune before attempting to delete.\n>>>\n>>> Thanks,\n>>> Jake\n>>\n>>\n>> Well, I never mentioned -d (I was using -D), but I think we're both in\n>> agreement.\n>>\n>>\n>\n>Out of curiosity, what is git branch -D behavior when the worktree does exist?\n>\n>Thanks,\n>Jake\n\nIt works the same irrespective of whether or not the directory exists:\n\n% git worktree add ../foo\nPreparing ../foo (identifier foo)\nHEAD is now at 91e095b Merge pull request #34429 from terminalmage/pkg-latest-versioncheck\n% git branch -D foo\nerror: Cannot delete branch 'foo' checked out at '/home/erik/git/salt/foo'\n% rm -rf /home/erik/git/salt/foo\n% git branch -D foo\nerror: Cannot delete branch 'foo' checked out at '/home/erik/git/salt/foo'\n% git worktree prune -v\nRemoving worktrees/foo: gitdir file points to non-existent location\n% git branch -D foo\nDeleted branch foo (was 91e095b).\n\n\n--\n\n-Erik\n\n\"For me, it is far better to grasp the universe as it really is than to\npersist in delusion, however satisfying and reassuring.\"  --Carl Sagan\n\n"},{"id":"291091","messageId":"CACsJy8BWAirnni+-ZzShMrKO0Pjs8xiUw1gXSJAR2ZT9kJFtuQ@mail.gmail.com","threadId":"42793","inReplyTo":"20160707184408.GA1916@gmail.com","subject":"Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-07-09T05:33:25Z","receivedAt":"2016-07-09T05:34:00Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Jul 7, 2016 at 8:44 PM, Erik Johnson <palehose@gmail.com> wrote:\n> % git branch -D archive-extracted-xz\n> error: Cannot delete branch 'archive-extracted-xz' checked out at\n> '/home/erik/git/salt/archive-extracted-xz'\n\nThis is from commit f292244 (branch -d: refuse deleting a branch which\nis currently checked out - 2016-03-29) which is about -d not -D, so\nit's probably an oversight. I think -D, as a forced form, should allow\ndeleting branches on other worktrees, we could simply detach the\nworktree first.\n\nIt's worth noting that before that commit, -D refuses to delete branch\non current worktree as well and f292244 simply applies the same\nbehavior on other worktrees. If we change the -D behavior about\ndeleting branches on other worktrees, we may need to consider to keep\nthe behavior on current branch, or treat it equally as any other\nworktrees.\n-- \nDuy\n"}]}