git alias: try alias last.
This disables alias "foo" from being used for git-foo, and when we do use alias we check the built-in and then existing command names first and then alias as the fallback. This avoids the problem of common commands used in scripts getting clobbered by user specific aliases. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jun 5, 2006 at 18:09 UTC
a025463bc0ec2c894a88f2dfb44cf88ba71bb712
1 file changed
+14
-6
git.c
+14
-6
@@ -202,6 +202,7 @@ int main(int argc, const char **argv, char **envp)
202
char *slash = strrchr(cmd, '/');
203
char git_command[PATH_MAX + 1];
204
const char *exec_path = NULL;
205
+ int done_alias = 0;
206
207
/*
208
* Take the basename of argv[0] as the command
@@ -229,7 +230,6 @@ int main(int argc, const char **argv, char **envp)
230
if (!strncmp(cmd, "git-", 4)) {
231
cmd += 4;
232
argv[0] = cmd;
232
- handle_alias(&argc, &argv);
233
handle_internal_command(argc, argv, envp);
234
die("cannot handle %s internally", cmd);
235
}
@@ -287,13 +287,21 @@ int main(int argc, const char **argv, char **envp)
287
exec_path = git_exec_path();
288
prepend_to_path(exec_path, strlen(exec_path));
289
290
- handle_alias(&argc, &argv);
290
+ while (1) {
291
+ /* See if it's an internal command */
292
+ handle_internal_command(argc, argv, envp);
293
292
- /* See if it's an internal command */
293
- handle_internal_command(argc, argv, envp);
294
+ /* .. then try the external ones */
295
+ execv_git_cmd(argv);
296
295
- /* .. then try the external ones */
296
- execv_git_cmd(argv);
297
+ /* It could be an alias -- this works around the insanity
298
+ * of overriding "git log" with "git show" by having
299
+ * alias.log = show
300
+ */
301
+ if (done_alias || !handle_alias(&argc, &argv))
302
+ break;
303
+ done_alias = 1;
304
+ }
305
306
if (errno == ENOENT)
307
cmd_usage(0, exec_path, "'%s' is not a git-command", cmd);