git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Nicholas Guriev <guriev-ns@ya.ru>
To: git@vger.kernel.org
Subject: [PATCH] worktree: treat "list" as default command
Date: Sat, 13 Jun 2020 10:14:21 +0300	[thread overview]
Message-ID: <202006130730.05D7UB99010559@dandelion.mymedia.su> (raw)

Perceive simple "git worktree" without a subcommand as "git worktree list"
for consistency with "git submodule" that already can work in such a way.

Signed-off-by: Nicholas Guriev <guriev-ns@ya.ru>
---
 builtin/worktree.c       |  4 ++--
 t/t2402-worktree-list.sh | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index d99db356..ad949eb5 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -960,10 +960,10 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
 
 	git_config(git_worktree_config, NULL);
 
-	if (ac < 2)
-		usage_with_options(worktree_usage, options);
 	if (!prefix)
 		prefix = "";
+	if (ac < 2 || av[1][0] == '-')
+		return list(ac, av, prefix);
 	if (!strcmp(av[1], "add"))
 		return add(ac - 1, av + 1, prefix);
 	if (!strcmp(av[1], "prune"))
diff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh
index 52585ec2..e53bafa3 100755
--- a/t/t2402-worktree-list.sh
+++ b/t/t2402-worktree-list.sh
@@ -157,4 +157,16 @@ test_expect_success 'worktree path when called in .git directory' '
 	test_cmp list1 list2
 '
 
+test_expect_success '"list" is the default command' '
+	git worktree >out1 &&
+	git worktree list >out2 &&
+	test_cmp out1 out2
+'
+
+test_expect_success 'options are passed to default command' '
+	git worktree --porcelain >out1 &&
+	git worktree list --porcelain >out2 &&
+	test_cmp out1 out2
+'
+
 test_done
-- 
2.25.1


             reply	other threads:[~2020-06-13  7:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-13  7:14 Nicholas Guriev [this message]
2020-06-13 16:36 ` [PATCH] worktree: treat "list" as default command Junio C Hamano
2020-06-14  5:56   ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202006130730.05D7UB99010559@dandelion.mymedia.su \
    --to=guriev-ns@ya.ru \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).