switch 'got tag' commit argument to a -c option for consistency
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
diff --git a/got/got.1 b/got/got.1
index 32d8fc7..60da95a 100644
--- a/got/got.1
+++ b/got/got.1
@@ -606,7 +606,7 @@ Do not switch and update the work tree after creating a new branch.
.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,
diff --git a/got/got.c b/got/got.c
index 6511394..29a1cd6 100644
--- a/got/got.c
+++ b/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
diff --git a/regress/cmdline/tag.sh b/regress/cmdline/tag.sh
index 4fe82be..fb5ed4e 100755
--- a/regress/cmdline/tag.sh
+++ b/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