Skip to content

Commit 27f6496

Browse files
committed
Merge branch 'st/maint-tag' into maint
* st/maint-tag: tag: Add more tests about mixing incompatible modes and options tag: Check that options are only allowed in the appropriate mode
2 parents 270c354 + e0e03a7 commit 27f6496

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

builtin-tag.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
344344
const char *object_ref, *tag;
345345
struct ref_lock *lock;
346346

347-
int annotate = 0, sign = 0, force = 0, lines = 0,
347+
int annotate = 0, sign = 0, force = 0, lines = -1,
348348
list = 0, delete = 0, verify = 0;
349349
const char *msgfile = NULL, *keyid = NULL;
350350
struct msg_arg msg = { 0, STRBUF_INIT };
@@ -380,9 +380,19 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
380380
}
381381
if (sign)
382382
annotate = 1;
383+
if (argc == 0 && !(delete || verify))
384+
list = 1;
383385

386+
if ((annotate || msg.given || msgfile || force) &&
387+
(list || delete || verify))
388+
usage_with_options(git_tag_usage, options);
389+
390+
if (list + delete + verify > 1)
391+
usage_with_options(git_tag_usage, options);
384392
if (list)
385-
return list_tags(argv[0], lines);
393+
return list_tags(argv[0], lines == -1 ? 0 : lines);
394+
if (lines != -1)
395+
die("-n option is only allowed with -l.");
386396
if (delete)
387397
return for_each_tag_name(argv, delete_tag);
388398
if (verify)
@@ -407,11 +417,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
407417
}
408418
}
409419

410-
if (argc == 0) {
411-
if (annotate)
412-
usage_with_options(git_tag_usage, options);
413-
return list_tags(NULL, lines);
414-
}
415420
tag = argv[0];
416421

417422
object_ref = argc == 2 ? argv[1] : "HEAD";

t/t7004-tag.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,4 +1090,15 @@ test_expect_success 'filename for the message is relative to cwd' '
10901090
git cat-file tag tag-from-subdir-2 | grep "in sub directory"
10911091
'
10921092
1093+
# mixing modes and options:
1094+
1095+
test_expect_success 'mixing incompatibles modes and options is forbidden' '
1096+
test_must_fail git tag -a
1097+
test_must_fail git tag -l -v
1098+
test_must_fail git tag -n 100
1099+
test_must_fail git tag -l -m msg
1100+
test_must_fail git tag -l -F some file
1101+
test_must_fail git tag -v -s
1102+
'
1103+
10931104
test_done

0 commit comments

Comments
 (0)