diff options
Diffstat (limited to 'setup.c')
-rw-r--r-- | setup.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -135,6 +135,7 @@ int path_inside_repo(const char *prefix, const char *path) int check_filename(const char *prefix, const char *arg) { const char *name; + char *to_free = NULL; struct stat st; if (starts_with(arg, ":/")) { @@ -142,13 +143,17 @@ int check_filename(const char *prefix, const char *arg) return 1; name = arg + 2; } else if (prefix) - name = prefix_filename(prefix, strlen(prefix), arg); + name = to_free = prefix_filename(prefix, arg); else name = arg; - if (!lstat(name, &st)) + if (!lstat(name, &st)) { + free(to_free); return 1; /* file exists */ - if (errno == ENOENT || errno == ENOTDIR) + } + if (errno == ENOENT || errno == ENOTDIR) { + free(to_free); return 0; /* file does not exist */ + } die_errno("failed to stat '%s'", arg); } @@ -982,7 +987,7 @@ const char *setup_git_directory_gently(int *nongit_ok) { static struct strbuf cwd = STRBUF_INIT; struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT; - const char *prefix; + const char *prefix, *env_prefix; /* * We may have read an incomplete configuration before @@ -1040,6 +1045,10 @@ const char *setup_git_directory_gently(int *nongit_ok) die("BUG: unhandled setup_git_directory_1() result"); } + env_prefix = getenv(GIT_TOPLEVEL_PREFIX_ENVIRONMENT); + if (env_prefix) + prefix = env_prefix; + if (prefix) setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1); else |