git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] rev-list: don't show usage when we see empty ref patterns

From
Jeff King <peff@peff.net>
Date
Aug 2, 2017, 22:26 UTC
Message-ID
<20170802222606.lbibwzygs5mr2xv5@sigill.intra.peff.net>
In-Reply-To
<20170802222425.7xkoxniz2xbjlnku@sigill.intra.peff.net>

If the user gives us no starting point for a traversal, we want to complain with our normal usage message. But if they tried to do so with "--all" or "--glob", but that happened not to match any refs, the usage message isn't helpful. We should just give them the empty output they asked for instead.

Signed-off-by: Jeff King <peff@peff.net>
---
This will have a minor textual conflict with my reflog series, which
touches the same conditional.
 builtin/rev-list.c       | 3 ++-
 t/t6018-rev-list-glob.sh | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 95d84d5cd..1e9cc5948 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -350,7 +350,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 
 	if ((!revs.commits &&
 	     (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
-	      !revs.pending.nr)) ||
+	      !revs.pending.nr) &&
+	     !revs.rev_input_given) ||
 	    revs.diff)
 		usage(rev_list_usage);
 
diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh
index f8367b829..d3453c583 100755
--- a/t/t6018-rev-list-glob.sh
+++ b/t/t6018-rev-list-glob.sh
@@ -261,13 +261,13 @@ test_expect_failure 'rev-list should succeed with empty output on empty stdin' '
 	test_cmp expect actual
 '
 
-test_expect_failure 'rev-list should succeed with empty output with all refs excluded' '
+test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
 	>expect &&
 	git rev-list --exclude=* --all >actual &&
 	test_cmp expect actual
 '
 
-test_expect_failure 'rev-list should succeed with empty output with empty --all' '
+test_expect_success 'rev-list should succeed with empty output with empty --all' '
 	(
 		test_create_repo empty &&
 		cd empty &&
@@ -277,7 +277,7 @@ test_expect_failure 'rev-list should succeed with empty output with empty --all'
 	)
 '
 
-test_expect_failure 'rev-list should succeed with empty output with empty glob' '
+test_expect_success 'rev-list should succeed with empty output with empty glob' '
 	>expect &&
 	git rev-list --glob=does-not-match-anything >actual &&
 	test_cmp expect actual
-- 
2.14.0.rc1.586.g00244b0b6
Previous: Jeff KingNext: Jeff King
Message 6 of 13 in “handling empty inputs in the revision machinery”
  1. 0/4 handling empty inputs in the revision machineryJeff King, Aug 2, 2017
  2. 1/4 t6018: flesh out empty input/output rev-list testsJeff King, Aug 2, 2017
  3. 2/4 revision: add rev_input_given flagJeff King, Aug 2, 2017
  4. Junio C HamanoAug 2, 2017
  5. Jeff KingAug 2, 2017
  6. 3/4 rev-list: don't show usage when we see empty ref patternsJeff King, Aug 2, 2017
  7. 4/4 revision: do not fallback to default when rev_input_given is setJeff King, Aug 2, 2017
  8. Junio C HamanoAug 2, 2017
  9. Stefan BellerAug 2, 2017
  10. 5/4 revision: let --stdin set rev_input_givenJeff King, Aug 2, 2017
  11. Junio C HamanoAug 3, 2017
  12. Jeff KingAug 3, 2017
  13. Junio C HamanoAug 2, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.