{"thread":{"id":"51182","subject":"worktree add already exists","startedAt":"2019-05-27T15:32:13Z","lastAt":"2019-06-06T09:35:24Z","messageCount":7,"participants":["Ingo Wolf","Eric Sunshine","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"376239","messageId":"ad2ff81a-d75e-1ac4-07d0-c807a2ed9e36@gmx.de","threadId":"51182","inReplyTo":null,"subject":"worktree add already exists","fromName":"Ingo Wolf","fromEmail":"ingo.wolf@gmx.de","sentAt":"2019-05-27T15:32:06Z","receivedAt":"2019-05-27T15:32:13Z","isPatch":false,"sender":{"key":"ingo.wolf@gmx.de","avatar":null},"body":"\nx@y MINGW64 ~/gittest\n$ ls\nbare/  barework/\n\nx@y MINGW64 ~/gittest\n$ ls -a barework\n./  ../  test.txt\n\nx@y MINGW64 ~/gittest\n$ git -C bare branch\n* master\n\nx@y MINGW64 ~/gittest\n$ git -C bare worktree add --no-checkout ../barework\nPreparing worktree (new branch 'barework')\nfatal: '../barework' already exists\n\nx@y MINGW64 ~/gittest\n$ git -C bare branch\n   barework\n* master\n\nWhy this doesn't just work and if not why is barework branch made then,\nwhy at all ?\n\nI would like to attach an existing dir to git (make it a workdir) and\nthen update the index with git reset and checkin the differences.\n\nI can do that tricking around with a little dir renaming, new empty dir,\nmove the .git file and rename back...\n\n\n"},{"id":"376537","messageId":"CAPig+cSsNQDe-3GLnmvA+EPior=RSPETJDjkCc7X1qi6gWSGDQ@mail.gmail.com","threadId":"51182","inReplyTo":"ad2ff81a-d75e-1ac4-07d0-c807a2ed9e36@gmx.de","subject":"Re: worktree add already exists","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2019-06-02T07:07:45Z","receivedAt":"2019-06-02T07:07:59Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, May 27, 2019 at 11:32 AM Ingo Wolf <ingo.wolf@gmx.de> wrote:\n> $ ls -a barework\n> ./  ../  test.txt\n> $ git -C bare worktree add --no-checkout ../barework\n> Preparing worktree (new branch 'barework')\n> fatal: '../barework' already exists\n> $ git -C bare branch\n>    barework\n> * master\n> Why this doesn't just work and if not why is barework branch made then,\n> why at all ?\n\nIt is by design that \"git worktree add\" (in general) fails if the\ntarget directory already exists and is non-empty. This is consistent\nwith how \"git clone\" behaves. As for why your particular use-case\nisn't directly supported, it's likely that nobody has yet asked for\nit, and nobody thought about this particular case when --no-checkout\nwas added (which came some time after basic \"git worktree add\" itself\nwas implemented).\n\nIt is an accident of implementation that the new branch gets created\nbefore \"git worktree add\" errors out due to the existing non-empty\ndirectory (and, likely, nobody complained about it, so it went\nunnoticed). This particular issue probably can be easily fixed now\nthat the logic for checking if the target directory can be a valid\nworktree has been factored out of the code which actually creates the\nnew directory[1].\n\n[1]: 45059e6468 (worktree: prepare for more checks of whether path can\nbecome worktree, 2018-08-28)\n\n> I would like to attach an existing dir to git (make it a workdir) and\n> then update the index with git reset and checkin the differences.\n\nI haven't thought through the possible ramifications, but the actual\nimplementation might be as simple as changing this code in\nbuiltin/worktree.c:validate_worktree_add():\n\n    if (file_exists(path) && !is_empty_dir(path))\n        die(_(\"'%s' already exists\"), path);\n\nto:\n\n    if (opts->checkout && file_exists(path) && !is_empty_dir(path))\n        die(_(\"'%s' already exists\"), path);\n\nor something.\n"},{"id":"376560","messageId":"CACsJy8CxSN90-EfTpkd6RUHFVp2iGjZXokpMqw7Tf0EMXT5LfQ@mail.gmail.com","threadId":"51182","inReplyTo":"CAPig+cSsNQDe-3GLnmvA+EPior=RSPETJDjkCc7X1qi6gWSGDQ@mail.gmail.com","subject":"Re: worktree add already exists","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-03T09:46:50Z","receivedAt":"2019-06-03T09:47:18Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Jun 2, 2019 at 2:11 PM Eric Sunshine <sunshine@sunshineco.com> wrote:\n>\n> On Mon, May 27, 2019 at 11:32 AM Ingo Wolf <ingo.wolf@gmx.de> wrote:\n> > $ ls -a barework\n> > ./  ../  test.txt\n> > $ git -C bare worktree add --no-checkout ../barework\n> > Preparing worktree (new branch 'barework')\n> > fatal: '../barework' already exists\n> > $ git -C bare branch\n> >    barework\n> > * master\n> > Why this doesn't just work and if not why is barework branch made then,\n> > why at all ?\n>\n> It is by design that \"git worktree add\" (in general) fails if the\n> target directory already exists and is non-empty. This is consistent\n> with how \"git clone\" behaves. As for why your particular use-case\n> isn't directly supported, it's likely that nobody has yet asked for\n> it, and nobody thought about this particular case when --no-checkout\n> was added (which came some time after basic \"git worktree add\" itself\n> was implemented).\n>\n> It is an accident of implementation that the new branch gets created\n> before \"git worktree add\" errors out due to the existing non-empty\n> directory (and, likely, nobody complained about it, so it went\n> unnoticed). This particular issue probably can be easily fixed now\n> that the logic for checking if the target directory can be a valid\n> worktree has been factored out of the code which actually creates the\n> new directory[1].\n>\n> [1]: 45059e6468 (worktree: prepare for more checks of whether path can\n> become worktree, 2018-08-28)\n>\n> > I would like to attach an existing dir to git (make it a workdir) and\n> > then update the index with git reset and checkin the differences.\n>\n> I haven't thought through the possible ramifications, but the actual\n> implementation might be as simple as changing this code in\n> builtin/worktree.c:validate_worktree_add():\n>\n>     if (file_exists(path) && !is_empty_dir(path))\n>         die(_(\"'%s' already exists\"), path);\n>\n> to:\n>\n>     if (opts->checkout && file_exists(path) && !is_empty_dir(path))\n>         die(_(\"'%s' already exists\"), path);\n>\n> or something.\n\nComing from \"git clone\" background I would still expect --no-checkout\nto abort on non-empty directory (i.e. we always start at a good known\nstate). Maybe another option can be used in combination with\n--no-checkout for this. And do we want the same option in \"git clone\"?\n-- \nDuy\n"},{"id":"376596","messageId":"CAPig+cQ0po+cqdqohkVqFyk=aowtjuYGM2J=31pFu6ZuPeAUFA@mail.gmail.com","threadId":"51182","inReplyTo":"CACsJy8CxSN90-EfTpkd6RUHFVp2iGjZXokpMqw7Tf0EMXT5LfQ@mail.gmail.com","subject":"Re: worktree add already exists","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2019-06-03T18:32:01Z","receivedAt":"2019-06-03T18:32:15Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Jun 3, 2019 at 5:47 AM Duy Nguyen <pclouds@gmail.com> wrote:\n> On Sun, Jun 2, 2019 at 2:11 PM Eric Sunshine <sunshine@sunshineco.com> wrote:\n> > On Mon, May 27, 2019 at 11:32 AM Ingo Wolf <ingo.wolf@gmx.de> wrote:\n> > > I would like to attach an existing dir to git (make it a workdir) and\n> > > then update the index with git reset and checkin the differences.\n> >\n> > I haven't thought through the possible ramifications, but the actual\n> > implementation might be as simple as changing this code in\n> > builtin/worktree.c:validate_worktree_add():\n>\n> Coming from \"git clone\" background I would still expect --no-checkout\n> to abort on non-empty directory (i.e. we always start at a good known\n> state). Maybe another option can be used in combination with\n> --no-checkout for this. And do we want the same option in \"git clone\"?\n\nTaking a potential use-case into account, it might be more appropriate\nto compare this suggested behavior to git-init rather than to\ngit-clone. Say, for instance, someone downloads a \"tarball\" of a\nproject (with no .git/ directory), experimentally hacks on it for a\nwhile and then decides that that work is worthy of being submitted to\nthe project as patches or a pull-request. One could imagine that a way\nto accomplish this would be to \"git clone ...\" the project, and then\n\"git worktree add --no-checkout /path/to/my/hacking\", followed by a\nseries of \"git add ...\" and \"git commit ...\" invocations to formalize\nthe changes into discreet commits.\n\nThis is analogous to how you might start hacking from scratch on a new\nexperimental project before you know if it will pan out, and before\nyou know if it will be worthy of placing under revision control. If it\ndoes pan out, then you \"git init\" the existing populated directory,\nand follow with a series of \"git add ...\" and \"git commit ...\"\ninvocations.\n\nI'm not sure how common such a use-case is, though. I recall being in\nsuch a situation once or twice over the years, but that's not\nnecessarily a good metric. So, I'm not suggesting that such a feature\nshould or need be added to git-worktree, but the above thought\nexperiment perhaps provides some context for possible behavior.\n"},{"id":"376708","messageId":"CACsJy8DiueSPST64=iCZc=V6UtU61RXjJqhBHvG59BwFVSh3QA@mail.gmail.com","threadId":"51182","inReplyTo":"CAPig+cQ0po+cqdqohkVqFyk=aowtjuYGM2J=31pFu6ZuPeAUFA@mail.gmail.com","subject":"Re: worktree add already exists","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-05T10:17:00Z","receivedAt":"2019-06-05T10:17:28Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Jun 4, 2019 at 1:32 AM Eric Sunshine <sunshine@sunshineco.com> wrote:\n>\n> On Mon, Jun 3, 2019 at 5:47 AM Duy Nguyen <pclouds@gmail.com> wrote:\n> > On Sun, Jun 2, 2019 at 2:11 PM Eric Sunshine <sunshine@sunshineco.com> wrote:\n> > > On Mon, May 27, 2019 at 11:32 AM Ingo Wolf <ingo.wolf@gmx.de> wrote:\n> > > > I would like to attach an existing dir to git (make it a workdir) and\n> > > > then update the index with git reset and checkin the differences.\n> > >\n> > > I haven't thought through the possible ramifications, but the actual\n> > > implementation might be as simple as changing this code in\n> > > builtin/worktree.c:validate_worktree_add():\n> >\n> > Coming from \"git clone\" background I would still expect --no-checkout\n> > to abort on non-empty directory (i.e. we always start at a good known\n> > state). Maybe another option can be used in combination with\n> > --no-checkout for this. And do we want the same option in \"git clone\"?\n>\n> Taking a potential use-case into account, it might be more appropriate\n> to compare this suggested behavior to git-init rather than to\n> git-clone. Say, for instance, someone downloads a \"tarball\" of a\n> project (with no .git/ directory), experimentally hacks on it for a\n> while and then decides that that work is worthy of being submitted to\n> the project as patches or a pull-request. One could imagine that a way\n> to accomplish this would be to \"git clone ...\" the project, and then\n> \"git worktree add --no-checkout /path/to/my/hacking\", followed by a\n> series of \"git add ...\" and \"git commit ...\" invocations to formalize\n> the changes into discreet commits.\n\nOr you could just git-clone directly to the place you unpacked the tarball.\n\n> This is analogous to how you might start hacking from scratch on a new\n> experimental project before you know if it will pan out, and before\n> you know if it will be worthy of placing under revision control. If it\n> does pan out, then you \"git init\" the existing populated directory,\n> and follow with a series of \"git add ...\" and \"git commit ...\"\n> invocations.\n>\n> I'm not sure how common such a use-case is, though. I recall being in\n> such a situation once or twice over the years, but that's not\n> necessarily a good metric. So, I'm not suggesting that such a feature\n> should or need be added to git-worktree, but the above thought\n> experiment perhaps provides some context for possible behavior.\n\nYeah I'm not suggesting we do anything immediately either.\n\nI still think though that we should change --no-checkout behavior.\n\"worktree add --no-checkout --keep-worktree\" is quite readable (and I\nassume this is not a popular use case that people will have to specify\nboth options often)\n-- \nDuy\n"},{"id":"376715","messageId":"cd006427-03ad-4823-e872-96903cc96fd0@gmx.de","threadId":"51182","inReplyTo":"CACsJy8DiueSPST64=iCZc=V6UtU61RXjJqhBHvG59BwFVSh3QA@mail.gmail.com","subject":"Re: worktree add already exists","fromName":"Ingo Wolf","fromEmail":"ingo.wolf@gmx.de","sentAt":"2019-06-05T15:30:45Z","receivedAt":"2019-06-05T15:30:55Z","isPatch":false,"sender":{"key":"ingo.wolf@gmx.de","avatar":null},"body":"Am 05.06.2019 um 12:17 schrieb Duy Nguyen:\n> \"worktree add --no-checkout --keep-worktree\" is quite readable\n\nworktree add --no-checkout -f (orce)\n\nI've expected to work on an not empty directory\n\n\n"},{"id":"376743","messageId":"CACsJy8AKNrC_XY+6bq1FpPCs4MWZa_jCSiAvjmypPjS0g26cHg@mail.gmail.com","threadId":"51182","inReplyTo":"cd006427-03ad-4823-e872-96903cc96fd0@gmx.de","subject":"Re: worktree add already exists","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-06T09:34:55Z","receivedAt":"2019-06-06T09:35:24Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Jun 5, 2019 at 10:30 PM Ingo Wolf <ingo.wolf@gmx.de> wrote:\n>\n> Am 05.06.2019 um 12:17 schrieb Duy Nguyen:\n> > \"worktree add --no-checkout --keep-worktree\" is quite readable\n>\n> worktree add --no-checkout -f (orce)\n>\n> I've expected to work on an not empty directory\n\nYeah --force works too. Not sure how it interacts with \"--force\n--force\". But --force is already overloaded, I don't think forcing\nharder is going to make it much worse.\n-- \nDuy\n"}]}