summaryrefslogtreecommitdiffstats
path: root/git.c
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2018-09-16 09:50:01 +0200
committerJunio C Hamano <gitster@pobox.com>2018-09-17 17:50:04 +0200
commit82f71d9a5a9df718553bf257ad8610e2ef1e1179 (patch)
treeb5379b1b4eee70b50baf89090865d673d03c70df /git.c
parentalias: add support for aliases of an alias (diff)
downloadgit-82f71d9a5a9df718553bf257ad8610e2ef1e1179.tar.xz
git-82f71d9a5a9df718553bf257ad8610e2ef1e1179.zip
alias: show the call history when an alias is looping
Just printing the command that the user entered is not particularly helpful when trying to find the alias that causes the loop. Print the history of substituted commands to help the user find the offending alias. Mark the entrypoint of the loop with "<==" and the last command (which looped back to the entrypoint) with "==>". Signed-off-by: Tim Schumacher <timschumi@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git.c')
-rw-r--r--git.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/git.c b/git.c
index 15727c17f1..a20eb4fa15 100644
--- a/git.c
+++ b/git.c
@@ -675,6 +675,7 @@ static int run_argv(int *argcp, const char ***argv)
{
int done_alias = 0;
struct string_list cmd_list = STRING_LIST_INIT_NODUP;
+ struct string_list_item *seen;
while (1) {
/*
@@ -692,9 +693,21 @@ static int run_argv(int *argcp, const char ***argv)
/* .. then try the external ones */
execv_dashed_external(*argv);
- if (unsorted_string_list_has_string(&cmd_list, *argv[0])) {
+ seen = unsorted_string_list_lookup(&cmd_list, *argv[0]);
+ if (seen) {
+ int i;
+ struct strbuf sb = STRBUF_INIT;
+ for (i = 0; i < cmd_list.nr; i++) {
+ struct string_list_item *item = &cmd_list.items[i];
+
+ strbuf_addf(&sb, "\n %s", item->string);
+ if (item == seen)
+ strbuf_addstr(&sb, " <==");
+ else if (i == cmd_list.nr - 1)
+ strbuf_addstr(&sb, " ==>");
+ }
die(_("alias loop detected: expansion of '%s' does"
- " not terminate"), cmd_list.items[0].string);
+ " not terminate:%s"), cmd_list.items[0].string, sb.buf);
}
string_list_append(&cmd_list, *argv[0]);