Skip to content

Commit 6fa8342

Browse files
samueltardieugitster
authored andcommitted
tag: Check that options are only allowed in the appropriate mode
If "git tag -d -l -v ..." is called, only "-l" is honored, which is arbitrary and wrong. Also, unrecognized options are accepted in the wrong modes, causing for example "git tag -n 100" to create a tag named "100" while the user may have wanted to type "git tag -n100". This patch checks that "git tag" knows in what mode it operates before performing any operation and accepts only the related options. Signed-off-by: Samuel Tardieu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a5a323f commit 6fa8342

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-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";

0 commit comments

Comments
 (0)