Code

Always set *nongit_ok in setup_git_directory_gently()
[git.git] / setup.c
diff --git a/setup.c b/setup.c
index bc80301c4239f1f101670cc623badb8bb694bd3d..3d2d9580f3283b4e4bc741d98863777510bd5173 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -91,7 +91,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
 {
        const char *orig = path;
        char *sanitized = xmalloc(len + strlen(path) + 1);
-       if (*orig == '/')
+       if (is_absolute_path(orig))
                strcpy(sanitized, path);
        else {
                if (len)
@@ -100,7 +100,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
        }
        if (sanitary_path_copy(sanitized, sanitized))
                goto error_out;
-       if (*orig == '/') {
+       if (is_absolute_path(orig)) {
                const char *work_tree = get_git_work_tree();
                size_t len = strlen(work_tree);
                size_t total = strlen(sanitized) + 1;
@@ -202,6 +202,8 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
                const char *p = prefix_path(prefix, prefixlen, *src);
                if (p)
                        *(dst++) = p;
+               else
+                       exit(128); /* error message already given */
                src++;
        }
        *dst = NULL;
@@ -323,6 +325,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
        const char *gitdirenv;
        int len, offset;
 
+       /*
+        * Let's assume that we are in a git repository.
+        * If it turns out later that we are somewhere else, the value will be
+        * updated accordingly.
+        */
+       if (nongit_ok)
+               *nongit_ok = 0;
+
        /*
         * If GIT_DIR is set explicitly, we're not going
         * to do any discovery, but we still do repository
@@ -448,8 +458,7 @@ int check_repository_format_version(const char *var, const char *value)
        } else if (strcmp(var, "core.worktree") == 0) {
                if (!value)
                        return config_error_nonbool(var);
-               if (git_work_tree_cfg)
-                       free(git_work_tree_cfg);
+               free(git_work_tree_cfg);
                git_work_tree_cfg = xstrdup(value);
                inside_work_tree = -1;
        }