setup: allow for prefix to be passed to git commands
authorBrandon Williams <bmwill@google.com>
Fri, 17 Mar 2017 17:22:54 +0000 (10:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Mar 2017 18:54:50 +0000 (11:54 -0700)
In a future patch child processes which act on submodules need a little
more context about the original command that was invoked. This patch
teaches git to use the prefix stored in `GIT_INTERNAL_TOPLEVEL_PREFIX`
instead of the prefix that was potentally found during the git directory
setup process.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
git.c
setup.c
diff --git a/cache.h b/cache.h
index 61fc86e6d7199518555632a0b0b584471b9083a8..c7aa6f4bfe4518ee14249e2436238edd4443afcc 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -410,6 +410,7 @@ static inline enum object_type object_type(unsigned int mode)
 #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
 #define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
 #define GIT_SUPER_PREFIX_ENVIRONMENT "GIT_INTERNAL_SUPER_PREFIX"
+#define GIT_TOPLEVEL_PREFIX_ENVIRONMENT "GIT_INTERNAL_TOPLEVEL_PREFIX"
 #define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
 #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
 #define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
diff --git a/git.c b/git.c
index c887272b129968db161a152ce8a91aca4439ca3c..51bad4127412d5a7631afe0d03fbf6c9feeb9ba7 100644 (file)
--- a/git.c
+++ b/git.c
@@ -361,8 +361,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
        if (!help && get_super_prefix()) {
                if (!(p->option & SUPPORT_SUPER_PREFIX))
                        die("%s doesn't support --super-prefix", p->cmd);
-               if (prefix)
-                       die("can't use --super-prefix from a subdirectory");
        }
 
        if (!help && p->option & NEED_WORK_TREE)
diff --git a/setup.c b/setup.c
index 967f289f1ef07d78f4b680e1d880e2fa86215371..56cd68ba93c47a64529bb811e21ae7bbbdabb38c 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -939,9 +939,14 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
 
 const char *setup_git_directory_gently(int *nongit_ok)
 {
-       const char *prefix;
+       const char *prefix, *env_prefix;
 
        prefix = setup_git_directory_gently_1(nongit_ok);
+       env_prefix = getenv(GIT_TOPLEVEL_PREFIX_ENVIRONMENT);
+
+       if (env_prefix)
+               prefix = env_prefix;
+
        if (prefix)
                setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
        else