{"thread":{"id":"22678","subject":"[WIP PATCH 01/26] rev-parse --git-dir: print relative gitdir correctly","startedAt":"2010-02-16T16:04:51Z","lastAt":"2010-02-16T16:05:17Z","messageCount":27,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":26},"messages":[{"id":"134762","messageId":"1266336317-607-1-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":null,"subject":"[WIP PATCH 00/26] Git setup cleanup series","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:51Z","receivedAt":"2010-02-16T16:04:51Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is the result of my \"Remove .git auto detection from setup_git_env()\"\npatch [1]. Basically I make git behave differently (and correctly) when\nGIT_HARDENED_SETUP=1 to smooth out the migration from the current messy setup\nto a less messy setup. Eventually GIT_HARDENED_SETUP should be enabled by\ndefault and the obsolete code removed, but we're far away from that.\n\nSummary of changes:\n\n - startup_info struct is added to help move up setup_git_directory_gently()\n   to run_builtin(), which reduces lots of headache.\n - GIT_HARDENED_SETUP=1 will make git die() whenever setup_git_env() is called\n   from anywhere but setup_git_dir*. It also creates lots of segfault because\n   get_git_dir() and friends now can return NULL.\n - gitattr, gitexcludes will not access repository if there is no repository\n - enter_repo() will use setup_git_dir* to do the setup\n - because non-builtin commands do not have startup_info, they will behave\n   just like before. I'll need to look at them.\n\nTests are lacking. But you can just try \"GIT_HARDENED_SETUP=1 make test\"\nafter 04/26, then again at the end of the series to see the difference.\nIt'd be great if people see new failing tests. I'm not sure I have caught\nthem all.\n\n[1] http://mid.gmane.org/1265370468-6147-1-git-send-email-pclouds@gmail.com\n\nNguyễn Thái Ngọc Duy (26):\n  rev-parse --git-dir: print relative gitdir correctly\n  setup_git_directory*: Explicitly set git dir\n  Save setup_git_dir* info globally for later use\n  Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors\n  enter_repo(): use setup_git_directory_gently internally\n  Tweak init/clone to work properly with GIT_HARDENED_SETUP=1\n  Support running setup_git_dir_gently() from the beginning for builtin commands\n  config: move up gitdir setup to run_builtin()\n  hash-object: move gitdir setup to run_builtin()\n  shortlog: move up gitdir setup to run_builtin()\n  Do not look for .git/info/exclude when gitdir is not set up\n  grep: move up gitdir setup to run_builtin()\n  USE_PAGER should not be used without RUN_SETUP*\n  Do not try to read $GIT_DIR/info/attributes if there is no repository\n  archive: move up gitdir setup to run_builtin()\n  mailinfo: move up gitdir setup to run_builtin()\n  check-ref-format: setup gitdir gently\n  verify-pack: set up gitdir gently\n  apply: move up gitdir setup to run_builtin()\n  bundle: move up gitdir setup to run_builtin()\n  diff: move up gitdir setup to run_builtin()\n  help: move up gitdir setup to run_builtin()\n  ls-remote: move up gitdir setup to run_builtin()\n  var: move up gitdir setup to run_builtin()\n  merge-file: move up gitdir setup to run_builtin()\n  Turn on GIT_HARDENED_SETUP for the whole test suite\n\n attr.c                  |    5 ++-\n builtin-apply.c         |   13 +++----\n builtin-archive.c       |    2 +-\n builtin-bundle.c        |    6 +--\n builtin-config.c        |   12 +++---\n builtin-diff.c          |    6 +--\n builtin-grep.c          |    9 ++---\n builtin-hash-object.c   |    9 +++--\n builtin-help.c          |    2 -\n builtin-init-db.c       |    4 ++\n builtin-ls-remote.c     |    3 --\n builtin-mailinfo.c      |    3 --\n builtin-merge-file.c    |    4 +--\n builtin-rev-parse.c     |    8 ++++\n builtin-shortlog.c      |    4 +--\n builtin-var.c           |    2 -\n cache.h                 |    8 ++++\n config.c                |   17 ++++++---\n dir.c                   |    8 +++--\n environment.c           |   43 +++++++++++++++++-----\n git.c                   |   88 +++++++++++++++++++++++++++++++----------------\n path.c                  |    8 ++---\n setup.c                 |   48 ++++++++++++++++++++------\n t/t0024-crlf-archive.sh |    1 +\n t/t1302-repo-version.sh |    2 +-\n t/test-lib.sh           |    3 ++\n 26 files changed, 204 insertions(+), 114 deletions(-)\n"},{"id":"134734","messageId":"1266336317-607-2-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 01/26] rev-parse --git-dir: print relative gitdir correctly","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:52Z","receivedAt":"2010-02-16T16:04:52Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"When git_dir is relative, it is relative to Git's current working\ndirectory, which is worktree top directory. \"git rev-parse --git-dir\"\nis expected to output relative to user's current working directory.\n\nCatch this case and make gitdir absolute (the easy way).\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n This one is probably not needed for now. In my later patches, set_git_dir()\n is used more, and this becomes necessary.\n\n builtin-rev-parse.c |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex a8c5043..a054256 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -638,6 +638,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tconst char *gitdir = getenv(GIT_DIR_ENVIRONMENT);\n \t\t\t\tstatic char cwd[PATH_MAX];\n \t\t\t\tif (gitdir) {\n+\t\t\t\t\tif (prefix && !is_absolute_path(gitdir)) {\n+\t\t\t\t\t\tint len;\n+\t\t\t\t\t\tif (!getcwd(cwd, PATH_MAX))\n+\t\t\t\t\t\t\tdie_errno(\"unable to get current working directory\");\n+\t\t\t\t\t\tlen = strlen(cwd);\n+\t\t\t\t\t\tprintf(\"%s%s%s\\n\", cwd, len && cwd[len-1] != '/' ? \"/\" : \"\", gitdir);\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\t}\n \t\t\t\t\tputs(gitdir);\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n-- \n1.7.0.195.g637a2\n"},{"id":"134749","messageId":"1266336317-607-3-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 02/26] setup_git_directory*: Explicitly set git dir","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:53Z","receivedAt":"2010-02-16T16:04:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"If setup_git_directory_gently() and its callers do not set gitdir\nnow, it will be eventually set by setup_git_env(), through obscure\ncall chain. One of the indirect call site is git_config().\n\nMy goal is to remove gitdir auto detection in setup_git_env(). So\nthe first step is not depend on that behavior.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n setup.c |   34 +++++++++++++++++++++++-----------\n 1 files changed, 23 insertions(+), 11 deletions(-)\n\ndiff --git a/setup.c b/setup.c\nindex b38cbee..183bcf6 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -313,8 +313,12 @@ const char *read_gitfile_gently(const char *path)\n /*\n  * We cannot decide in this function whether we are in the work tree or\n  * not, since the config can only be read _after_ this function was called.\n+ *\n+ * After this function is finished, set_git_dir() must be called if a\n+ * a repository is found. Repo format will be checked later by\n+ * setup_git_directory_gently()\n  */\n-const char *setup_git_directory_gently(int *nongit_ok)\n+static const char *setup_git_directory_gently_1(int *nongit_ok)\n {\n \tconst char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);\n \tconst char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);\n@@ -345,18 +349,17 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\tconst char *retval;\n \n \t\t\tif (!work_tree_env) {\n+\t\t\t\t/* core.worktree may override worktree */\n \t\t\t\tretval = set_work_tree(gitdirenv);\n-\t\t\t\t/* config may override worktree */\n-\t\t\t\tif (check_repository_format_gently(nongit_ok))\n-\t\t\t\t\treturn NULL;\n+\t\t\t\tset_git_dir(gitdirenv);\n \t\t\t\treturn retval;\n \t\t\t}\n-\t\t\tif (check_repository_format_gently(nongit_ok))\n-\t\t\t\treturn NULL;\n \t\t\tretval = get_relative_cwd(buffer, sizeof(buffer) - 1,\n \t\t\t\t\tget_git_work_tree());\n-\t\t\tif (!retval || !*retval)\n+\t\t\tif (!retval || !*retval) {\n+\t\t\t\tset_git_dir(gitdirenv);\n \t\t\t\treturn NULL;\n+\t\t\t}\n \t\t\tset_git_dir(make_absolute_path(gitdirenv));\n \t\t\tif (chdir(work_tree_env) < 0)\n \t\t\t\tdie_errno (\"Could not chdir to '%s'\", work_tree_env);\n@@ -396,8 +399,10 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\t\tdie(\"Repository setup failed\");\n \t\t\tbreak;\n \t\t}\n-\t\tif (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))\n+\t\tif (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) {\n+\t\t\tset_git_dir(DEFAULT_GIT_DIR_ENVIRONMENT);\n \t\t\tbreak;\n+\t\t}\n \t\tif (is_git_directory(\".\")) {\n \t\t\tinside_git_dir = 1;\n \t\t\tif (!work_tree_env)\n@@ -407,7 +412,6 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\t\tset_git_dir(cwd);\n \t\t\t} else\n \t\t\t\tset_git_dir(\".\");\n-\t\t\tcheck_repository_format_gently(nongit_ok);\n \t\t\treturn NULL;\n \t\t}\n \t\twhile (--offset > ceil_offset && cwd[offset] != '/');\n@@ -428,8 +432,6 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \tif (!work_tree_env)\n \t\tinside_work_tree = 1;\n \tgit_work_tree_cfg = xstrndup(cwd, offset);\n-\tif (check_repository_format_gently(nongit_ok))\n-\t\treturn NULL;\n \tif (offset == len)\n \t\treturn NULL;\n \n@@ -440,6 +442,16 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \treturn cwd + offset;\n }\n \n+const char *setup_git_directory_gently(int *nongit_ok)\n+{\n+\tconst char *prefix;\n+\n+\tprefix = setup_git_directory_gently_1(nongit_ok);\n+\tif (!nongit_ok || (!*nongit_ok && check_repository_format_gently(nongit_ok)))\n+\t\tprefix = NULL;\n+\treturn prefix;\n+}\n+\n int git_config_perm(const char *var, const char *value)\n {\n \tint i;\n-- \n1.7.0.195.g637a2\n"},{"id":"134735","messageId":"1266336317-607-4-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 03/26] Save setup_git_dir* info globally for later use","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:54Z","receivedAt":"2010-02-16T16:04:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"For one thing, this could help catching setup_git_dir being run twice,\nwhich is usually wrong.\n\nThis also helps moving up setup_git_dir* from inside builtin commands\nto handle_internal_command(). Without this, run_builtin()\nneeds to find another way to pass \"nongit_ok\" to builtin commands.\n\nThe main program has to intialize startup_info pointer properly. For\nbuiltin commands, git.c will take care of that. If startup_info is\nNULL, the prior behavior should apply.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Could have save the command name in startup_info too, so error\n messages are clearer..\n\n cache.h       |    8 ++++++++\n environment.c |    1 +\n git.c         |   31 +++++++++++++++++++++++--------\n setup.c       |   14 +++++++++++++-\n 4 files changed, 45 insertions(+), 9 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex d478eff..fcbed37 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1040,4 +1040,12 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix);\n char *alias_lookup(const char *alias);\n int split_cmdline(char *cmdline, const char ***argv);\n \n+/* git.c */\n+struct startup_info {\n+\tconst char *prefix;\n+\tint have_set_gitdir;\n+\tint have_repository;\n+};\n+extern struct startup_info *startup_info;\n+\n #endif /* CACHE_H */\ndiff --git a/environment.c b/environment.c\nindex 739ec27..1ab8815 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -52,6 +52,7 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;\n char *notes_ref_name;\n int grafts_replace_parents = 1;\n int core_apply_sparse_checkout;\n+struct startup_info *startup_info;\n \n /* Parallel index stat data preload? */\n int core_preload_index = 0;\ndiff --git a/git.c b/git.c\nindex b3e23f1..ea29cca 100644\n--- a/git.c\n+++ b/git.c\n@@ -13,6 +13,8 @@ const char git_usage_string[] =\n const char git_more_info_string[] =\n \t\"See 'git help COMMAND' for more information on a specific command.\";\n \n+static struct startup_info opts;\n+struct startup_info *startup_info;\n static int use_pager = -1;\n struct pager_config {\n \tconst char *cmd;\n@@ -206,9 +208,6 @@ static int handle_alias(int *argcp, const char ***argv)\n \t\tret = 1;\n \t}\n \n-\tif (subdir && chdir(subdir))\n-\t\tdie_errno(\"Cannot change to '%s'\", subdir);\n-\n \terrno = saved_errno;\n \n \treturn ret;\n@@ -234,13 +233,26 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n {\n \tint status, help;\n \tstruct stat st;\n-\tconst char *prefix;\n \n-\tprefix = NULL;\n \thelp = argc == 2 && !strcmp(argv[1], \"-h\");\n \tif (!help) {\n-\t\tif (p->option & RUN_SETUP)\n-\t\t\tprefix = setup_git_directory();\n+\t\t/* handle_alias() may have set up gitdir for alias lookup */\n+\t\tif (startup_info->have_set_gitdir) {\n+\t\t\tif (p->option & RUN_SETUP) {\n+\t\t\t\tif (!startup_info->have_repository)\n+\t\t\t\t\tdie(\"No repository found\");\n+\t\t\t}\n+\t\t\telse {\n+\t\t\t\t/* This is WRONG, but we can't get rid of it now */\n+\t\t\t\tstartup_info->have_set_gitdir = 0;\n+\t\t\t\tif (startup_info->prefix && chdir(startup_info->prefix))\n+\t\t\t\t\tdie(\"Cannot change to '%s'\", startup_info->prefix);\n+\t\t\t}\n+\t\t}\n+\t\telse {\n+\t\t\tif (p->option & RUN_SETUP)\n+\t\t\t\tsetup_git_directory();\n+\t\t}\n \n \t\tif (use_pager == -1 && p->option & RUN_SETUP)\n \t\t\tuse_pager = check_pager_config(p->cmd);\n@@ -254,7 +266,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \n \ttrace_argv_printf(argv, \"trace: built-in: git\");\n \n-\tstatus = p->fn(argc, argv, prefix);\n+\tstatus = p->fn(argc, argv, startup_info->prefix);\n \tif (status)\n \t\treturn status;\n \n@@ -473,6 +485,9 @@ int main(int argc, const char **argv)\n {\n \tconst char *cmd;\n \n+\tstartup_info = &opts;\n+\tmemset(startup_info, 0, sizeof(*startup_info));\n+\n \tcmd = git_extract_argv0_path(argv[0]);\n \tif (!cmd)\n \t\tcmd = \"git-help\";\ndiff --git a/setup.c b/setup.c\nindex 183bcf6..0c05d36 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -236,7 +236,13 @@ void setup_work_tree(void)\n \t\tgit_dir = make_absolute_path(git_dir);\n \tif (!work_tree || chdir(work_tree))\n \t\tdie(\"This operation must be run in a work tree\");\n+\n+\t/* we know gitdir is already set, we only adjust it to relative path */\n+\tif (startup_info)\n+\t\tstartup_info->have_set_gitdir = 0;\n \tset_git_dir(make_relative_path(git_dir, work_tree));\n+\tif (startup_info)\n+\t\tstartup_info->have_set_gitdir = 1;\n \tinitialized = 1;\n }\n \n@@ -447,8 +453,14 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \tconst char *prefix;\n \n \tprefix = setup_git_directory_gently_1(nongit_ok);\n-\tif (!nongit_ok || (!*nongit_ok && check_repository_format_gently(nongit_ok)))\n+\tif (startup_info)\n+\t\tstartup_info->have_set_gitdir = 1;\n+\tif ((!nongit_ok || !*nongit_ok) && check_repository_format_gently(nongit_ok))\n \t\tprefix = NULL;\n+\tif (startup_info) {\n+\t\tstartup_info->prefix = prefix;\n+\t\tstartup_info->have_repository = !nongit_ok || !*nongit_ok;\n+\t}\n \treturn prefix;\n }\n \n-- \n1.7.0.195.g637a2\n"},{"id":"134738","messageId":"1266336317-607-5-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 04/26] Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:55Z","receivedAt":"2010-02-16T16:04:55Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"When GIT_DIR environment variable is not specified, .git will be\nsearched if a repository is needed. Currently this can be done in two\nplaces: setup_git_directory_gently() and setup_git_env().\n\nThe one in setup_git_env() is no longer correct and should IMHO have\nbeen removed since the introduction of setup_git_directory_gently() in\nd288a70. Having two ways of auto detection may lead to obscure errors\nbecause .git may be misdetected by setup_git_env(),\nautomatically called via git_path(), which is all over the place.\n\nThis patch makes setup_git_env() die if GIT_DIR is not explictly\nset. That's setup_git_directory_gently()'s job. If you ever want to\ntouch things inside $GIT_DIR, you should have already called\nsetup_git_directory_gently().\n\nHowever, doing that will break Git the hard way. So the die()ing\nbehavior will be only triggered if environment variable\nGIT_HARDENED_SETUP is set. Otherwise old behavior remains. Once all\nGit commands have been adapted to stay away from the old behavior, the\nold code can be removed.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n config.c      |   17 ++++++++++++-----\n environment.c |   42 ++++++++++++++++++++++++++++++++----------\n setup.c       |    4 +++-\n 3 files changed, 47 insertions(+), 16 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 6963fbe..eee12b4 100644\n--- a/config.c\n+++ b/config.c\n@@ -704,6 +704,7 @@ int git_config(config_fn_t fn, void *data)\n \tint ret = 0, found = 0;\n \tchar *repo_config = NULL;\n \tconst char *home = NULL;\n+\tconst char *hardened_setup = getenv(\"GIT_HARDENED_SETUP\");\n \n \t/* Setting $GIT_CONFIG makes git read _only_ the given config file. */\n \tif (config_exclusive_filename)\n@@ -724,12 +725,18 @@ int git_config(config_fn_t fn, void *data)\n \t\tfree(user_config);\n \t}\n \n-\trepo_config = git_pathdup(\"config\");\n-\tif (!access(repo_config, R_OK)) {\n-\t\tret += git_config_from_file(fn, repo_config, data);\n-\t\tfound += 1;\n+\tif (hardened_setup && !*hardened_setup)\n+\t\thardened_setup = NULL;\n+\tif (hardened_setup && startup_info && !startup_info->have_set_gitdir)\n+\t\tdie(\"Try to access a repository before properly setting it up\");\n+\tif (!hardened_setup || !startup_info || startup_info->have_repository) {\n+\t\trepo_config = git_pathdup(\"config\");\n+\t\tif (!access(repo_config, R_OK)) {\n+\t\t\tret += git_config_from_file(fn, repo_config, data);\n+\t\t\tfound += 1;\n+\t\t}\n+\t\tfree(repo_config);\n \t}\n-\tfree(repo_config);\n \tif (found == 0)\n \t\treturn -1;\n \treturn ret;\ndiff --git a/environment.c b/environment.c\nindex 1ab8815..4795441 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -66,9 +66,19 @@ static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;\n \n static void setup_git_env(void)\n {\n+\tconst char *harden_setup = getenv(\"GIT_HARDENED_SETUP\");\n+\n+\tif (harden_setup && !*harden_setup)\n+\t\tharden_setup = NULL;\n+\n \tgit_dir = getenv(GIT_DIR_ENVIRONMENT);\n-\tif (!git_dir)\n-\t\tgit_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);\n+\tif (!git_dir) {\n+\t\tif (harden_setup)\n+\t\t\tdie(\"GIT_DIR not properly set\");\n+\t\t git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);\n+\t}\n+\tif (harden_setup && startup_info && startup_info->have_set_gitdir)\n+\t\t\tdie(\"internal error: setup_git_env can't be called twice\");\n \tif (!git_dir)\n \t\tgit_dir = DEFAULT_GIT_DIR_ENVIRONMENT;\n \tgit_object_dir = getenv(DB_ENVIRONMENT);\n@@ -103,8 +113,11 @@ int have_git_dir(void)\n \n const char *get_git_dir(void)\n {\n-\tif (!git_dir)\n-\t\tsetup_git_env();\n+\tif (!git_dir) {\n+\t\tconst char *harden_setup = getenv(\"GIT_HARDENED_SETUP\");\n+\t\tif (!harden_setup || !*harden_setup)\n+\t\t\tsetup_git_env();\n+\t}\n \treturn git_dir;\n }\n \n@@ -146,22 +159,31 @@ const char *get_git_work_tree(void)\n \n char *get_object_directory(void)\n {\n-\tif (!git_object_dir)\n-\t\tsetup_git_env();\n+\tif (!git_object_dir) {\n+\t\tconst char *harden_setup = getenv(\"GIT_HARDENED_SETUP\");\n+\t\tif (!harden_setup || !*harden_setup)\n+\t\t\tsetup_git_env();\n+\t}\n \treturn git_object_dir;\n }\n \n char *get_index_file(void)\n {\n-\tif (!git_index_file)\n-\t\tsetup_git_env();\n+\tif (!git_index_file) {\n+\t\tconst char *harden_setup = getenv(\"GIT_HARDENED_SETUP\");\n+\t\tif (!harden_setup || !*harden_setup)\n+\t\t\tsetup_git_env();\n+\t}\n \treturn git_index_file;\n }\n \n char *get_graft_file(void)\n {\n-\tif (!git_graft_file)\n-\t\tsetup_git_env();\n+\tif (!git_graft_file) {\n+\t\tconst char *harden_setup = getenv(\"GIT_HARDENED_SETUP\");\n+\t\tif (!harden_setup || !*harden_setup)\n+\t\t\tsetup_git_env();\n+\t}\n \treturn git_graft_file;\n }\n \ndiff --git a/setup.c b/setup.c\nindex 0c05d36..5c8777a 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -453,8 +453,10 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \tconst char *prefix;\n \n \tprefix = setup_git_directory_gently_1(nongit_ok);\n-\tif (startup_info)\n+\tif (startup_info) {\n \t\tstartup_info->have_set_gitdir = 1;\n+\t\tstartup_info->have_repository = get_git_dir() != NULL;\n+\t}\n \tif ((!nongit_ok || !*nongit_ok) && check_repository_format_gently(nongit_ok))\n \t\tprefix = NULL;\n \tif (startup_info) {\n-- \n1.7.0.195.g637a2\n"},{"id":"134737","messageId":"1266336317-607-6-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 05/26] enter_repo(): use setup_git_directory_gently internally","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:56Z","receivedAt":"2010-02-16T16:04:56Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n path.c |    8 +++-----\n 1 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/path.c b/path.c\nindex 0005df3..6a311d7 100644\n--- a/path.c\n+++ b/path.c\n@@ -281,6 +281,7 @@ char *enter_repo(char *path, int strict)\n {\n \tstatic char used_path[PATH_MAX];\n \tstatic char validated_path[PATH_MAX];\n+\tint nongit_ok;\n \n \tif (!path)\n \t\treturn NULL;\n@@ -334,12 +335,9 @@ char *enter_repo(char *path, int strict)\n \telse if (chdir(path))\n \t\treturn NULL;\n \n-\tif (access(\"objects\", X_OK) == 0 && access(\"refs\", X_OK) == 0 &&\n-\t    validate_headref(\"HEAD\") == 0) {\n-\t\tset_git_dir(\".\");\n-\t\tcheck_repository_format();\n+\tsetup_git_directory_gently(&nongit_ok);\n+\tif (!nongit_ok)\n \t\treturn path;\n-\t}\n \n \treturn NULL;\n }\n-- \n1.7.0.195.g637a2\n"},{"id":"134736","messageId":"1266336317-607-7-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 06/26] Tweak init/clone to work properly with GIT_HARDENED_SETUP=1","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:57Z","receivedAt":"2010-02-16T16:04:57Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-init-db.c             |    4 ++++\n t/t0000-basic.sh              |    2 ++\n t/t0001-init.sh               |    2 ++\n t/t0003-attributes.sh         |    2 ++\n t/t5600-clone-fail-cleanup.sh |    2 ++\n t/t5601-clone.sh              |    2 ++\n t/t5602-clone-remote-exec.sh  |    2 ++\n t/t5700-clone-reference.sh    |    2 ++\n t/t5701-clone-local.sh        |    2 ++\n t/t5702-clone-options.sh      |    2 ++\n t/t5704-bundle.sh             |    2 ++\n t/t5705-clone-2gb.sh          |    2 ++\n t/t5706-clone-branch.sh       |    2 ++\n 13 files changed, 28 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex dd84cae..22b2b07 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -195,6 +195,7 @@ static int create_default_files(const char *template_path)\n \t * from it after installing.\n \t */\n \tcopy_templates(template_path);\n+\tstartup_info->have_repository = 1;\n \n \tgit_config(git_default_config, NULL);\n \tis_bare_repository_cfg = init_is_bare_repository;\n@@ -286,6 +287,9 @@ int init_db(const char *template_dir, unsigned int flags)\n \tchar *path;\n \tint len, reinit;\n \n+\t/* init_db's caller mush have called set_git_dir() */\n+\tstartup_info->have_set_gitdir = 1;\n+\n \tsafe_create_dir(get_git_dir(), 0);\n \n \tinit_is_bare_repository = is_bare_repository();\ndiff --git a/t/t0000-basic.sh b/t/t0000-basic.sh\nindex f4ca4fc..0a4be17 100755\n--- a/t/t0000-basic.sh\n+++ b/t/t0000-basic.sh\n@@ -28,6 +28,8 @@ then\n \texit 1\n fi\n \n+export GIT_HARDENED_SETUP=1\n+\n . ./test-lib.sh\n \n ################################################################\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 5386504..0dd6ffa 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -4,6 +4,8 @@ test_description='git init'\n \n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n check_config () {\n \tif test -d \"$1\" && test -f \"$1/config\" && test -d \"$1/refs\"\n \tthen\ndiff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh\nindex 1c77192..2ebb345 100755\n--- a/t/t0003-attributes.sh\n+++ b/t/t0003-attributes.sh\n@@ -4,6 +4,8 @@ test_description=gitattributes\n \n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n attr_check () {\n \n \tpath=\"$1\"\ndiff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh\nindex ee06d28..424e6ad 100755\n--- a/t/t5600-clone-fail-cleanup.sh\n+++ b/t/t5600-clone-fail-cleanup.sh\n@@ -11,6 +11,8 @@ remove the directory before attempting a clone again.'\n \n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n test_expect_success \\\n     'clone of non-existent source should fail' \\\n     'test_must_fail git clone foo bar'\ndiff --git a/t/t5601-clone.sh b/t/t5601-clone.sh\nindex 2147567..a598f75 100755\n--- a/t/t5601-clone.sh\n+++ b/t/t5601-clone.sh\n@@ -4,6 +4,8 @@ test_description=clone\n \n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n test_expect_success setup '\n \n \trm -fr .git &&\ndiff --git a/t/t5602-clone-remote-exec.sh b/t/t5602-clone-remote-exec.sh\nindex deffdae..a94c528 100755\n--- a/t/t5602-clone-remote-exec.sh\n+++ b/t/t5602-clone-remote-exec.sh\n@@ -4,6 +4,8 @@ test_description=clone\n \n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n test_expect_success setup '\n \techo \"#!/bin/sh\" > not_ssh\n \techo \"echo \\\"\\$*\\\" > not_ssh_output\" >> not_ssh\ndiff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh\nindex 1c10916..2464f57 100755\n--- a/t/t5700-clone-reference.sh\n+++ b/t/t5700-clone-reference.sh\n@@ -6,6 +6,8 @@\n test_description='test clone --reference'\n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n base_dir=`pwd`\n \n U=$base_dir/UPLOAD_LOG\ndiff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh\nindex 8b4c356..3c3d6ed 100755\n--- a/t/t5701-clone-local.sh\n+++ b/t/t5701-clone-local.sh\n@@ -3,6 +3,8 @@\n test_description='test local clone'\n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n D=`pwd`\n \n test_expect_success 'preparing origin repository' '\ndiff --git a/t/t5702-clone-options.sh b/t/t5702-clone-options.sh\nindex 02cb024..63f59ba 100755\n--- a/t/t5702-clone-options.sh\n+++ b/t/t5702-clone-options.sh\n@@ -3,6 +3,8 @@\n test_description='basic clone options'\n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n test_expect_success 'setup' '\n \n \tmkdir parent &&\ndiff --git a/t/t5704-bundle.sh b/t/t5704-bundle.sh\nindex a8f4419..507c838 100755\n--- a/t/t5704-bundle.sh\n+++ b/t/t5704-bundle.sh\n@@ -3,6 +3,8 @@\n test_description='some bundle related tests'\n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n test_expect_success 'setup' '\n \n \t: > file &&\ndiff --git a/t/t5705-clone-2gb.sh b/t/t5705-clone-2gb.sh\nindex adfaae8..f63a557 100755\n--- a/t/t5705-clone-2gb.sh\n+++ b/t/t5705-clone-2gb.sh\n@@ -3,6 +3,8 @@\n test_description='Test cloning a repository larger than 2 gigabyte'\n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n test -z \"$GIT_TEST_CLONE_2GB\" &&\n say \"Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t\" &&\n test_done &&\ndiff --git a/t/t5706-clone-branch.sh b/t/t5706-clone-branch.sh\nindex f3f9a76..fbee0d0 100755\n--- a/t/t5706-clone-branch.sh\n+++ b/t/t5706-clone-branch.sh\n@@ -3,6 +3,8 @@\n test_description='clone --branch option'\n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n check_HEAD() {\n \techo refs/heads/\"$1\" >expect &&\n \tgit symbolic-ref HEAD >actual &&\n-- \n1.7.0.195.g637a2\n"},{"id":"134739","messageId":"1266336317-607-8-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 07/26] Support running setup_git_dir_gently() from the beginning for builtin commands","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:58Z","receivedAt":"2010-02-16T16:04:58Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Attempt to access gitdir is everywhere, even before cmd_*() is called.\nThe sooner we setup gitdir, the less trouble we may have to deal with.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n git.c |   16 +++++++++++++---\n 1 files changed, 13 insertions(+), 3 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex ea29cca..5391292 100644\n--- a/git.c\n+++ b/git.c\n@@ -215,13 +215,14 @@ static int handle_alias(int *argcp, const char ***argv)\n \n const char git_version_string[] = GIT_VERSION;\n \n-#define RUN_SETUP\t(1<<0)\n-#define USE_PAGER\t(1<<1)\n+#define RUN_SETUP\t\t(1<<0)\n+#define USE_PAGER\t\t(1<<1)\n /*\n  * require working tree to be present -- anything uses this needs\n  * RUN_SETUP for reading from the configuration file.\n  */\n-#define NEED_WORK_TREE\t(1<<2)\n+#define NEED_WORK_TREE\t\t(1<<2)\n+#define RUN_SETUP_GENTLY\t(1<<3)\n \n struct cmd_struct {\n \tconst char *cmd;\n@@ -236,12 +237,17 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \n \thelp = argc == 2 && !strcmp(argv[1], \"-h\");\n \tif (!help) {\n+\t\tif ((p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) == (RUN_SETUP | RUN_SETUP_GENTLY))\n+\t\t\tdie(\"Internal error: RUN_SETUP and RUN_SETUP_GENTLY are mutually exclusive\");\n+\n \t\t/* handle_alias() may have set up gitdir for alias lookup */\n \t\tif (startup_info->have_set_gitdir) {\n \t\t\tif (p->option & RUN_SETUP) {\n \t\t\t\tif (!startup_info->have_repository)\n \t\t\t\t\tdie(\"No repository found\");\n \t\t\t}\n+\t\t\tif (p->option & RUN_SETUP_GENTLY)\n+\t\t\t\t; /* all done */\n \t\t\telse {\n \t\t\t\t/* This is WRONG, but we can't get rid of it now */\n \t\t\t\tstartup_info->have_set_gitdir = 0;\n@@ -252,6 +258,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \t\telse {\n \t\t\tif (p->option & RUN_SETUP)\n \t\t\t\tsetup_git_directory();\n+\t\t\tif (p->option & RUN_SETUP_GENTLY) {\n+\t\t\t\tint nongit_ok;\n+\t\t\t\tsetup_git_directory_gently(&nongit_ok);\n+\t\t\t}\n \t\t}\n \n \t\tif (use_pager == -1 && p->option & RUN_SETUP)\n-- \n1.7.0.195.g637a2\n"},{"id":"134741","messageId":"1266336317-607-9-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 08/26] config: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:04:59Z","receivedAt":"2010-02-16T16:04:59Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-config.c        |   12 ++++++------\n git.c                   |    4 ++--\n t/t1302-repo-version.sh |    2 +-\n 3 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 4bc46b1..944ec9d 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -159,7 +159,8 @@ static int get_value(const char *key_, const char *regex_)\n \tlocal = config_exclusive_filename;\n \tif (!local) {\n \t\tconst char *home = getenv(\"HOME\");\n-\t\tlocal = repo_config = git_pathdup(\"config\");\n+\t\tif (startup_info->have_repository)\n+\t\t\tlocal = repo_config = git_pathdup(\"config\");\n \t\tif (git_config_global() && home)\n \t\t\tglobal = xstrdup(mkpath(\"%s/.gitconfig\", home));\n \t\tif (git_config_system())\n@@ -197,7 +198,8 @@ static int get_value(const char *key_, const char *regex_)\n \t\tgit_config_from_file(show_config, system_wide, NULL);\n \tif (do_all && global)\n \t\tgit_config_from_file(show_config, global, NULL);\n-\tgit_config_from_file(show_config, local, NULL);\n+\tif (local)\n+\t\tgit_config_from_file(show_config, local, NULL);\n \tif (!do_all && !seen && global)\n \t\tgit_config_from_file(show_config, global, NULL);\n \tif (!do_all && !seen && system_wide)\n@@ -326,11 +328,9 @@ static int get_colorbool(int print)\n \t\treturn get_colorbool_found ? 0 : 1;\n }\n \n-int cmd_config(int argc, const char **argv, const char *unused_prefix)\n+int cmd_config(int argc, const char **argv, const char *prefix)\n {\n-\tint nongit;\n \tchar *value;\n-\tconst char *prefix = setup_git_directory_gently(&nongit);\n \n \tconfig_exclusive_filename = getenv(CONFIG_ENVIRONMENT);\n \n@@ -409,7 +409,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)\n \t}\n \telse if (actions == ACTION_EDIT) {\n \t\tcheck_argc(argc, 0, 0);\n-\t\tif (!config_exclusive_filename && nongit)\n+\t\tif (!config_exclusive_filename && !startup_info->have_repository)\n \t\t\tdie(\"not in a git directory\");\n \t\tgit_config(git_default_config, NULL);\n \t\tlaunch_editor(config_exclusive_filename ?\ndiff --git a/git.c b/git.c\nindex 5391292..0022f02 100644\n--- a/git.c\n+++ b/git.c\n@@ -322,7 +322,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"clean\", cmd_clean, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"commit\", cmd_commit, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"commit-tree\", cmd_commit_tree, RUN_SETUP },\n-\t\t{ \"config\", cmd_config },\n+\t\t{ \"config\", cmd_config, RUN_SETUP_GENTLY },\n \t\t{ \"count-objects\", cmd_count_objects, RUN_SETUP },\n \t\t{ \"describe\", cmd_describe, RUN_SETUP },\n \t\t{ \"diff\", cmd_diff },\n@@ -378,7 +378,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"reflog\", cmd_reflog, RUN_SETUP },\n \t\t{ \"remote\", cmd_remote, RUN_SETUP },\n \t\t{ \"replace\", cmd_replace, RUN_SETUP },\n-\t\t{ \"repo-config\", cmd_config },\n+\t\t{ \"repo-config\", cmd_config, RUN_SETUP_GENTLY },\n \t\t{ \"rerere\", cmd_rerere, RUN_SETUP },\n \t\t{ \"reset\", cmd_reset, RUN_SETUP },\n \t\t{ \"rev-list\", cmd_rev_list, RUN_SETUP },\ndiff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh\nindex 8d305b4..74bf51f 100755\n--- a/t/t1302-repo-version.sh\n+++ b/t/t1302-repo-version.sh\n@@ -29,7 +29,7 @@ test_expect_success 'gitdir selection on normal repos' '\n # Make sure it would stop at test2, not trash\n test_expect_success 'gitdir selection on unsupported repo' '\n \t(cd test2 &&\n-\ttest \"$(git config core.repositoryformatversion)\" = 99)'\n+\ttest \"$(git config --file=.git/config core.repositoryformatversion)\" = 99)'\n \n test_expect_success 'gitdir not required mode' '\n \t(git apply --stat test.patch &&\n-- \n1.7.0.195.g637a2\n"},{"id":"134743","messageId":"1266336317-607-10-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 09/26] hash-object: move gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:00Z","receivedAt":"2010-02-16T16:05:00Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-hash-object.c |    9 +++++----\n git.c                 |    2 +-\n 2 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-hash-object.c b/builtin-hash-object.c\nindex 6a5f5b5..57330b8 100644\n--- a/builtin-hash-object.c\n+++ b/builtin-hash-object.c\n@@ -76,7 +76,7 @@ static const struct option hash_object_options[] = {\n int cmd_hash_object(int argc, const char **argv, const char *prefix)\n {\n \tint i;\n-\tint prefix_length = -1;\n+\tint prefix_length;\n \tconst char *errstr = NULL;\n \n \ttype = blob_type;\n@@ -84,9 +84,10 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, NULL, hash_object_options,\n \t\t\t     hash_object_usage, 0);\n \n+\tprefix_length = prefix ? strlen(prefix) : 0;\n \tif (write_object) {\n-\t\tprefix = setup_git_directory();\n-\t\tprefix_length = prefix ? strlen(prefix) : 0;\n+\t\tif (!startup_info->have_repository)\n+\t\t\tdie(\"No repository found\");\n \t\tif (vpath && prefix)\n \t\t\tvpath = prefix_filename(prefix, prefix_length, vpath);\n \t}\n@@ -121,7 +122,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)\n \tfor (i = 0 ; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n \n-\t\tif (0 <= prefix_length)\n+\t\tif (prefix_length)\n \t\t\targ = prefix_filename(prefix, prefix_length, arg);\n \t\thash_object(arg, type, write_object,\n \t\t\t    no_filters ? NULL : vpath ? vpath : arg);\ndiff --git a/git.c b/git.c\nindex 0022f02..a165b43 100644\n--- a/git.c\n+++ b/git.c\n@@ -340,7 +340,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"gc\", cmd_gc, RUN_SETUP },\n \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n \t\t{ \"grep\", cmd_grep, USE_PAGER },\n-\t\t{ \"hash-object\", cmd_hash_object },\n+\t\t{ \"hash-object\", cmd_hash_object, RUN_SETUP_GENTLY },\n \t\t{ \"help\", cmd_help },\n \t\t{ \"index-pack\", cmd_index_pack },\n \t\t{ \"init\", cmd_init_db },\n-- \n1.7.0.195.g637a2\n"},{"id":"134748","messageId":"1266336317-607-11-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 10/26] shortlog: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:01Z","receivedAt":"2010-02-16T16:05:01Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"shortlog has USE_PAGER set. setup_pager() may read config even\nsetup_git_dir* is not run yet. When the config path is required,\nsetup_git_env() plays hero and set gitdir to \".git\". Shortly after,\nsetup_git_dir* is run inside cmd_shortlog() and may move gitdir\nto somewhere else.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-shortlog.c  |    4 +---\n git.c               |    2 +-\n t/t4201-shortlog.sh |    2 ++\n 3 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-shortlog.c b/builtin-shortlog.c\nindex b3b055f..a62dfb0 100644\n--- a/builtin-shortlog.c\n+++ b/builtin-shortlog.c\n@@ -249,7 +249,6 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)\n {\n \tstatic struct shortlog log;\n \tstatic struct rev_info rev;\n-\tint nongit;\n \n \tstatic const struct option options[] = {\n \t\tOPT_BOOLEAN('n', \"numbered\", &log.sort_by_number,\n@@ -265,7 +264,6 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)\n \n \tstruct parse_opt_ctx_t ctx;\n \n-\tprefix = setup_git_directory_gently(&nongit);\n \tgit_config(git_default_config, NULL);\n \tshortlog_init(&log);\n \tinit_revisions(&rev, prefix);\n@@ -292,7 +290,7 @@ parse_done:\n \tlog.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;\n \n \t/* assume HEAD if from a tty */\n-\tif (!nongit && !rev.pending.nr && isatty(0))\n+\tif (startup_info->have_repository && !rev.pending.nr && isatty(0))\n \t\tadd_head_to_pending(&rev);\n \tif (rev.pending.nr == 0) {\n \t\tread_from_stdin(&log);\ndiff --git a/git.c b/git.c\nindex a165b43..c7af80e 100644\n--- a/git.c\n+++ b/git.c\n@@ -386,7 +386,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"revert\", cmd_revert, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"rm\", cmd_rm, RUN_SETUP },\n \t\t{ \"send-pack\", cmd_send_pack, RUN_SETUP },\n-\t\t{ \"shortlog\", cmd_shortlog, USE_PAGER },\n+\t\t{ \"shortlog\", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },\n \t\t{ \"show-branch\", cmd_show_branch, RUN_SETUP },\n \t\t{ \"show\", cmd_show, RUN_SETUP | USE_PAGER },\n \t\t{ \"status\", cmd_status, RUN_SETUP | NEED_WORK_TREE },\ndiff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh\nindex a01e55b..7ae327a 100755\n--- a/t/t4201-shortlog.sh\n+++ b/t/t4201-shortlog.sh\n@@ -8,6 +8,8 @@ test_description='git shortlog\n \n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n echo 1 > a1\n git add a1\n tree=$(git write-tree)\n-- \n1.7.0.195.g637a2\n"},{"id":"134740","messageId":"1266336317-607-12-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 11/26] Do not look for .git/info/exclude when gitdir is not set up","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:02Z","receivedAt":"2010-02-16T16:05:02Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n dir.c |    8 +++++---\n 1 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex 67c3af6..a8fcbce 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1024,9 +1024,11 @@ void setup_standard_excludes(struct dir_struct *dir)\n \tconst char *path;\n \n \tdir->exclude_per_dir = \".gitignore\";\n-\tpath = git_path(\"info/exclude\");\n-\tif (!access(path, R_OK))\n-\t\tadd_excludes_from_file(dir, path);\n+\tif (!startup_info || startup_info->have_repository) {\n+\t\tpath = git_path(\"info/exclude\");\n+\t\tif (!access(path, R_OK))\n+\t\t\tadd_excludes_from_file(dir, path);\n+\t}\n \tif (excludes_file && !access(excludes_file, R_OK))\n \t\tadd_excludes_from_file(dir, excludes_file);\n }\n-- \n1.7.0.195.g637a2\n"},{"id":"134747","messageId":"1266336317-607-13-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 12/26] grep: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:03Z","receivedAt":"2010-02-16T16:05:03Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"grep has USE_PAGER set. setup_pager() may read config even\nsetup_git_dir* is not run yet. When the config path is required,\nsetup_git_env() plays hero and set gitdir to \".git\". Shortly after,\nsetup_git_dir* is run inside cmd_shortlog() and may move gitdir\nto somewhere else.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-grep.c  |    9 +++------\n git.c           |    2 +-\n t/t7002-grep.sh |    2 ++\n 3 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 46ffc1d..84c05e0 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -758,7 +758,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \tconst char **paths = NULL;\n \tint i;\n \tint dummy;\n-\tint nongit = 0, use_index = 1;\n+\tint use_index = 1;\n \tstruct option options[] = {\n \t\tOPT_BOOLEAN(0, \"cached\", &cached,\n \t\t\t\"search in index instead of in the work tree\"),\n@@ -846,8 +846,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\tOPT_END()\n \t};\n \n-\tprefix = setup_git_directory_gently(&nongit);\n-\n \t/*\n \t * 'git grep -h', unlike 'git grep -h <pattern>', is a request\n \t * to show usage information and exit.\n@@ -885,9 +883,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t     PARSE_OPT_STOP_AT_NON_OPTION |\n \t\t\t     PARSE_OPT_NO_INTERNAL_HELP);\n \n-\tif (use_index && nongit)\n-\t\t/* die the same way as if we did it at the beginning */\n-\t\tsetup_git_directory();\n+\tif (use_index && !startup_info->have_repository)\n+\t\tdie(\"No git repository found\");\n \n \t/*\n \t * skip a -- separator; we know it cannot be\ndiff --git a/git.c b/git.c\nindex c7af80e..3462b49 100644\n--- a/git.c\n+++ b/git.c\n@@ -339,7 +339,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"fsck-objects\", cmd_fsck, RUN_SETUP },\n \t\t{ \"gc\", cmd_gc, RUN_SETUP },\n \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n-\t\t{ \"grep\", cmd_grep, USE_PAGER },\n+\t\t{ \"grep\", cmd_grep, RUN_SETUP_GENTLY | USE_PAGER },\n \t\t{ \"hash-object\", cmd_hash_object, RUN_SETUP_GENTLY },\n \t\t{ \"help\", cmd_help },\n \t\t{ \"index-pack\", cmd_index_pack },\ndiff --git a/t/t7002-grep.sh b/t/t7002-grep.sh\nindex ebae152..67afb42 100755\n--- a/t/t7002-grep.sh\n+++ b/t/t7002-grep.sh\n@@ -8,6 +8,8 @@ test_description='git grep various.\n \n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n cat >hello.c <<EOF\n #include <stdio.h>\n int main(int argc, const char **argv)\n-- \n1.7.0.195.g637a2\n"},{"id":"134742","messageId":"1266336317-607-14-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 13/26] USE_PAGER should not be used without RUN_SETUP*","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:04Z","receivedAt":"2010-02-16T16:05:04Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n git.c |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 3462b49..1d1ad1a 100644\n--- a/git.c\n+++ b/git.c\n@@ -266,8 +266,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \n \t\tif (use_pager == -1 && p->option & RUN_SETUP)\n \t\t\tuse_pager = check_pager_config(p->cmd);\n-\t\tif (use_pager == -1 && p->option & USE_PAGER)\n+\t\tif (use_pager == -1 && p->option & USE_PAGER) {\n+\t\t\tif ((p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) == 0)\n+\t\t\t\tdie(\"Internal error: USE_PAGER must be together with RUN_SETUP*\");\n \t\t\tuse_pager = 1;\n+\t\t}\n \t}\n \tcommit_pager_choice();\n \n-- \n1.7.0.195.g637a2\n"},{"id":"134750","messageId":"1266336317-607-15-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 14/26] Do not try to read $GIT_DIR/info/attributes if there is no repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:05Z","receivedAt":"2010-02-16T16:05:05Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n attr.c |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex f5346ed..f1362de 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -480,7 +480,10 @@ static void bootstrap_attr_stack(void)\n \t\t\tdebug_push(elem);\n \t\t}\n \n-\t\telem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);\n+\t\tif (!startup_info || startup_info->have_repository)\n+\t\t\telem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);\n+\t\telse\n+\t\t\telem = NULL;\n \t\tif (!elem)\n \t\t\telem = xcalloc(1, sizeof(*elem));\n \t\telem->origin = NULL;\n-- \n1.7.0.195.g637a2\n"},{"id":"134744","messageId":"1266336317-607-16-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 15/26] archive: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:06Z","receivedAt":"2010-02-16T16:05:06Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-archive.c       |    2 +-\n git.c                   |    4 ++--\n t/t0024-crlf-archive.sh |    3 +++\n t/t5000-tar-tree.sh     |    2 ++\n t/t5001-archive-attr.sh |    2 ++\n 5 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex 6a887f5..ef0bef8 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -125,5 +125,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)\n \n \tsetvbuf(stderr, NULL, _IOLBF, BUFSIZ);\n \n-\treturn write_archive(argc, argv, prefix, 1);\n+\treturn write_archive(argc, argv, prefix, 0);\n }\ndiff --git a/git.c b/git.c\nindex 1d1ad1a..24fc0fc 100644\n--- a/git.c\n+++ b/git.c\n@@ -308,7 +308,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"stage\", cmd_add, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"annotate\", cmd_annotate, RUN_SETUP },\n \t\t{ \"apply\", cmd_apply },\n-\t\t{ \"archive\", cmd_archive },\n+\t\t{ \"archive\", cmd_archive, RUN_SETUP_GENTLY },\n \t\t{ \"bisect--helper\", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"blame\", cmd_blame, RUN_SETUP },\n \t\t{ \"branch\", cmd_branch, RUN_SETUP },\n@@ -396,7 +396,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"stripspace\", cmd_stripspace },\n \t\t{ \"symbolic-ref\", cmd_symbolic_ref, RUN_SETUP },\n \t\t{ \"tag\", cmd_tag, RUN_SETUP },\n-\t\t{ \"tar-tree\", cmd_tar_tree },\n+\t\t{ \"tar-tree\", cmd_tar_tree, RUN_SETUP_GENTLY },\n \t\t{ \"unpack-file\", cmd_unpack_file, RUN_SETUP },\n \t\t{ \"unpack-objects\", cmd_unpack_objects, RUN_SETUP },\n \t\t{ \"update-index\", cmd_update_index, RUN_SETUP },\ndiff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh\nindex c7d0324..f96db4d 100755\n--- a/t/t0024-crlf-archive.sh\n+++ b/t/t0024-crlf-archive.sh\n@@ -3,6 +3,9 @@\n test_description='respect crlf in git archive'\n \n . ./test-lib.sh\n+\n+export GIT_HARDENED_SETUP=1\n+\n UNZIP=${UNZIP:-unzip}\n \n test_expect_success setup '\ndiff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh\nindex 27bfba5..4c69dd2 100755\n--- a/t/t5000-tar-tree.sh\n+++ b/t/t5000-tar-tree.sh\n@@ -29,6 +29,8 @@ UNZIP=${UNZIP:-unzip}\n \n SUBSTFORMAT=%H%n\n \n+export GIT_HARDENED_SETUP=1\n+\n test_expect_success \\\n     'populate workdir' \\\n     'mkdir a b c &&\ndiff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh\nindex 426b319..80e1e72 100755\n--- a/t/t5001-archive-attr.sh\n+++ b/t/t5001-archive-attr.sh\n@@ -4,6 +4,8 @@ test_description='git archive attribute tests'\n \n . ./test-lib.sh\n \n+export GIT_HARDENED_SETUP=1\n+\n SUBSTFORMAT=%H%n\n \n test_expect_exists() {\n-- \n1.7.0.195.g637a2\n"},{"id":"134751","messageId":"1266336317-607-17-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 16/26] mailinfo: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:07Z","receivedAt":"2010-02-16T16:05:07Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"mailinfo may use repo config, so setup gitdir first.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-mailinfo.c |    3 ---\n git.c              |    2 +-\n 2 files changed, 1 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\nindex a50ac22..af72151 100644\n--- a/builtin-mailinfo.c\n+++ b/builtin-mailinfo.c\n@@ -1027,9 +1027,6 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)\n {\n \tconst char *def_charset;\n \n-\t/* NEEDSWORK: might want to do the optional .git/ directory\n-\t * discovery\n-\t */\n \tgit_config(git_mailinfo_config, NULL);\n \n \tdef_charset = (git_commit_encoding ? git_commit_encoding : \"UTF-8\");\ndiff --git a/git.c b/git.c\nindex 24fc0fc..8386a3a 100644\n--- a/git.c\n+++ b/git.c\n@@ -352,7 +352,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"ls-files\", cmd_ls_files, RUN_SETUP },\n \t\t{ \"ls-tree\", cmd_ls_tree, RUN_SETUP },\n \t\t{ \"ls-remote\", cmd_ls_remote },\n-\t\t{ \"mailinfo\", cmd_mailinfo },\n+\t\t{ \"mailinfo\", cmd_mailinfo, RUN_SETUP_GENTLY },\n \t\t{ \"mailsplit\", cmd_mailsplit },\n \t\t{ \"merge\", cmd_merge, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"merge-base\", cmd_merge_base, RUN_SETUP },\n-- \n1.7.0.195.g637a2\n"},{"id":"134758","messageId":"1266336317-607-18-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 17/26] check-ref-format: setup gitdir gently","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:08Z","receivedAt":"2010-02-16T16:05:08Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n git.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 8386a3a..8892d5a 100644\n--- a/git.c\n+++ b/git.c\n@@ -317,7 +317,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"checkout\", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"checkout-index\", cmd_checkout_index,\n \t\t\tRUN_SETUP | NEED_WORK_TREE},\n-\t\t{ \"check-ref-format\", cmd_check_ref_format },\n+\t\t{ \"check-ref-format\", cmd_check_ref_format, RUN_SETUP_GENTLY },\n \t\t{ \"check-attr\", cmd_check_attr, RUN_SETUP },\n \t\t{ \"cherry\", cmd_cherry, RUN_SETUP },\n \t\t{ \"cherry-pick\", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },\n-- \n1.7.0.195.g637a2\n"},{"id":"134757","messageId":"1266336317-607-19-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 18/26] verify-pack: set up gitdir gently","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:09Z","receivedAt":"2010-02-16T16:05:09Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n git.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 8892d5a..ee596bb 100644\n--- a/git.c\n+++ b/git.c\n@@ -408,7 +408,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"version\", cmd_version },\n \t\t{ \"whatchanged\", cmd_whatchanged, RUN_SETUP | USE_PAGER },\n \t\t{ \"write-tree\", cmd_write_tree, RUN_SETUP },\n-\t\t{ \"verify-pack\", cmd_verify_pack },\n+\t\t{ \"verify-pack\", cmd_verify_pack, RUN_SETUP_GENTLY },\n \t\t{ \"show-ref\", cmd_show_ref, RUN_SETUP },\n \t\t{ \"pack-refs\", cmd_pack_refs, RUN_SETUP },\n \t};\n-- \n1.7.0.195.g637a2\n"},{"id":"134753","messageId":"1266336317-607-20-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 19/26] apply: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:10Z","receivedAt":"2010-02-16T16:05:10Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-apply.c |   13 ++++++-------\n git.c           |    2 +-\n 2 files changed, 7 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 2a1004d..44bb74f 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -26,7 +26,7 @@\n  *  --cached updates only the cache without ever touching the working tree.\n  */\n static const char *prefix;\n-static int prefix_length = -1;\n+static int prefix_length;\n static int newfd = -1;\n \n static int unidiff_zero;\n@@ -2441,7 +2441,7 @@ static int apply_binary(struct image *img, struct patch *patch)\n \t\treturn 0; /* deletion patch */\n \t}\n \n-\tif (has_sha1_file(sha1)) {\n+\tif (startup_info->have_repository && has_sha1_file(sha1)) {\n \t\t/* We already have the postimage */\n \t\tenum object_type type;\n \t\tunsigned long size;\n@@ -3512,11 +3512,10 @@ static int option_parse_directory(const struct option *opt,\n \treturn 0;\n }\n \n-int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n+int cmd_apply(int argc, const char **argv, const char *prefix_)\n {\n \tint i;\n \tint errs = 0;\n-\tint is_not_gitdir;\n \tint binary;\n \tint force_apply = 0;\n \n@@ -3589,7 +3588,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \t\tOPT_END()\n \t};\n \n-\tprefix = setup_git_directory_gently(&is_not_gitdir);\n+\tprefix = prefix_;\n \tprefix_length = prefix ? strlen(prefix) : 0;\n \tgit_config(git_apply_config, NULL);\n \tif (apply_default_whitespace)\n@@ -3604,10 +3603,10 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \t\tapply = apply_verbosely = 1;\n \tif (!force_apply && (diffstat || numstat || summary || check || fake_ancestor))\n \t\tapply = 0;\n-\tif (check_index && is_not_gitdir)\n+\tif (check_index && !startup_info->have_repository)\n \t\tdie(\"--index outside a repository\");\n \tif (cached) {\n-\t\tif (is_not_gitdir)\n+\t\tif (!startup_info->have_repository)\n \t\t\tdie(\"--cached outside a repository\");\n \t\tcheck_index = 1;\n \t}\ndiff --git a/git.c b/git.c\nindex ee596bb..96ccedd 100644\n--- a/git.c\n+++ b/git.c\n@@ -307,7 +307,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"add\", cmd_add, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"stage\", cmd_add, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"annotate\", cmd_annotate, RUN_SETUP },\n-\t\t{ \"apply\", cmd_apply },\n+\t\t{ \"apply\", cmd_apply, RUN_SETUP_GENTLY },\n \t\t{ \"archive\", cmd_archive, RUN_SETUP_GENTLY },\n \t\t{ \"bisect--helper\", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"blame\", cmd_blame, RUN_SETUP },\n-- \n1.7.0.195.g637a2\n"},{"id":"134756","messageId":"1266336317-607-21-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 20/26] bundle: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:11Z","receivedAt":"2010-02-16T16:05:11Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-bundle.c |    6 ++----\n git.c            |    2 +-\n 2 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-bundle.c b/builtin-bundle.c\nindex 2006cc5..80649ba 100644\n--- a/builtin-bundle.c\n+++ b/builtin-bundle.c\n@@ -18,7 +18,6 @@ static const char builtin_bundle_usage[] =\n int cmd_bundle(int argc, const char **argv, const char *prefix)\n {\n \tstruct bundle_header header;\n-\tint nongit;\n \tconst char *cmd, *bundle_file;\n \tint bundle_fd = -1;\n \tchar buffer[PATH_MAX];\n@@ -31,7 +30,6 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)\n \targc -= 2;\n \targv += 2;\n \n-\tprefix = setup_git_directory_gently(&nongit);\n \tif (prefix && bundle_file[0] != '/') {\n \t\tsnprintf(buffer, sizeof(buffer), \"%s/%s\", prefix, bundle_file);\n \t\tbundle_file = buffer;\n@@ -54,11 +52,11 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)\n \t\treturn !!list_bundle_refs(&header, argc, argv);\n \t}\n \tif (!strcmp(cmd, \"create\")) {\n-\t\tif (nongit)\n+\t\tif (!startup_info->have_repository)\n \t\t\tdie(\"Need a repository to create a bundle.\");\n \t\treturn !!create_bundle(&header, bundle_file, argc, argv);\n \t} else if (!strcmp(cmd, \"unbundle\")) {\n-\t\tif (nongit)\n+\t\tif (!startup_info->have_repository)\n \t\t\tdie(\"Need a repository to unbundle.\");\n \t\treturn !!unbundle(&header, bundle_fd) ||\n \t\t\tlist_bundle_refs(&header, argc, argv);\ndiff --git a/git.c b/git.c\nindex 96ccedd..9a85619 100644\n--- a/git.c\n+++ b/git.c\n@@ -312,7 +312,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"bisect--helper\", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"blame\", cmd_blame, RUN_SETUP },\n \t\t{ \"branch\", cmd_branch, RUN_SETUP },\n-\t\t{ \"bundle\", cmd_bundle },\n+\t\t{ \"bundle\", cmd_bundle, RUN_SETUP_GENTLY },\n \t\t{ \"cat-file\", cmd_cat_file, RUN_SETUP },\n \t\t{ \"checkout\", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"checkout-index\", cmd_checkout_index,\n-- \n1.7.0.195.g637a2\n"},{"id":"134754","messageId":"1266336317-607-22-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 21/26] diff: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:12Z","receivedAt":"2010-02-16T16:05:12Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-diff.c |    6 ++----\n git.c          |    2 +-\n 2 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-diff.c b/builtin-diff.c\nindex ffcdd05..e4bd855 100644\n--- a/builtin-diff.c\n+++ b/builtin-diff.c\n@@ -252,7 +252,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \tint ents = 0, blobs = 0, paths = 0;\n \tconst char *path = NULL;\n \tstruct blobinfo blob[2];\n-\tint nongit;\n \tint result = 0;\n \n \t/*\n@@ -278,7 +277,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \t * Other cases are errors.\n \t */\n \n-\tprefix = setup_git_directory_gently(&nongit);\n \tgit_config(git_diff_ui_config, NULL);\n \n \tif (diff_use_color_default == -1)\n@@ -287,7 +285,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \tinit_revisions(&rev, prefix);\n \n \t/* If this is a no-index diff, just run it and exit there. */\n-\tdiff_no_index(&rev, argc, argv, nongit, prefix);\n+\tdiff_no_index(&rev, argc, argv, !startup_info->have_repository, prefix);\n \n \t/* Otherwise, we are doing the usual \"git\" diff */\n \trev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;\n@@ -296,7 +294,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \tDIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);\n \tDIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);\n \n-\tif (nongit)\n+\tif (!startup_info->have_repository)\n \t\tdie(\"Not a git repository\");\n \targc = setup_revisions(argc, argv, &rev, NULL);\n \tif (!rev.diffopt.output_format) {\ndiff --git a/git.c b/git.c\nindex 9a85619..0a0588b 100644\n--- a/git.c\n+++ b/git.c\n@@ -328,7 +328,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"config\", cmd_config, RUN_SETUP_GENTLY },\n \t\t{ \"count-objects\", cmd_count_objects, RUN_SETUP },\n \t\t{ \"describe\", cmd_describe, RUN_SETUP },\n-\t\t{ \"diff\", cmd_diff },\n+\t\t{ \"diff\", cmd_diff, RUN_SETUP_GENTLY },\n \t\t{ \"diff-files\", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"diff-index\", cmd_diff_index, RUN_SETUP },\n \t\t{ \"diff-tree\", cmd_diff_tree, RUN_SETUP },\n-- \n1.7.0.195.g637a2\n"},{"id":"134746","messageId":"1266336317-607-23-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 22/26] help: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:13Z","receivedAt":"2010-02-16T16:05:13Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-help.c |    2 --\n git.c          |    2 +-\n 2 files changed, 1 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-help.c b/builtin-help.c\nindex 3182a2b..4988629 100644\n--- a/builtin-help.c\n+++ b/builtin-help.c\n@@ -414,7 +414,6 @@ static void show_html_page(const char *git_cmd)\n \n int cmd_help(int argc, const char **argv, const char *prefix)\n {\n-\tint nongit;\n \tconst char *alias;\n \tenum help_format parsed_help_format;\n \tload_command_list(\"git-\", &main_cmds, &other_cmds);\n@@ -437,7 +436,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t\treturn 0;\n \t}\n \n-\tsetup_git_directory_gently(&nongit);\n \tgit_config(git_help_config, NULL);\n \n \tif (parsed_help_format != HELP_FORMAT_NONE)\ndiff --git a/git.c b/git.c\nindex 0a0588b..c922400 100644\n--- a/git.c\n+++ b/git.c\n@@ -344,7 +344,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n \t\t{ \"grep\", cmd_grep, RUN_SETUP_GENTLY | USE_PAGER },\n \t\t{ \"hash-object\", cmd_hash_object, RUN_SETUP_GENTLY },\n-\t\t{ \"help\", cmd_help },\n+\t\t{ \"help\", cmd_help, RUN_SETUP_GENTLY },\n \t\t{ \"index-pack\", cmd_index_pack },\n \t\t{ \"init\", cmd_init_db },\n \t\t{ \"init-db\", cmd_init_db },\n-- \n1.7.0.195.g637a2\n"},{"id":"134752","messageId":"1266336317-607-24-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 23/26] ls-remote: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:14Z","receivedAt":"2010-02-16T16:05:14Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-ls-remote.c |    3 ---\n git.c               |    4 ++--\n 2 files changed, 2 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-ls-remote.c b/builtin-ls-remote.c\nindex 70f5622..998f2c8 100644\n--- a/builtin-ls-remote.c\n+++ b/builtin-ls-remote.c\n@@ -31,7 +31,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n {\n \tint i;\n \tconst char *dest = NULL;\n-\tint nongit;\n \tunsigned flags = 0;\n \tconst char *uploadpack = NULL;\n \tconst char **pattern = NULL;\n@@ -40,8 +39,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n \tstruct transport *transport;\n \tconst struct ref *ref;\n \n-\tsetup_git_directory_gently(&nongit);\n-\n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n \ndiff --git a/git.c b/git.c\nindex c922400..8d23f75 100644\n--- a/git.c\n+++ b/git.c\n@@ -351,7 +351,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"log\", cmd_log, RUN_SETUP | USE_PAGER },\n \t\t{ \"ls-files\", cmd_ls_files, RUN_SETUP },\n \t\t{ \"ls-tree\", cmd_ls_tree, RUN_SETUP },\n-\t\t{ \"ls-remote\", cmd_ls_remote },\n+\t\t{ \"ls-remote\", cmd_ls_remote, RUN_SETUP_GENTLY },\n \t\t{ \"mailinfo\", cmd_mailinfo, RUN_SETUP_GENTLY },\n \t\t{ \"mailsplit\", cmd_mailsplit },\n \t\t{ \"merge\", cmd_merge, RUN_SETUP | NEED_WORK_TREE },\n@@ -371,7 +371,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"pack-objects\", cmd_pack_objects, RUN_SETUP },\n \t\t{ \"pack-redundant\", cmd_pack_redundant, RUN_SETUP },\n \t\t{ \"patch-id\", cmd_patch_id },\n-\t\t{ \"peek-remote\", cmd_ls_remote },\n+\t\t{ \"peek-remote\", cmd_ls_remote, RUN_SETUP_GENTLY },\n \t\t{ \"pickaxe\", cmd_blame, RUN_SETUP },\n \t\t{ \"prune\", cmd_prune, RUN_SETUP },\n \t\t{ \"prune-packed\", cmd_prune_packed, RUN_SETUP },\n-- \n1.7.0.195.g637a2\n"},{"id":"134745","messageId":"1266336317-607-25-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 24/26] var: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:15Z","receivedAt":"2010-02-16T16:05:15Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-var.c |    2 --\n git.c         |    2 +-\n 2 files changed, 1 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-var.c b/builtin-var.c\nindex 2280518..f1e1fe3 100644\n--- a/builtin-var.c\n+++ b/builtin-var.c\n@@ -75,12 +75,10 @@ static int show_config(const char *var, const char *value, void *cb)\n int cmd_var(int argc, const char **argv, const char *prefix)\n {\n \tconst char *val;\n-\tint nongit;\n \tif (argc != 2) {\n \t\tusage(var_usage);\n \t}\n \n-\tsetup_git_directory_gently(&nongit);\n \tval = NULL;\n \n \tif (strcmp(argv[1], \"-l\") == 0) {\ndiff --git a/git.c b/git.c\nindex 8d23f75..7f715ba 100644\n--- a/git.c\n+++ b/git.c\n@@ -403,7 +403,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"update-ref\", cmd_update_ref, RUN_SETUP },\n \t\t{ \"update-server-info\", cmd_update_server_info, RUN_SETUP },\n \t\t{ \"upload-archive\", cmd_upload_archive },\n-\t\t{ \"var\", cmd_var },\n+\t\t{ \"var\", cmd_var, RUN_SETUP_GENTLY },\n \t\t{ \"verify-tag\", cmd_verify_tag, RUN_SETUP },\n \t\t{ \"version\", cmd_version },\n \t\t{ \"whatchanged\", cmd_whatchanged, RUN_SETUP | USE_PAGER },\n-- \n1.7.0.195.g637a2\n"},{"id":"134755","messageId":"1266336317-607-26-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 25/26] merge-file: move up gitdir setup to run_builtin()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:16Z","receivedAt":"2010-02-16T16:05:16Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-merge-file.c |    4 +---\n git.c                |    2 +-\n 2 files changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-merge-file.c b/builtin-merge-file.c\nindex 1e70073..474c6c2 100644\n--- a/builtin-merge-file.c\n+++ b/builtin-merge-file.c\n@@ -30,7 +30,6 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \tint level = XDL_MERGE_ZEALOUS_ALNUM;\n \tint style = 0, quiet = 0;\n \tint favor = 0;\n-\tint nongit;\n \n \tstruct option options[] = {\n \t\tOPT_BOOLEAN('p', \"stdout\", &to_stdout, \"send results to standard output\"),\n@@ -45,8 +44,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \t\tOPT_END(),\n \t};\n \n-\tprefix = setup_git_directory_gently(&nongit);\n-\tif (!nongit) {\n+\tif (startup_info->have_repository) {\n \t\t/* Read the configuration file */\n \t\tgit_config(git_xmerge_config, NULL);\n \t\tif (0 <= git_xmerge_style)\ndiff --git a/git.c b/git.c\nindex 7f715ba..3bbcca2 100644\n--- a/git.c\n+++ b/git.c\n@@ -356,7 +356,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"mailsplit\", cmd_mailsplit },\n \t\t{ \"merge\", cmd_merge, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"merge-base\", cmd_merge_base, RUN_SETUP },\n-\t\t{ \"merge-file\", cmd_merge_file },\n+\t\t{ \"merge-file\", cmd_merge_file, RUN_SETUP_GENTLY },\n \t\t{ \"merge-index\", cmd_merge_index, RUN_SETUP },\n \t\t{ \"merge-ours\", cmd_merge_ours, RUN_SETUP },\n \t\t{ \"merge-recursive\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n-- \n1.7.0.195.g637a2\n"},{"id":"134760","messageId":"1266336317-607-27-git-send-email-pclouds@gmail.com","threadId":"22678","inReplyTo":"1266336317-607-1-git-send-email-pclouds@gmail.com","subject":"[WIP PATCH 26/26] Turn on GIT_HARDENED_SETUP for the whole test suite","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-02-16T16:05:17Z","receivedAt":"2010-02-16T16:05:17Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n t/t0000-basic.sh              |    2 --\n t/t0001-init.sh               |    2 --\n t/t0003-attributes.sh         |    2 --\n t/t0024-crlf-archive.sh       |    2 --\n t/t4201-shortlog.sh           |    2 --\n t/t5000-tar-tree.sh           |    2 --\n t/t5001-archive-attr.sh       |    2 --\n t/t5600-clone-fail-cleanup.sh |    2 --\n t/t5601-clone.sh              |    2 --\n t/t5602-clone-remote-exec.sh  |    2 --\n t/t5700-clone-reference.sh    |    2 --\n t/t5701-clone-local.sh        |    2 --\n t/t5702-clone-options.sh      |    2 --\n t/t5704-bundle.sh             |    2 --\n t/t5705-clone-2gb.sh          |    2 --\n t/t5706-clone-branch.sh       |    2 --\n t/t7002-grep.sh               |    2 --\n t/test-lib.sh                 |    3 +++\n 18 files changed, 3 insertions(+), 34 deletions(-)\n\ndiff --git a/t/t0000-basic.sh b/t/t0000-basic.sh\nindex 0a4be17..f4ca4fc 100755\n--- a/t/t0000-basic.sh\n+++ b/t/t0000-basic.sh\n@@ -28,8 +28,6 @@ then\n \texit 1\n fi\n \n-export GIT_HARDENED_SETUP=1\n-\n . ./test-lib.sh\n \n ################################################################\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 0dd6ffa..5386504 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -4,8 +4,6 @@ test_description='git init'\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n check_config () {\n \tif test -d \"$1\" && test -f \"$1/config\" && test -d \"$1/refs\"\n \tthen\ndiff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh\nindex 2ebb345..1c77192 100755\n--- a/t/t0003-attributes.sh\n+++ b/t/t0003-attributes.sh\n@@ -4,8 +4,6 @@ test_description=gitattributes\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n attr_check () {\n \n \tpath=\"$1\"\ndiff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh\nindex f96db4d..ff345ea 100755\n--- a/t/t0024-crlf-archive.sh\n+++ b/t/t0024-crlf-archive.sh\n@@ -4,8 +4,6 @@ test_description='respect crlf in git archive'\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n UNZIP=${UNZIP:-unzip}\n \n test_expect_success setup '\ndiff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh\nindex 7ae327a..a01e55b 100755\n--- a/t/t4201-shortlog.sh\n+++ b/t/t4201-shortlog.sh\n@@ -8,8 +8,6 @@ test_description='git shortlog\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n echo 1 > a1\n git add a1\n tree=$(git write-tree)\ndiff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh\nindex 4c69dd2..27bfba5 100755\n--- a/t/t5000-tar-tree.sh\n+++ b/t/t5000-tar-tree.sh\n@@ -29,8 +29,6 @@ UNZIP=${UNZIP:-unzip}\n \n SUBSTFORMAT=%H%n\n \n-export GIT_HARDENED_SETUP=1\n-\n test_expect_success \\\n     'populate workdir' \\\n     'mkdir a b c &&\ndiff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh\nindex 80e1e72..426b319 100755\n--- a/t/t5001-archive-attr.sh\n+++ b/t/t5001-archive-attr.sh\n@@ -4,8 +4,6 @@ test_description='git archive attribute tests'\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n SUBSTFORMAT=%H%n\n \n test_expect_exists() {\ndiff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh\nindex 424e6ad..ee06d28 100755\n--- a/t/t5600-clone-fail-cleanup.sh\n+++ b/t/t5600-clone-fail-cleanup.sh\n@@ -11,8 +11,6 @@ remove the directory before attempting a clone again.'\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n test_expect_success \\\n     'clone of non-existent source should fail' \\\n     'test_must_fail git clone foo bar'\ndiff --git a/t/t5601-clone.sh b/t/t5601-clone.sh\nindex a598f75..2147567 100755\n--- a/t/t5601-clone.sh\n+++ b/t/t5601-clone.sh\n@@ -4,8 +4,6 @@ test_description=clone\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n test_expect_success setup '\n \n \trm -fr .git &&\ndiff --git a/t/t5602-clone-remote-exec.sh b/t/t5602-clone-remote-exec.sh\nindex a94c528..deffdae 100755\n--- a/t/t5602-clone-remote-exec.sh\n+++ b/t/t5602-clone-remote-exec.sh\n@@ -4,8 +4,6 @@ test_description=clone\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n test_expect_success setup '\n \techo \"#!/bin/sh\" > not_ssh\n \techo \"echo \\\"\\$*\\\" > not_ssh_output\" >> not_ssh\ndiff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh\nindex 2464f57..1c10916 100755\n--- a/t/t5700-clone-reference.sh\n+++ b/t/t5700-clone-reference.sh\n@@ -6,8 +6,6 @@\n test_description='test clone --reference'\n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n base_dir=`pwd`\n \n U=$base_dir/UPLOAD_LOG\ndiff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh\nindex 3c3d6ed..8b4c356 100755\n--- a/t/t5701-clone-local.sh\n+++ b/t/t5701-clone-local.sh\n@@ -3,8 +3,6 @@\n test_description='test local clone'\n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n D=`pwd`\n \n test_expect_success 'preparing origin repository' '\ndiff --git a/t/t5702-clone-options.sh b/t/t5702-clone-options.sh\nindex 63f59ba..02cb024 100755\n--- a/t/t5702-clone-options.sh\n+++ b/t/t5702-clone-options.sh\n@@ -3,8 +3,6 @@\n test_description='basic clone options'\n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n test_expect_success 'setup' '\n \n \tmkdir parent &&\ndiff --git a/t/t5704-bundle.sh b/t/t5704-bundle.sh\nindex 507c838..a8f4419 100755\n--- a/t/t5704-bundle.sh\n+++ b/t/t5704-bundle.sh\n@@ -3,8 +3,6 @@\n test_description='some bundle related tests'\n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n test_expect_success 'setup' '\n \n \t: > file &&\ndiff --git a/t/t5705-clone-2gb.sh b/t/t5705-clone-2gb.sh\nindex f63a557..adfaae8 100755\n--- a/t/t5705-clone-2gb.sh\n+++ b/t/t5705-clone-2gb.sh\n@@ -3,8 +3,6 @@\n test_description='Test cloning a repository larger than 2 gigabyte'\n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n test -z \"$GIT_TEST_CLONE_2GB\" &&\n say \"Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t\" &&\n test_done &&\ndiff --git a/t/t5706-clone-branch.sh b/t/t5706-clone-branch.sh\nindex fbee0d0..f3f9a76 100755\n--- a/t/t5706-clone-branch.sh\n+++ b/t/t5706-clone-branch.sh\n@@ -3,8 +3,6 @@\n test_description='clone --branch option'\n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n check_HEAD() {\n \techo refs/heads/\"$1\" >expect &&\n \tgit symbolic-ref HEAD >actual &&\ndiff --git a/t/t7002-grep.sh b/t/t7002-grep.sh\nindex 67afb42..ebae152 100755\n--- a/t/t7002-grep.sh\n+++ b/t/t7002-grep.sh\n@@ -8,8 +8,6 @@ test_description='git grep various.\n \n . ./test-lib.sh\n \n-export GIT_HARDENED_SETUP=1\n-\n cat >hello.c <<EOF\n #include <stdio.h>\n int main(int argc, const char **argv)\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex afd3053..e3e3084 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -61,6 +61,9 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n export EDITOR\n GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\n \n+GIT_HARDENED_SETUP=1\n+export GIT_HARDENED_SETUP\n+\n # Protect ourselves from common misconfiguration to export\n # CDPATH into the environment\n unset CDPATH\n-- \n1.7.0.195.g637a2\n"}]}