@matheusbsbs / matheus-bagliano / commits / 6fa8342b12
Fork 0

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 <sam@rfc1149.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Samuel Tardieu committed Nov 5, 2008 at 00:20 UTC 6fa8342b12aeb3e3895d3b3d8d34d45fa872ac45
1 file changed +12 -7
builtin-tag.c
+12 -7
@@ -344,7 +344,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
344 const char *object_ref, *tag;
345 struct ref_lock *lock;
346
347 - int annotate = 0, sign = 0, force = 0, lines = 0,
347 + int annotate = 0, sign = 0, force = 0, lines = -1,
348 list = 0, delete = 0, verify = 0;
349 const char *msgfile = NULL, *keyid = NULL;
350 struct msg_arg msg = { 0, STRBUF_INIT };
@@ -380,9 +380,19 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
380 }
381 if (sign)
382 annotate = 1;
383 + if (argc == 0 && !(delete || verify))
384 + list = 1;
385
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);
392 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.");
396 if (delete)
397 return for_each_tag_name(argv, delete_tag);
398 if (verify)
@@ -407,11 +417,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
417 }
418 }
419
410 - if (argc == 0) {
411 - if (annotate)
412 - usage_with_options(git_tag_usage, options);
413 - return list_tags(NULL, lines);
414 - }
420 tag = argv[0];
421
422 object_ref = argc == 2 ? argv[1] : "HEAD";