Skip to contentSkip to conversation

bugfix, rfc alias.foo = --git-dir /path/to/repo ...

PATCH Matthias Lederhofer 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

I found this while playing with alias.foo = --git-dir /path/to/repo (looking for other problems):

    $ git foo
    *** glibc detected *** realloc(): invalid pointer: 0x0811d14c ***
    [1]    24815 abort      git foo

Patch for this problem is below. Now that this is fixed the more interesting thing is

    alias.foo = --git-dir /tmp/foo.git log
    alias.bar = --git-dir /tmp/foo.git status

The first one will use the current repository and the second one will use /tmp/foo.git (because status is no built-in command).

Possible solutions:
(1) allow changing the repository path after reading the config
(2) deny the use of --git-dir in aliases
(3) reexec git for the alias instead of handling commands internally

    if --git-dir is used

I'm in favour of (3).

---
fix bug in handle_options

handle_options did not count the number of used arguments correctly. When --git-dir was used the extra argument was not added to the number of handled arguments.

---
 git.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
git.c +1 -0
index 33dd4d3..7def319 100644
@@ -66,6 +66,7 @@ static int handle_options(const char*** argv, int* argc)
 			setenv(GIT_DIR_ENVIRONMENT, (*argv)[1], 1);
 			(*argv)++;
 			(*argc)--;
+			handled++;
 		} else if (!prefixcmp(cmd, "--git-dir=")) {
 			setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
 		} else if (!strcmp(cmd, "--bare")) {
Signature · 1 line
1.5.1.1.81.g6aead-dirty