git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Apr 12, 2007, 18:52 UTC
Message-ID
<20070412185203.GA28255@moooo.ath.cx>

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.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
 git.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/git.c b/git.c
index 33dd4d3..7def319 100644
--- a/git.c
+++ b/git.c
@@ -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")) {
-- 
1.5.1.1.81.g6aead-dirty
Message 1 of 1 in “bugfix, rfc alias.foo = --git-dir /path/to/repo ...”
  1. Matthias LederhoferApr 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.