Skip to content

Commit 8fbaf0b

Browse files
committed
Merge branch 'jk/rev-list-empty-input'
"git log --tag=no-such-tag" showed log starting from HEAD, which has been fixed---it now shows nothing. * jk/rev-list-empty-input: revision: do not fallback to default when rev_input_given is set rev-list: don't show usage when we see empty ref patterns revision: add rev_input_given flag t6018: flesh out empty input/output rev-list tests
2 parents 9c1259a + 5d34d1a commit 8fbaf0b

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

builtin/rev-list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
352352

353353
if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
354354
(!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
355-
!revs.pending.nr)) ||
355+
!revs.pending.nr) &&
356+
!revs.rev_input_given) ||
356357
revs.diff)
357358
usage(rev_list_usage);
358359

revision.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,
11661166
{
11671167
cb->all_revs = revs;
11681168
cb->all_flags = flags;
1169+
revs->rev_input_given = 1;
11691170
}
11701171

11711172
void clear_ref_exclusion(struct string_list **ref_excludes_p)
@@ -2313,7 +2314,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
23132314
opt->tweak(revs, opt);
23142315
if (revs->show_merge)
23152316
prepare_show_merge(revs);
2316-
if (revs->def && !revs->pending.nr && !got_rev_arg) {
2317+
if (revs->def && !revs->pending.nr && !revs->rev_input_given && !got_rev_arg) {
23172318
struct object_id oid;
23182319
struct object *object;
23192320
struct object_context oc;

revision.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ struct rev_info {
7171
const char *def;
7272
struct pathspec prune_data;
7373

74+
/*
75+
* Whether the arguments parsed by setup_revisions() included any
76+
* "input" revisions that might still have yielded an empty pending
77+
* list (e.g., patterns like "--all" or "--glob").
78+
*/
79+
int rev_input_given;
80+
7481
/* topo-sort */
7582
enum rev_sort_order sort_order;
7683

t/t4202-log.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,12 @@ test_expect_success 'log diagnoses bogus HEAD' '
15231523
test_i18ngrep broken stderr
15241524
'
15251525

1526+
test_expect_success 'log does not default to HEAD when rev input is given' '
1527+
>expect &&
1528+
git log --branches=does-not-exist >actual &&
1529+
test_cmp expect actual
1530+
'
1531+
15261532
test_expect_success 'set up --source tests' '
15271533
git checkout --orphan source-a &&
15281534
test_commit one &&

t/t6018-rev-list-glob.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,27 +255,19 @@ test_expect_success 'rev-list accumulates multiple --exclude' '
255255
compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
256256
'
257257

258-
259-
# "git rev-list<ENTER>" is likely to be a bug in the calling script and may
260-
# deserve an error message, but do cases where set of refs programmatically
261-
# given using globbing and/or --stdin need to fail with the same error, or
262-
# are we better off reporting a success with no output? The following few
263-
# tests document the current behaviour to remind us that we might want to
264-
# think about this issue.
265-
266-
test_expect_failure 'rev-list may want to succeed with empty output on no input (1)' '
258+
test_expect_failure 'rev-list should succeed with empty output on empty stdin' '
267259
>expect &&
268260
git rev-list --stdin <expect >actual &&
269261
test_cmp expect actual
270262
'
271263

272-
test_expect_failure 'rev-list may want to succeed with empty output on no input (2)' '
264+
test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
273265
>expect &&
274266
git rev-list --exclude=* --all >actual &&
275267
test_cmp expect actual
276268
'
277269

278-
test_expect_failure 'rev-list may want to succeed with empty output on no input (3)' '
270+
test_expect_success 'rev-list should succeed with empty output with empty --all' '
279271
(
280272
test_create_repo empty &&
281273
cd empty &&
@@ -285,6 +277,12 @@ test_expect_failure 'rev-list may want to succeed with empty output on no input
285277
)
286278
'
287279

280+
test_expect_success 'rev-list should succeed with empty output with empty glob' '
281+
>expect &&
282+
git rev-list --glob=does-not-match-anything >actual &&
283+
test_cmp expect actual
284+
'
285+
288286
test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
289287
290288
compare shortlog "subspace/one subspace/two" --branches=subspace &&

0 commit comments

Comments
 (0)