require user to type full got command names or short aliases The previous strncmp-based approach was problematic, e.g. "co" was treated as an alias for "commit", while most users will expect "co" to map to "checkout". Introduce explicit aliases and document them.
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
diff --git a/got/got.1 b/got/got.1
index 5b0caca..73e5c0f 100644
--- a/got/got.1
+++ b/got/got.1
@@ -97,6 +97,9 @@ Only files beneath the specified
.Ar path-prefix
will be checked out.
.El
+.It Cm co
+Short alias for
+.Cm checkout .
.It Cm update [ Fl b Ar branch ] [ Fl c Ar commit ] [ Ar path ]
Update an existing work tree to a different commit.
Show the status of each affected file, using the following status codes:
@@ -147,6 +150,9 @@ automatically, provided the abbreviation is unique.
If this option is not specified, the most recent commit on the work tree's
branch will be used.
.El
+.It Cm up
+Short alias for
+.Cm update .
.It Cm status [ Ar path ]
Show the current modification status of files in a work tree,
using the following status codes:
@@ -164,6 +170,9 @@ using the following status codes:
If a
.Ar path
is specified, only show modifications within this path.
+.It Cm st
+Short alias for
+.Cm status .
.It Cm log [ Fl b ] [ Fl c Ar commit ] [ Fl C Ar number ] [ Fl l Ar N ] [ Fl p ] [ Fl r Ar repository-path ] [ path ]
Display history of a repository.
If a
@@ -356,6 +365,9 @@ List all existing branches in the repository.
.It Fl d Ar name
Delete the branch with the specified name from the repository.
.El
+.It Cm br
+Short alias for
+.Cm branch .
.It Cm add Ar file-path ...
Schedule unversioned files in a work tree for addition to the
repository in the next commit.
@@ -383,6 +395,9 @@ it will become an unversioned file again.
If a file was deleted with
.Cm got rm
it will be restored.
+.It Cm rv
+Short alias for
+.Cm revert .
.It Cm commit [ Fl m Ar message ] [ file-path ]
Create a new commit in the repository from local changes in a work tree
and use this commit as the new base commit for the work tree.
@@ -422,6 +437,9 @@ option,
.Cm got commit
opens a temporary file in an editor where a log message can be written.
.El
+.It Cm ci
+Short alias for
+.Cm commit .
.It Cm cherrypick Ar commit
Merge changes from a single
.Ar commit
@@ -462,6 +480,9 @@ to a single base commit with
.Cm got update .
If the work tree already contains files with merge conflicts, these
conflicts must be resolved first.
+.It Cm ch
+Short alias for
+.Cm cherrypick .
.It Cm backout Ar commit
Reverse-merge changes from a single
.Ar commit
@@ -502,6 +523,9 @@ to a single base commit with
.Cm got update .
If the work tree already contains files with merge conflicts, these
conflicts must be resolved first.
+.It Cm bo
+Short alias for
+.Cm backout .
.El
.Sh ENVIRONMENT
.Bl -tag -width GOT_AUTHOR
diff --git a/got/got.c b/got/got.c
index f51f008..e6a9bf7 100644
--- a/got/got.c
+++ b/got/got.c
@@ -70,6 +70,7 @@ struct got_cmd {
const char *cmd_name;
const struct got_error *(*cmd_main)(int, char *[]);
void (*cmd_usage)(void);
+ const char *cmd_alias;
};
__dead static void usage(void);
@@ -108,22 +109,22 @@ static const struct got_error* cmd_cherrypick(int, char *[]);
static const struct got_error* cmd_backout(int, char *[]);
static struct got_cmd got_commands[] = {
- { "init", cmd_init, usage_init },
- { "checkout", cmd_checkout, usage_checkout },
- { "update", cmd_update, usage_update },
- { "log", cmd_log, usage_log },
- { "diff", cmd_diff, usage_diff },
- { "blame", cmd_blame, usage_blame },
- { "tree", cmd_tree, usage_tree },
- { "status", cmd_status, usage_status },
- { "ref", cmd_ref, usage_ref },
- { "branch", cmd_branch, usage_branch },
- { "add", cmd_add, usage_add },
- { "rm", cmd_rm, usage_rm },
- { "revert", cmd_revert, usage_revert },
- { "commit", cmd_commit, usage_commit },
- { "cherrypick", cmd_cherrypick, usage_cherrypick },
- { "backout", cmd_backout, usage_backout },
+ { "init", cmd_init, usage_init, "" },
+ { "checkout", cmd_checkout, usage_checkout, "co" },
+ { "update", cmd_update, usage_update, "up" },
+ { "log", cmd_log, usage_log, "" },
+ { "diff", cmd_diff, usage_diff, "" },
+ { "blame", cmd_blame, usage_blame, "" },
+ { "tree", cmd_tree, usage_tree, "" },
+ { "status", cmd_status, usage_status, "st" },
+ { "ref", cmd_ref, usage_ref, "" },
+ { "branch", cmd_branch, usage_branch, "br" },
+ { "add", cmd_add, usage_add, "" },
+ { "rm", cmd_rm, usage_rm, "" },
+ { "revert", cmd_revert, usage_revert, "rv" },
+ { "commit", cmd_commit, usage_commit, "ci" },
+ { "cherrypick", cmd_cherrypick, usage_cherrypick, "ch" },
+ { "backout", cmd_backout, usage_backout, "bo" },
};
int
@@ -162,7 +163,8 @@ main(int argc, char *argv[])
cmd = &got_commands[i];
- if (strncmp(cmd->cmd_name, argv[0], strlen(argv[0])))
+ if (strcmp(cmd->cmd_name, argv[0]) != 0 &&
+ strcmp(cmd->cmd_alias, argv[0]) != 0)
continue;
if (hflag)