Merge branch 'jk/rev-list-empty-input' into maint

"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
This commit is contained in:
Junio C Hamano 2017-09-10 17:02:48 +09:00
Родитель 638eb4e701 5d34d1ac06
Коммит c2a3bb47f0
5 изменённых файлов: 26 добавлений и 13 удалений

Просмотреть файл

@ -352,7 +352,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
if ((!revs.commits && reflog_walk_empty(revs.reflog_info) && if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
(!(revs.tag_objects || revs.tree_objects || revs.blob_objects) && (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
!revs.pending.nr)) || !revs.pending.nr) &&
!revs.rev_input_given) ||
revs.diff) revs.diff)
usage(rev_list_usage); usage(rev_list_usage);

Просмотреть файл

@ -1166,6 +1166,7 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,
{ {
cb->all_revs = revs; cb->all_revs = revs;
cb->all_flags = flags; cb->all_flags = flags;
revs->rev_input_given = 1;
} }
void clear_ref_exclusion(struct string_list **ref_excludes_p) 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
opt->tweak(revs, opt); opt->tweak(revs, opt);
if (revs->show_merge) if (revs->show_merge)
prepare_show_merge(revs); prepare_show_merge(revs);
if (revs->def && !revs->pending.nr && !got_rev_arg) { if (revs->def && !revs->pending.nr && !revs->rev_input_given && !got_rev_arg) {
struct object_id oid; struct object_id oid;
struct object *object; struct object *object;
struct object_context oc; struct object_context oc;

Просмотреть файл

@ -71,6 +71,13 @@ struct rev_info {
const char *def; const char *def;
struct pathspec prune_data; struct pathspec prune_data;
/*
* Whether the arguments parsed by setup_revisions() included any
* "input" revisions that might still have yielded an empty pending
* list (e.g., patterns like "--all" or "--glob").
*/
int rev_input_given;
/* topo-sort */ /* topo-sort */
enum rev_sort_order sort_order; enum rev_sort_order sort_order;

Просмотреть файл

@ -1523,6 +1523,12 @@ test_expect_success 'log diagnoses bogus HEAD' '
test_i18ngrep broken stderr test_i18ngrep broken stderr
' '
test_expect_success 'log does not default to HEAD when rev input is given' '
>expect &&
git log --branches=does-not-exist >actual &&
test_cmp expect actual
'
test_expect_success 'set up --source tests' ' test_expect_success 'set up --source tests' '
git checkout --orphan source-a && git checkout --orphan source-a &&
test_commit one && test_commit one &&

Просмотреть файл

@ -255,27 +255,19 @@ test_expect_success 'rev-list accumulates multiple --exclude' '
compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
' '
test_expect_failure 'rev-list should succeed with empty output on empty stdin' '
# "git rev-list<ENTER>" is likely to be a bug in the calling script and may
# deserve an error message, but do cases where set of refs programmatically
# given using globbing and/or --stdin need to fail with the same error, or
# are we better off reporting a success with no output? The following few
# tests document the current behaviour to remind us that we might want to
# think about this issue.
test_expect_failure 'rev-list may want to succeed with empty output on no input (1)' '
>expect && >expect &&
git rev-list --stdin <expect >actual && git rev-list --stdin <expect >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_failure 'rev-list may want to succeed with empty output on no input (2)' ' test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
>expect && >expect &&
git rev-list --exclude=* --all >actual && git rev-list --exclude=* --all >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_failure 'rev-list may want to succeed with empty output on no input (3)' ' test_expect_success 'rev-list should succeed with empty output with empty --all' '
( (
test_create_repo empty && test_create_repo empty &&
cd empty && cd empty &&
@ -285,6 +277,12 @@ test_expect_failure 'rev-list may want to succeed with empty output on no input
) )
' '
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
'
test_expect_success 'shortlog accepts --glob/--tags/--remotes' ' test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
compare shortlog "subspace/one subspace/two" --branches=subspace && compare shortlog "subspace/one subspace/two" --branches=subspace &&