{"thread":{"id":"16175","subject":"[(v2) PATCH 1/2] tag: Check that options are only allowed in the appropriate mode","startedAt":"2008-11-04T23:20:31Z","lastAt":"2008-11-04T23:47:22Z","messageCount":3,"participants":["Samuel Tardieu","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"94931","messageId":"20081104232031.19090.47633.stgit@arrakis.enst.fr","threadId":"16175","inReplyTo":null,"subject":"[(v2) PATCH 1/2] tag: Check that options are only allowed in the appropriate mode","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-11-04T23:20:31Z","receivedAt":"2008-11-04T23:20:31Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"If \"git tag -d -l -v ...\" is called, only \"-l\" is honored, which is\narbitrary and wrong. Also, unrecognized options are accepted in the\nwrong modes, causing for example \"git tag -n 100\" to create a tag\nnamed \"100\" while the user may have wanted to type \"git tag -n100\".\n\nThis patch checks that \"git tag\" knows in what mode it operates before\nperforming any operation and accepts only the related options.\n\nSigned-off-by: Samuel Tardieu <sam@rfc1149.net>\n---\n builtin-tag.c |   19 ++++++++++++-------\n 1 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex 84db156..d339971 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -344,7 +344,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tconst char *object_ref, *tag;\n \tstruct ref_lock *lock;\n \n-\tint annotate = 0, sign = 0, force = 0, lines = 0,\n+\tint annotate = 0, sign = 0, force = 0, lines = -1,\n \t\tlist = 0, delete = 0, verify = 0;\n \tconst char *msgfile = NULL, *keyid = NULL;\n \tstruct msg_arg msg = { 0, STRBUF_INIT };\n@@ -380,9 +380,19 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t}\n \tif (sign)\n \t\tannotate = 1;\n+\tif (argc == 0 && !(delete || verify))\n+\t\tlist = 1;\n \n+\tif ((annotate || msg.given || msgfile || force) &&\n+\t    (list || delete || verify))\n+\t\tusage_with_options(git_tag_usage, options);\n+\n+\tif (list + delete + verify > 1)\n+\t\tusage_with_options(git_tag_usage, options);\n \tif (list)\n-\t\treturn list_tags(argv[0], lines);\n+\t\treturn list_tags(argv[0], lines == -1 ? 0 : lines);\n+\tif (lines != -1)\n+\t\tdie(\"-n option is only allowed with -l.\");\n \tif (delete)\n \t\treturn for_each_tag_name(argv, delete_tag);\n \tif (verify)\n@@ -406,11 +416,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tif (argc == 0) {\n-\t\tif (annotate)\n-\t\t\tusage_with_options(git_tag_usage, options);\n-\t\treturn list_tags(NULL, lines);\n-\t}\n \ttag = argv[0];\n \n \tobject_ref = argc == 2 ? argv[1] : \"HEAD\";\n"},{"id":"94932","messageId":"20081104232036.19090.6085.stgit@arrakis.enst.fr","threadId":"16175","inReplyTo":"20081104232031.19090.47633.stgit@arrakis.enst.fr","subject":"[(v2) PATCH 2/2] tag: Add more tests about mixing incompatible modes and options","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-11-04T23:20:36Z","receivedAt":"2008-11-04T23:20:36Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"Signed-off-by: Samuel Tardieu <sam@rfc1149.net>\n---\n t/t7004-tag.sh |   11 +++++++++++\n 1 files changed, 11 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\nindex f0edbf1..f377fea 100755\n--- a/t/t7004-tag.sh\n+++ b/t/t7004-tag.sh\n@@ -1090,4 +1090,15 @@ test_expect_success 'filename for the message is relative to cwd' '\n \tgit cat-file tag tag-from-subdir-2 | grep \"in sub directory\"\n '\n \n+# mixing modes and options:\n+\n+test_expect_success 'mixing incompatibles modes and options is forbidden' '\n+\ttest_must_fail git tag -a\n+\ttest_must_fail git tag -l -v\n+\ttest_must_fail git tag -n 100\n+\ttest_must_fail git tag -l -m msg\n+\ttest_must_fail git tag -l -F some file\n+\ttest_must_fail git tag -v -s\n+'\n+\n test_done\n"},{"id":"94935","messageId":"7vk5bjoxyt.fsf@gitster.siamese.dyndns.org","threadId":"16175","inReplyTo":"20081104232036.19090.6085.stgit@arrakis.enst.fr","subject":"Re: [(v2) PATCH 2/2] tag: Add more tests about mixing incompatible modes and options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-11-04T23:47:22Z","receivedAt":"2008-11-04T23:47:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; will queue.\n"}]}