commit 80106605fef38d5bd94de493c3aa9ccdbcb9c8f8 from: Stefan Sperling date: Mon Feb 24 20:31:09 2020 UTC switch 'got tag' commit argument to a -c option for consistency commit - da76fce2dfde1786444285db2a03ddf14328c662 commit + 80106605fef38d5bd94de493c3aa9ccdbcb9c8f8 blob - 32d8fc768f703d3c9e8fac8881adf39cfbc3583d blob + 60da95afedf6b34f6eba7c8f546b7bad802dfa6b --- got/got.1 +++ got/got.1 @@ -606,7 +606,7 @@ Do not switch and update the work tree after creating .It Cm br Short alias for .Cm branch . -.It Cm tag Oo Fl m Ar message Oc Oo Fl r Ar repository-path Oc Oo Fl l Oc Ar name Op Ar commit +.It Cm tag Oo Fl c Ar commit Oc Oo Fl m Ar message Oc Oo Fl r Ar repository-path Oc Oo Fl l Oc Ar name Manage tags in a repository. .Pp Tags are managed via references which live in the @@ -618,24 +618,29 @@ command operates on references in this namespace only. References in this namespace point at tag objects which contain a pointer to another object, a tag message, as well as author and timestamp information. .Pp -Expect one or two arguments and attempt to create a tag with the given +Attempt to create a tag with the given .Ar name , and make this tag point at the given .Ar commit . If no commit is specified, default to the latest commit on the work tree's current branch if invoked in a work tree, and to a commit resolved via the repository's HEAD reference otherwise. -Otherwise, the expected argument is a commit ID SHA1 hash or an existing -reference or tag name which will be resolved to a commit ID. -An abbreviated hash argument will be expanded to a full SHA1 hash -automatically, provided the abbreviation is unique. .Pp The options for .Cm got tag are as follows: .Bl -tag -width Ds +.It Fl c Ar commit +Make the newly created tag reference point at the specified +.Ar commit . +The expected +.Ar commit +argument is a commit ID SHA1 hash or an existing reference or tag name which +will be resolved to a commit ID. +An abbreviated hash argument will be expanded to a full SHA1 hash +automatically, provided the abbreviation is unique. .It Fl m Ar message -Use the specified tag message when creating the new tag +Use the specified tag message when creating the new tag. Without the .Fl m option, blob - 6511394034a17291d582179257e2235d6f21731a blob + 29a1cd66bc29f275ce5a281897b333c512af0187 --- got/got.c +++ got/got.c @@ -3650,8 +3650,8 @@ __dead static void usage_tag(void) { fprintf(stderr, - "usage: %s tag [-r repository] | -l | " - "[-m message] name [commit]\n", getprogname()); + "usage: %s tag [-c commit] [-r repository] [-l] " + "[-m message] name\n", getprogname()); exit(1); } @@ -4002,8 +4002,11 @@ cmd_tag(int argc, char *argv[]) const char *tag_name, *commit_id_arg = NULL, *tagmsg = NULL; int ch, do_list = 0; - while ((ch = getopt(argc, argv, "m:r:l")) != -1) { + while ((ch = getopt(argc, argv, "c:m:r:l")) != -1) { switch (ch) { + case 'c': + commit_id_arg = optarg; + break; case 'm': tagmsg = optarg; break; @@ -4027,14 +4030,15 @@ cmd_tag(int argc, char *argv[]) argv += optind; if (do_list) { + if (commit_id_arg != NULL) + errx(1, "-c option can only be used when creating a tag"); if (tagmsg) - errx(1, "-l and -m options are mutually exclusive\n"); + errx(1, "-l and -m options are mutually exclusive"); if (argc > 0) usage_tag(); - } else if (argc < 1 || argc > 2) + } else if (argc != 1) usage_tag(); - else if (argc > 1) - commit_id_arg = argv[1]; + tag_name = argv[0]; #ifndef PROFILE blob - 4fe82be2ade02d326fa45a5b99005bf6bda52252 blob + fb5ed4ec1a17f3f2d28601e6ab05fe32d7d6b879 --- regress/cmdline/tag.sh +++ regress/cmdline/tag.sh @@ -23,7 +23,7 @@ function test_tag_create { local tag2=2.0.0 # Create a tag based on repository's HEAD reference - got tag -m 'test' -r $testroot/repo $tag HEAD > $testroot/stdout + got tag -m 'test' -r $testroot/repo -c HEAD $tag > $testroot/stdout ret="$?" if [ "$ret" != "0" ]; then echo "got ref command failed unexpectedly" @@ -88,7 +88,7 @@ function test_tag_create { # Attempt to create a tag pointing at a non-commit local tree_id=`git_show_tree $testroot/repo` - (cd $testroot/wt && got tag -m 'test' foobar $tree_id \ + (cd $testroot/wt && got tag -m 'test' -c $tree_id foobar \ 2> $testroot/stderr) ret="$?" if [ "$ret" == "0" ]; then