Code

Merge branch 'ei/worktree+filter'
[git.git] / setup.c
diff --git a/setup.c b/setup.c
index 14a4d955b5bec90251f2c464d4086b08945b8b59..01f74d4644c35862b2498ee8534213b2d76bf721 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -39,7 +39,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
        if (len) {
                int speclen = strlen(path);
                char *n = xmalloc(speclen + len + 1);
-       
+
                memcpy(n, prefix, len);
                memcpy(n + len, path, speclen+1);
                path = n;
@@ -47,7 +47,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
        return path;
 }
 
-/* 
+/*
  * Unlike prefix_path, this should be used if the named file does
  * not have to interact with index entry; i.e. name of a random file
  * on the filesystem.
@@ -251,6 +251,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
                        die("Not a git repository");
                }
                setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
+               gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
+               if (!gitdirenv)
+                       die("getenv after setenv failed");
        }
 
        if (PATH_MAX - 40 < strlen(gitdirenv)) {
@@ -290,6 +293,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
        if (gitdirenv[0] != '/') {
                setenv(GIT_DIR_ENVIRONMENT, gitdir, 1);
                gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
+               if (!gitdirenv)
+                       die("getenv after setenv failed");
                if (PATH_MAX - 40 < strlen(gitdirenv)) {
                        if (nongit_ok) {
                                *nongit_ok = 1;