{"thread":{"id":"53669","subject":"[PATCH] worktree: treat \"list\" as default command","startedAt":"2020-06-13T07:34:12Z","lastAt":"2020-06-14T05:56:47Z","messageCount":3,"participants":["Nicholas Guriev","Junio C Hamano","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"399639","messageId":"202006130730.05D7UB99010559@dandelion.mymedia.su","threadId":"53669","inReplyTo":null,"subject":"[PATCH] worktree: treat \"list\" as default command","fromName":"Nicholas Guriev","fromEmail":"guriev-ns@ya.ru","sentAt":"2020-06-13T07:14:21Z","receivedAt":"2020-06-13T07:34:12Z","isPatch":true,"sender":{"key":"guriev-ns@ya.ru","avatar":"https://avatars.githubusercontent.com/u/9163157?v=4"},"body":"Perceive simple \"git worktree\" without a subcommand as \"git worktree list\"\nfor consistency with \"git submodule\" that already can work in such a way.\n\nSigned-off-by: Nicholas Guriev <guriev-ns@ya.ru>\n---\n builtin/worktree.c       |  4 ++--\n t/t2402-worktree-list.sh | 12 ++++++++++++\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex d99db356..ad949eb5 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -960,10 +960,10 @@ int cmd_worktree(int ac, const char **av, const char *prefix)\n \n \tgit_config(git_worktree_config, NULL);\n \n-\tif (ac < 2)\n-\t\tusage_with_options(worktree_usage, options);\n \tif (!prefix)\n \t\tprefix = \"\";\n+\tif (ac < 2 || av[1][0] == '-')\n+\t\treturn list(ac, av, prefix);\n \tif (!strcmp(av[1], \"add\"))\n \t\treturn add(ac - 1, av + 1, prefix);\n \tif (!strcmp(av[1], \"prune\"))\ndiff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh\nindex 52585ec2..e53bafa3 100755\n--- a/t/t2402-worktree-list.sh\n+++ b/t/t2402-worktree-list.sh\n@@ -157,4 +157,16 @@ test_expect_success 'worktree path when called in .git directory' '\n \ttest_cmp list1 list2\n '\n \n+test_expect_success '\"list\" is the default command' '\n+\tgit worktree >out1 &&\n+\tgit worktree list >out2 &&\n+\ttest_cmp out1 out2\n+'\n+\n+test_expect_success 'options are passed to default command' '\n+\tgit worktree --porcelain >out1 &&\n+\tgit worktree list --porcelain >out2 &&\n+\ttest_cmp out1 out2\n+'\n+\n test_done\n-- \n2.25.1\n\n"},{"id":"399656","messageId":"xmqqr1uizzwf.fsf@gitster.c.googlers.com","threadId":"53669","inReplyTo":"202006130730.05D7UB99010559@dandelion.mymedia.su","subject":"Re: [PATCH] worktree: treat \"list\" as default command","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-13T16:36:16Z","receivedAt":"2020-06-13T16:36:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicholas Guriev <guriev-ns@ya.ru> writes:\n\n> Perceive simple \"git worktree\" without a subcommand as \"git worktree list\"\n> for consistency with \"git submodule\" that already can work in such a way.\n\n\"git branch\" works the same way, and probably \"git remote\", too?\n\n\"git config\" doesn't work that way, though.  Should it default to\nthe list mode (rhetorical/tongue-in-cheek question---but it gives a\nhint for writing the justification to decide where to draw the line).\n"},{"id":"399683","messageId":"CAPig+cRLkv=gd58Qm2MiKz2H74s3O1zoQ4GZ_cBE7QkbBCqN4A@mail.gmail.com","threadId":"53669","inReplyTo":"xmqqr1uizzwf.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] worktree: treat \"list\" as default command","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-06-14T05:56:32Z","receivedAt":"2020-06-14T05:56:47Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, Jun 13, 2020 at 12:36 PM Junio C Hamano <gitster@pobox.com> wrote:\n> Nicholas Guriev <guriev-ns@ya.ru> writes:\n> > Perceive simple \"git worktree\" without a subcommand as \"git worktree list\"\n> > for consistency with \"git submodule\" that already can work in such a way.\n>\n> \"git branch\" works the same way, and probably \"git remote\", too?\n>\n> \"git config\" doesn't work that way, though. Should it default to\n> the list mode (rhetorical/tongue-in-cheek question---but it gives a\n> hint for writing the justification to decide where to draw the line).\n\nMy knee-jerk reaction to this patch is not to accept such a change,\nthough I can't fully articulate why I feel this way.\n\nOne concrete reason I'm not enthused about this change is, as Junio\nnotes, there is no consensus even among Git commands, as to what\naction should be taken when not specified explicitly. Although bare\n\"git branch\" is interpreted as \"git branch list\", bare \"git stash\" is\n_not_ interpreted as \"git stash list\", but instead as \"git stash\npush\". It's possible to imagine someone familiar with \"git stash\"\ncoming along and expecting bare \"git worktree\" to mean \"git worktree\nadd\".\n\nI also have a vague recollection from past mailing list discussions\nthat people eventually consider it flawed UI design for a command to\nperform some default action when none is requested explicitly. Bare\n\"git stash\" is one such example which comes to mind as being\nconsidered poor UI design. (It's possible that this recollection is\nincorrect; I haven't bothered trying to dig up any past discussions.)\n\nFinally, not having a default action for bare \"git worktree\" was a\ndeliberate design decision, probably (at least in part) motivated by\nthe above considerations. So, I'm hesitant about accepting such a\nchange without stronger justification.\n\nThe patch itself looks reasonable -- based upon a superficial scan --\nalthough I'd probably combine the two new tests (though that's\nsubjective). To be accepted, however (assuming people are convinced it\nis a worthwhile change), it would almost certainly need to include an\nupdate to Documentation/git-worktree.txt.\n"}]}