All of lore.kernel.org
 help / color / mirror / Atom feed
* [WIP PATCH 00/26] Git setup cleanup series
@ 2010-02-16 16:04 Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 01/26] rev-parse --git-dir: print relative gitdir correctly Nguyễn Thái Ngọc Duy
                   ` (25 more replies)
  0 siblings, 26 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This is the result of my "Remove .git auto detection from setup_git_env()"
patch [1]. Basically I make git behave differently (and correctly) when
GIT_HARDENED_SETUP=1 to smooth out the migration from the current messy setup
to a less messy setup. Eventually GIT_HARDENED_SETUP should be enabled by
default and the obsolete code removed, but we're far away from that.

Summary of changes:

 - startup_info struct is added to help move up setup_git_directory_gently()
   to run_builtin(), which reduces lots of headache.
 - GIT_HARDENED_SETUP=1 will make git die() whenever setup_git_env() is called
   from anywhere but setup_git_dir*. It also creates lots of segfault because
   get_git_dir() and friends now can return NULL.
 - gitattr, gitexcludes will not access repository if there is no repository
 - enter_repo() will use setup_git_dir* to do the setup
 - because non-builtin commands do not have startup_info, they will behave
   just like before. I'll need to look at them.

Tests are lacking. But you can just try "GIT_HARDENED_SETUP=1 make test"
after 04/26, then again at the end of the series to see the difference.
It'd be great if people see new failing tests. I'm not sure I have caught
them all.

[1] http://mid.gmane.org/1265370468-6147-1-git-send-email-pclouds@gmail.com

Nguyễn Thái Ngọc Duy (26):
  rev-parse --git-dir: print relative gitdir correctly
  setup_git_directory*: Explicitly set git dir
  Save setup_git_dir* info globally for later use
  Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors
  enter_repo(): use setup_git_directory_gently internally
  Tweak init/clone to work properly with GIT_HARDENED_SETUP=1
  Support running setup_git_dir_gently() from the beginning for builtin commands
  config: move up gitdir setup to run_builtin()
  hash-object: move gitdir setup to run_builtin()
  shortlog: move up gitdir setup to run_builtin()
  Do not look for .git/info/exclude when gitdir is not set up
  grep: move up gitdir setup to run_builtin()
  USE_PAGER should not be used without RUN_SETUP*
  Do not try to read $GIT_DIR/info/attributes if there is no repository
  archive: move up gitdir setup to run_builtin()
  mailinfo: move up gitdir setup to run_builtin()
  check-ref-format: setup gitdir gently
  verify-pack: set up gitdir gently
  apply: move up gitdir setup to run_builtin()
  bundle: move up gitdir setup to run_builtin()
  diff: move up gitdir setup to run_builtin()
  help: move up gitdir setup to run_builtin()
  ls-remote: move up gitdir setup to run_builtin()
  var: move up gitdir setup to run_builtin()
  merge-file: move up gitdir setup to run_builtin()
  Turn on GIT_HARDENED_SETUP for the whole test suite

 attr.c                  |    5 ++-
 builtin-apply.c         |   13 +++----
 builtin-archive.c       |    2 +-
 builtin-bundle.c        |    6 +--
 builtin-config.c        |   12 +++---
 builtin-diff.c          |    6 +--
 builtin-grep.c          |    9 ++---
 builtin-hash-object.c   |    9 +++--
 builtin-help.c          |    2 -
 builtin-init-db.c       |    4 ++
 builtin-ls-remote.c     |    3 --
 builtin-mailinfo.c      |    3 --
 builtin-merge-file.c    |    4 +--
 builtin-rev-parse.c     |    8 ++++
 builtin-shortlog.c      |    4 +--
 builtin-var.c           |    2 -
 cache.h                 |    8 ++++
 config.c                |   17 ++++++---
 dir.c                   |    8 +++--
 environment.c           |   43 +++++++++++++++++-----
 git.c                   |   88 +++++++++++++++++++++++++++++++----------------
 path.c                  |    8 ++---
 setup.c                 |   48 ++++++++++++++++++++------
 t/t0024-crlf-archive.sh |    1 +
 t/t1302-repo-version.sh |    2 +-
 t/test-lib.sh           |    3 ++
 26 files changed, 204 insertions(+), 114 deletions(-)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [WIP PATCH 01/26] rev-parse --git-dir: print relative gitdir correctly
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:04 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 02/26] setup_git_directory*: Explicitly set git dir Nguyễn Thái Ngọc Duy
                   ` (24 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

When git_dir is relative, it is relative to Git's current working
directory, which is worktree top directory. "git rev-parse --git-dir"
is expected to output relative to user's current working directory.

Catch this case and make gitdir absolute (the easy way).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 This one is probably not needed for now. In my later patches, set_git_dir()
 is used more, and this becomes necessary.

 builtin-rev-parse.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index a8c5043..a054256 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -638,6 +638,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
 				static char cwd[PATH_MAX];
 				if (gitdir) {
+					if (prefix && !is_absolute_path(gitdir)) {
+						int len;
+						if (!getcwd(cwd, PATH_MAX))
+							die_errno("unable to get current working directory");
+						len = strlen(cwd);
+						printf("%s%s%s\n", cwd, len && cwd[len-1] != '/' ? "/" : "", gitdir);
+						continue;
+					}
 					puts(gitdir);
 					continue;
 				}
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 02/26] setup_git_directory*: Explicitly set git dir
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 01/26] rev-parse --git-dir: print relative gitdir correctly Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:04 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 03/26] Save setup_git_dir* info globally for later use Nguyễn Thái Ngọc Duy
                   ` (23 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

If setup_git_directory_gently() and its callers do not set gitdir
now, it will be eventually set by setup_git_env(), through obscure
call chain. One of the indirect call site is git_config().

My goal is to remove gitdir auto detection in setup_git_env(). So
the first step is not depend on that behavior.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 setup.c |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/setup.c b/setup.c
index b38cbee..183bcf6 100644
--- a/setup.c
+++ b/setup.c
@@ -313,8 +313,12 @@ const char *read_gitfile_gently(const char *path)
 /*
  * We cannot decide in this function whether we are in the work tree or
  * not, since the config can only be read _after_ this function was called.
+ *
+ * After this function is finished, set_git_dir() must be called if a
+ * a repository is found. Repo format will be checked later by
+ * setup_git_directory_gently()
  */
-const char *setup_git_directory_gently(int *nongit_ok)
+static const char *setup_git_directory_gently_1(int *nongit_ok)
 {
 	const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
 	const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
@@ -345,18 +349,17 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			const char *retval;
 
 			if (!work_tree_env) {
+				/* core.worktree may override worktree */
 				retval = set_work_tree(gitdirenv);
-				/* config may override worktree */
-				if (check_repository_format_gently(nongit_ok))
-					return NULL;
+				set_git_dir(gitdirenv);
 				return retval;
 			}
-			if (check_repository_format_gently(nongit_ok))
-				return NULL;
 			retval = get_relative_cwd(buffer, sizeof(buffer) - 1,
 					get_git_work_tree());
-			if (!retval || !*retval)
+			if (!retval || !*retval) {
+				set_git_dir(gitdirenv);
 				return NULL;
+			}
 			set_git_dir(make_absolute_path(gitdirenv));
 			if (chdir(work_tree_env) < 0)
 				die_errno ("Could not chdir to '%s'", work_tree_env);
@@ -396,8 +399,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
 				die("Repository setup failed");
 			break;
 		}
-		if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
+		if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) {
+			set_git_dir(DEFAULT_GIT_DIR_ENVIRONMENT);
 			break;
+		}
 		if (is_git_directory(".")) {
 			inside_git_dir = 1;
 			if (!work_tree_env)
@@ -407,7 +412,6 @@ const char *setup_git_directory_gently(int *nongit_ok)
 				set_git_dir(cwd);
 			} else
 				set_git_dir(".");
-			check_repository_format_gently(nongit_ok);
 			return NULL;
 		}
 		while (--offset > ceil_offset && cwd[offset] != '/');
@@ -428,8 +432,6 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	if (!work_tree_env)
 		inside_work_tree = 1;
 	git_work_tree_cfg = xstrndup(cwd, offset);
-	if (check_repository_format_gently(nongit_ok))
-		return NULL;
 	if (offset == len)
 		return NULL;
 
@@ -440,6 +442,16 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	return cwd + offset;
 }
 
+const char *setup_git_directory_gently(int *nongit_ok)
+{
+	const char *prefix;
+
+	prefix = setup_git_directory_gently_1(nongit_ok);
+	if (!nongit_ok || (!*nongit_ok && check_repository_format_gently(nongit_ok)))
+		prefix = NULL;
+	return prefix;
+}
+
 int git_config_perm(const char *var, const char *value)
 {
 	int i;
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 03/26] Save setup_git_dir* info globally for later use
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 01/26] rev-parse --git-dir: print relative gitdir correctly Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 02/26] setup_git_directory*: Explicitly set git dir Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:04 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 04/26] Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors Nguyễn Thái Ngọc Duy
                   ` (22 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

For one thing, this could help catching setup_git_dir being run twice,
which is usually wrong.

This also helps moving up setup_git_dir* from inside builtin commands
to handle_internal_command(). Without this, run_builtin()
needs to find another way to pass "nongit_ok" to builtin commands.

The main program has to intialize startup_info pointer properly. For
builtin commands, git.c will take care of that. If startup_info is
NULL, the prior behavior should apply.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Could have save the command name in startup_info too, so error
 messages are clearer..

 cache.h       |    8 ++++++++
 environment.c |    1 +
 git.c         |   31 +++++++++++++++++++++++--------
 setup.c       |   14 +++++++++++++-
 4 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/cache.h b/cache.h
index d478eff..fcbed37 100644
--- a/cache.h
+++ b/cache.h
@@ -1040,4 +1040,12 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix);
 char *alias_lookup(const char *alias);
 int split_cmdline(char *cmdline, const char ***argv);
 
+/* git.c */
+struct startup_info {
+	const char *prefix;
+	int have_set_gitdir;
+	int have_repository;
+};
+extern struct startup_info *startup_info;
+
 #endif /* CACHE_H */
diff --git a/environment.c b/environment.c
index 739ec27..1ab8815 100644
--- a/environment.c
+++ b/environment.c
@@ -52,6 +52,7 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
 char *notes_ref_name;
 int grafts_replace_parents = 1;
 int core_apply_sparse_checkout;
+struct startup_info *startup_info;
 
 /* Parallel index stat data preload? */
 int core_preload_index = 0;
diff --git a/git.c b/git.c
index b3e23f1..ea29cca 100644
--- a/git.c
+++ b/git.c
@@ -13,6 +13,8 @@ const char git_usage_string[] =
 const char git_more_info_string[] =
 	"See 'git help COMMAND' for more information on a specific command.";
 
+static struct startup_info opts;
+struct startup_info *startup_info;
 static int use_pager = -1;
 struct pager_config {
 	const char *cmd;
@@ -206,9 +208,6 @@ static int handle_alias(int *argcp, const char ***argv)
 		ret = 1;
 	}
 
-	if (subdir && chdir(subdir))
-		die_errno("Cannot change to '%s'", subdir);
-
 	errno = saved_errno;
 
 	return ret;
@@ -234,13 +233,26 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 {
 	int status, help;
 	struct stat st;
-	const char *prefix;
 
-	prefix = NULL;
 	help = argc == 2 && !strcmp(argv[1], "-h");
 	if (!help) {
-		if (p->option & RUN_SETUP)
-			prefix = setup_git_directory();
+		/* handle_alias() may have set up gitdir for alias lookup */
+		if (startup_info->have_set_gitdir) {
+			if (p->option & RUN_SETUP) {
+				if (!startup_info->have_repository)
+					die("No repository found");
+			}
+			else {
+				/* This is WRONG, but we can't get rid of it now */
+				startup_info->have_set_gitdir = 0;
+				if (startup_info->prefix && chdir(startup_info->prefix))
+					die("Cannot change to '%s'", startup_info->prefix);
+			}
+		}
+		else {
+			if (p->option & RUN_SETUP)
+				setup_git_directory();
+		}
 
 		if (use_pager == -1 && p->option & RUN_SETUP)
 			use_pager = check_pager_config(p->cmd);
@@ -254,7 +266,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 
 	trace_argv_printf(argv, "trace: built-in: git");
 
-	status = p->fn(argc, argv, prefix);
+	status = p->fn(argc, argv, startup_info->prefix);
 	if (status)
 		return status;
 
@@ -473,6 +485,9 @@ int main(int argc, const char **argv)
 {
 	const char *cmd;
 
+	startup_info = &opts;
+	memset(startup_info, 0, sizeof(*startup_info));
+
 	cmd = git_extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "git-help";
diff --git a/setup.c b/setup.c
index 183bcf6..0c05d36 100644
--- a/setup.c
+++ b/setup.c
@@ -236,7 +236,13 @@ void setup_work_tree(void)
 		git_dir = make_absolute_path(git_dir);
 	if (!work_tree || chdir(work_tree))
 		die("This operation must be run in a work tree");
+
+	/* we know gitdir is already set, we only adjust it to relative path */
+	if (startup_info)
+		startup_info->have_set_gitdir = 0;
 	set_git_dir(make_relative_path(git_dir, work_tree));
+	if (startup_info)
+		startup_info->have_set_gitdir = 1;
 	initialized = 1;
 }
 
@@ -447,8 +453,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	const char *prefix;
 
 	prefix = setup_git_directory_gently_1(nongit_ok);
-	if (!nongit_ok || (!*nongit_ok && check_repository_format_gently(nongit_ok)))
+	if (startup_info)
+		startup_info->have_set_gitdir = 1;
+	if ((!nongit_ok || !*nongit_ok) && check_repository_format_gently(nongit_ok))
 		prefix = NULL;
+	if (startup_info) {
+		startup_info->prefix = prefix;
+		startup_info->have_repository = !nongit_ok || !*nongit_ok;
+	}
 	return prefix;
 }
 
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 04/26] Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (2 preceding siblings ...)
  2010-02-16 16:04 ` [WIP PATCH 03/26] Save setup_git_dir* info globally for later use Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:04 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 05/26] enter_repo(): use setup_git_directory_gently internally Nguyễn Thái Ngọc Duy
                   ` (21 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

When GIT_DIR environment variable is not specified, .git will be
searched if a repository is needed. Currently this can be done in two
places: setup_git_directory_gently() and setup_git_env().

The one in setup_git_env() is no longer correct and should IMHO have
been removed since the introduction of setup_git_directory_gently() in
d288a70. Having two ways of auto detection may lead to obscure errors
because .git may be misdetected by setup_git_env(),
automatically called via git_path(), which is all over the place.

This patch makes setup_git_env() die if GIT_DIR is not explictly
set. That's setup_git_directory_gently()'s job. If you ever want to
touch things inside $GIT_DIR, you should have already called
setup_git_directory_gently().

However, doing that will break Git the hard way. So the die()ing
behavior will be only triggered if environment variable
GIT_HARDENED_SETUP is set. Otherwise old behavior remains. Once all
Git commands have been adapted to stay away from the old behavior, the
old code can be removed.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 config.c      |   17 ++++++++++++-----
 environment.c |   42 ++++++++++++++++++++++++++++++++----------
 setup.c       |    4 +++-
 3 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/config.c b/config.c
index 6963fbe..eee12b4 100644
--- a/config.c
+++ b/config.c
@@ -704,6 +704,7 @@ int git_config(config_fn_t fn, void *data)
 	int ret = 0, found = 0;
 	char *repo_config = NULL;
 	const char *home = NULL;
+	const char *hardened_setup = getenv("GIT_HARDENED_SETUP");
 
 	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
 	if (config_exclusive_filename)
@@ -724,12 +725,18 @@ int git_config(config_fn_t fn, void *data)
 		free(user_config);
 	}
 
-	repo_config = git_pathdup("config");
-	if (!access(repo_config, R_OK)) {
-		ret += git_config_from_file(fn, repo_config, data);
-		found += 1;
+	if (hardened_setup && !*hardened_setup)
+		hardened_setup = NULL;
+	if (hardened_setup && startup_info && !startup_info->have_set_gitdir)
+		die("Try to access a repository before properly setting it up");
+	if (!hardened_setup || !startup_info || startup_info->have_repository) {
+		repo_config = git_pathdup("config");
+		if (!access(repo_config, R_OK)) {
+			ret += git_config_from_file(fn, repo_config, data);
+			found += 1;
+		}
+		free(repo_config);
 	}
-	free(repo_config);
 	if (found == 0)
 		return -1;
 	return ret;
diff --git a/environment.c b/environment.c
index 1ab8815..4795441 100644
--- a/environment.c
+++ b/environment.c
@@ -66,9 +66,19 @@ static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
 
 static void setup_git_env(void)
 {
+	const char *harden_setup = getenv("GIT_HARDENED_SETUP");
+
+	if (harden_setup && !*harden_setup)
+		harden_setup = NULL;
+
 	git_dir = getenv(GIT_DIR_ENVIRONMENT);
-	if (!git_dir)
-		git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
+	if (!git_dir) {
+		if (harden_setup)
+			die("GIT_DIR not properly set");
+		 git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
+	}
+	if (harden_setup && startup_info && startup_info->have_set_gitdir)
+			die("internal error: setup_git_env can't be called twice");
 	if (!git_dir)
 		git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
 	git_object_dir = getenv(DB_ENVIRONMENT);
@@ -103,8 +113,11 @@ int have_git_dir(void)
 
 const char *get_git_dir(void)
 {
-	if (!git_dir)
-		setup_git_env();
+	if (!git_dir) {
+		const char *harden_setup = getenv("GIT_HARDENED_SETUP");
+		if (!harden_setup || !*harden_setup)
+			setup_git_env();
+	}
 	return git_dir;
 }
 
@@ -146,22 +159,31 @@ const char *get_git_work_tree(void)
 
 char *get_object_directory(void)
 {
-	if (!git_object_dir)
-		setup_git_env();
+	if (!git_object_dir) {
+		const char *harden_setup = getenv("GIT_HARDENED_SETUP");
+		if (!harden_setup || !*harden_setup)
+			setup_git_env();
+	}
 	return git_object_dir;
 }
 
 char *get_index_file(void)
 {
-	if (!git_index_file)
-		setup_git_env();
+	if (!git_index_file) {
+		const char *harden_setup = getenv("GIT_HARDENED_SETUP");
+		if (!harden_setup || !*harden_setup)
+			setup_git_env();
+	}
 	return git_index_file;
 }
 
 char *get_graft_file(void)
 {
-	if (!git_graft_file)
-		setup_git_env();
+	if (!git_graft_file) {
+		const char *harden_setup = getenv("GIT_HARDENED_SETUP");
+		if (!harden_setup || !*harden_setup)
+			setup_git_env();
+	}
 	return git_graft_file;
 }
 
diff --git a/setup.c b/setup.c
index 0c05d36..5c8777a 100644
--- a/setup.c
+++ b/setup.c
@@ -453,8 +453,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
 	const char *prefix;
 
 	prefix = setup_git_directory_gently_1(nongit_ok);
-	if (startup_info)
+	if (startup_info) {
 		startup_info->have_set_gitdir = 1;
+		startup_info->have_repository = get_git_dir() != NULL;
+	}
 	if ((!nongit_ok || !*nongit_ok) && check_repository_format_gently(nongit_ok))
 		prefix = NULL;
 	if (startup_info) {
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 05/26] enter_repo(): use setup_git_directory_gently internally
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (3 preceding siblings ...)
  2010-02-16 16:04 ` [WIP PATCH 04/26] Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:04 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 06/26] Tweak init/clone to work properly with GIT_HARDENED_SETUP=1 Nguyễn Thái Ngọc Duy
                   ` (20 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 path.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/path.c b/path.c
index 0005df3..6a311d7 100644
--- a/path.c
+++ b/path.c
@@ -281,6 +281,7 @@ char *enter_repo(char *path, int strict)
 {
 	static char used_path[PATH_MAX];
 	static char validated_path[PATH_MAX];
+	int nongit_ok;
 
 	if (!path)
 		return NULL;
@@ -334,12 +335,9 @@ char *enter_repo(char *path, int strict)
 	else if (chdir(path))
 		return NULL;
 
-	if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
-	    validate_headref("HEAD") == 0) {
-		set_git_dir(".");
-		check_repository_format();
+	setup_git_directory_gently(&nongit_ok);
+	if (!nongit_ok)
 		return path;
-	}
 
 	return NULL;
 }
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 06/26] Tweak init/clone to work properly with GIT_HARDENED_SETUP=1
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (4 preceding siblings ...)
  2010-02-16 16:04 ` [WIP PATCH 05/26] enter_repo(): use setup_git_directory_gently internally Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:04 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 07/26] Support running setup_git_dir_gently() from the beginning for builtin commands Nguyễn Thái Ngọc Duy
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-init-db.c             |    4 ++++
 t/t0000-basic.sh              |    2 ++
 t/t0001-init.sh               |    2 ++
 t/t0003-attributes.sh         |    2 ++
 t/t5600-clone-fail-cleanup.sh |    2 ++
 t/t5601-clone.sh              |    2 ++
 t/t5602-clone-remote-exec.sh  |    2 ++
 t/t5700-clone-reference.sh    |    2 ++
 t/t5701-clone-local.sh        |    2 ++
 t/t5702-clone-options.sh      |    2 ++
 t/t5704-bundle.sh             |    2 ++
 t/t5705-clone-2gb.sh          |    2 ++
 t/t5706-clone-branch.sh       |    2 ++
 13 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/builtin-init-db.c b/builtin-init-db.c
index dd84cae..22b2b07 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -195,6 +195,7 @@ static int create_default_files(const char *template_path)
 	 * from it after installing.
 	 */
 	copy_templates(template_path);
+	startup_info->have_repository = 1;
 
 	git_config(git_default_config, NULL);
 	is_bare_repository_cfg = init_is_bare_repository;
@@ -286,6 +287,9 @@ int init_db(const char *template_dir, unsigned int flags)
 	char *path;
 	int len, reinit;
 
+	/* init_db's caller mush have called set_git_dir() */
+	startup_info->have_set_gitdir = 1;
+
 	safe_create_dir(get_git_dir(), 0);
 
 	init_is_bare_repository = is_bare_repository();
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index f4ca4fc..0a4be17 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -28,6 +28,8 @@ then
 	exit 1
 fi
 
+export GIT_HARDENED_SETUP=1
+
 . ./test-lib.sh
 
 ################################################################
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 5386504..0dd6ffa 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -4,6 +4,8 @@ test_description='git init'
 
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 check_config () {
 	if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
 	then
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 1c77192..2ebb345 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -4,6 +4,8 @@ test_description=gitattributes
 
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 attr_check () {
 
 	path="$1"
diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh
index ee06d28..424e6ad 100755
--- a/t/t5600-clone-fail-cleanup.sh
+++ b/t/t5600-clone-fail-cleanup.sh
@@ -11,6 +11,8 @@ remove the directory before attempting a clone again.'
 
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 test_expect_success \
     'clone of non-existent source should fail' \
     'test_must_fail git clone foo bar'
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 2147567..a598f75 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -4,6 +4,8 @@ test_description=clone
 
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 test_expect_success setup '
 
 	rm -fr .git &&
diff --git a/t/t5602-clone-remote-exec.sh b/t/t5602-clone-remote-exec.sh
index deffdae..a94c528 100755
--- a/t/t5602-clone-remote-exec.sh
+++ b/t/t5602-clone-remote-exec.sh
@@ -4,6 +4,8 @@ test_description=clone
 
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 test_expect_success setup '
 	echo "#!/bin/sh" > not_ssh
 	echo "echo \"\$*\" > not_ssh_output" >> not_ssh
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 1c10916..2464f57 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -6,6 +6,8 @@
 test_description='test clone --reference'
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 base_dir=`pwd`
 
 U=$base_dir/UPLOAD_LOG
diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh
index 8b4c356..3c3d6ed 100755
--- a/t/t5701-clone-local.sh
+++ b/t/t5701-clone-local.sh
@@ -3,6 +3,8 @@
 test_description='test local clone'
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 D=`pwd`
 
 test_expect_success 'preparing origin repository' '
diff --git a/t/t5702-clone-options.sh b/t/t5702-clone-options.sh
index 02cb024..63f59ba 100755
--- a/t/t5702-clone-options.sh
+++ b/t/t5702-clone-options.sh
@@ -3,6 +3,8 @@
 test_description='basic clone options'
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 test_expect_success 'setup' '
 
 	mkdir parent &&
diff --git a/t/t5704-bundle.sh b/t/t5704-bundle.sh
index a8f4419..507c838 100755
--- a/t/t5704-bundle.sh
+++ b/t/t5704-bundle.sh
@@ -3,6 +3,8 @@
 test_description='some bundle related tests'
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 test_expect_success 'setup' '
 
 	: > file &&
diff --git a/t/t5705-clone-2gb.sh b/t/t5705-clone-2gb.sh
index adfaae8..f63a557 100755
--- a/t/t5705-clone-2gb.sh
+++ b/t/t5705-clone-2gb.sh
@@ -3,6 +3,8 @@
 test_description='Test cloning a repository larger than 2 gigabyte'
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 test -z "$GIT_TEST_CLONE_2GB" &&
 say "Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t" &&
 test_done &&
diff --git a/t/t5706-clone-branch.sh b/t/t5706-clone-branch.sh
index f3f9a76..fbee0d0 100755
--- a/t/t5706-clone-branch.sh
+++ b/t/t5706-clone-branch.sh
@@ -3,6 +3,8 @@
 test_description='clone --branch option'
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 check_HEAD() {
 	echo refs/heads/"$1" >expect &&
 	git symbolic-ref HEAD >actual &&
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 07/26] Support running setup_git_dir_gently() from the beginning for builtin commands
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (5 preceding siblings ...)
  2010-02-16 16:04 ` [WIP PATCH 06/26] Tweak init/clone to work properly with GIT_HARDENED_SETUP=1 Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:04 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:04 ` [WIP PATCH 08/26] config: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
                   ` (18 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Attempt to access gitdir is everywhere, even before cmd_*() is called.
The sooner we setup gitdir, the less trouble we may have to deal with.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 git.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/git.c b/git.c
index ea29cca..5391292 100644
--- a/git.c
+++ b/git.c
@@ -215,13 +215,14 @@ static int handle_alias(int *argcp, const char ***argv)
 
 const char git_version_string[] = GIT_VERSION;
 
-#define RUN_SETUP	(1<<0)
-#define USE_PAGER	(1<<1)
+#define RUN_SETUP		(1<<0)
+#define USE_PAGER		(1<<1)
 /*
  * require working tree to be present -- anything uses this needs
  * RUN_SETUP for reading from the configuration file.
  */
-#define NEED_WORK_TREE	(1<<2)
+#define NEED_WORK_TREE		(1<<2)
+#define RUN_SETUP_GENTLY	(1<<3)
 
 struct cmd_struct {
 	const char *cmd;
@@ -236,12 +237,17 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 
 	help = argc == 2 && !strcmp(argv[1], "-h");
 	if (!help) {
+		if ((p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) == (RUN_SETUP | RUN_SETUP_GENTLY))
+			die("Internal error: RUN_SETUP and RUN_SETUP_GENTLY are mutually exclusive");
+
 		/* handle_alias() may have set up gitdir for alias lookup */
 		if (startup_info->have_set_gitdir) {
 			if (p->option & RUN_SETUP) {
 				if (!startup_info->have_repository)
 					die("No repository found");
 			}
+			if (p->option & RUN_SETUP_GENTLY)
+				; /* all done */
 			else {
 				/* This is WRONG, but we can't get rid of it now */
 				startup_info->have_set_gitdir = 0;
@@ -252,6 +258,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 		else {
 			if (p->option & RUN_SETUP)
 				setup_git_directory();
+			if (p->option & RUN_SETUP_GENTLY) {
+				int nongit_ok;
+				setup_git_directory_gently(&nongit_ok);
+			}
 		}
 
 		if (use_pager == -1 && p->option & RUN_SETUP)
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 08/26] config: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (6 preceding siblings ...)
  2010-02-16 16:04 ` [WIP PATCH 07/26] Support running setup_git_dir_gently() from the beginning for builtin commands Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:04 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 09/26] hash-object: move " Nguyễn Thái Ngọc Duy
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-config.c        |   12 ++++++------
 git.c                   |    4 ++--
 t/t1302-repo-version.sh |    2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/builtin-config.c b/builtin-config.c
index 4bc46b1..944ec9d 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -159,7 +159,8 @@ static int get_value(const char *key_, const char *regex_)
 	local = config_exclusive_filename;
 	if (!local) {
 		const char *home = getenv("HOME");
-		local = repo_config = git_pathdup("config");
+		if (startup_info->have_repository)
+			local = repo_config = git_pathdup("config");
 		if (git_config_global() && home)
 			global = xstrdup(mkpath("%s/.gitconfig", home));
 		if (git_config_system())
@@ -197,7 +198,8 @@ static int get_value(const char *key_, const char *regex_)
 		git_config_from_file(show_config, system_wide, NULL);
 	if (do_all && global)
 		git_config_from_file(show_config, global, NULL);
-	git_config_from_file(show_config, local, NULL);
+	if (local)
+		git_config_from_file(show_config, local, NULL);
 	if (!do_all && !seen && global)
 		git_config_from_file(show_config, global, NULL);
 	if (!do_all && !seen && system_wide)
@@ -326,11 +328,9 @@ static int get_colorbool(int print)
 		return get_colorbool_found ? 0 : 1;
 }
 
-int cmd_config(int argc, const char **argv, const char *unused_prefix)
+int cmd_config(int argc, const char **argv, const char *prefix)
 {
-	int nongit;
 	char *value;
-	const char *prefix = setup_git_directory_gently(&nongit);
 
 	config_exclusive_filename = getenv(CONFIG_ENVIRONMENT);
 
@@ -409,7 +409,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
 	}
 	else if (actions == ACTION_EDIT) {
 		check_argc(argc, 0, 0);
-		if (!config_exclusive_filename && nongit)
+		if (!config_exclusive_filename && !startup_info->have_repository)
 			die("not in a git directory");
 		git_config(git_default_config, NULL);
 		launch_editor(config_exclusive_filename ?
diff --git a/git.c b/git.c
index 5391292..0022f02 100644
--- a/git.c
+++ b/git.c
@@ -322,7 +322,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE },
 		{ "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE },
 		{ "commit-tree", cmd_commit_tree, RUN_SETUP },
-		{ "config", cmd_config },
+		{ "config", cmd_config, RUN_SETUP_GENTLY },
 		{ "count-objects", cmd_count_objects, RUN_SETUP },
 		{ "describe", cmd_describe, RUN_SETUP },
 		{ "diff", cmd_diff },
@@ -378,7 +378,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "reflog", cmd_reflog, RUN_SETUP },
 		{ "remote", cmd_remote, RUN_SETUP },
 		{ "replace", cmd_replace, RUN_SETUP },
-		{ "repo-config", cmd_config },
+		{ "repo-config", cmd_config, RUN_SETUP_GENTLY },
 		{ "rerere", cmd_rerere, RUN_SETUP },
 		{ "reset", cmd_reset, RUN_SETUP },
 		{ "rev-list", cmd_rev_list, RUN_SETUP },
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index 8d305b4..74bf51f 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -29,7 +29,7 @@ test_expect_success 'gitdir selection on normal repos' '
 # Make sure it would stop at test2, not trash
 test_expect_success 'gitdir selection on unsupported repo' '
 	(cd test2 &&
-	test "$(git config core.repositoryformatversion)" = 99)'
+	test "$(git config --file=.git/config core.repositoryformatversion)" = 99)'
 
 test_expect_success 'gitdir not required mode' '
 	(git apply --stat test.patch &&
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 09/26] hash-object: move gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (7 preceding siblings ...)
  2010-02-16 16:04 ` [WIP PATCH 08/26] config: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 10/26] shortlog: move up " Nguyễn Thái Ngọc Duy
                   ` (16 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-hash-object.c |    9 +++++----
 git.c                 |    2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/builtin-hash-object.c b/builtin-hash-object.c
index 6a5f5b5..57330b8 100644
--- a/builtin-hash-object.c
+++ b/builtin-hash-object.c
@@ -76,7 +76,7 @@ static const struct option hash_object_options[] = {
 int cmd_hash_object(int argc, const char **argv, const char *prefix)
 {
 	int i;
-	int prefix_length = -1;
+	int prefix_length;
 	const char *errstr = NULL;
 
 	type = blob_type;
@@ -84,9 +84,10 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, NULL, hash_object_options,
 			     hash_object_usage, 0);
 
+	prefix_length = prefix ? strlen(prefix) : 0;
 	if (write_object) {
-		prefix = setup_git_directory();
-		prefix_length = prefix ? strlen(prefix) : 0;
+		if (!startup_info->have_repository)
+			die("No repository found");
 		if (vpath && prefix)
 			vpath = prefix_filename(prefix, prefix_length, vpath);
 	}
@@ -121,7 +122,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
 	for (i = 0 ; i < argc; i++) {
 		const char *arg = argv[i];
 
-		if (0 <= prefix_length)
+		if (prefix_length)
 			arg = prefix_filename(prefix, prefix_length, arg);
 		hash_object(arg, type, write_object,
 			    no_filters ? NULL : vpath ? vpath : arg);
diff --git a/git.c b/git.c
index 0022f02..a165b43 100644
--- a/git.c
+++ b/git.c
@@ -340,7 +340,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "gc", cmd_gc, RUN_SETUP },
 		{ "get-tar-commit-id", cmd_get_tar_commit_id },
 		{ "grep", cmd_grep, USE_PAGER },
-		{ "hash-object", cmd_hash_object },
+		{ "hash-object", cmd_hash_object, RUN_SETUP_GENTLY },
 		{ "help", cmd_help },
 		{ "index-pack", cmd_index_pack },
 		{ "init", cmd_init_db },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 10/26] shortlog: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (8 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 09/26] hash-object: move " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 11/26] Do not look for .git/info/exclude when gitdir is not set up Nguyễn Thái Ngọc Duy
                   ` (15 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

shortlog has USE_PAGER set. setup_pager() may read config even
setup_git_dir* is not run yet. When the config path is required,
setup_git_env() plays hero and set gitdir to ".git". Shortly after,
setup_git_dir* is run inside cmd_shortlog() and may move gitdir
to somewhere else.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-shortlog.c  |    4 +---
 git.c               |    2 +-
 t/t4201-shortlog.sh |    2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index b3b055f..a62dfb0 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -249,7 +249,6 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
 {
 	static struct shortlog log;
 	static struct rev_info rev;
-	int nongit;
 
 	static const struct option options[] = {
 		OPT_BOOLEAN('n', "numbered", &log.sort_by_number,
@@ -265,7 +264,6 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
 
 	struct parse_opt_ctx_t ctx;
 
-	prefix = setup_git_directory_gently(&nongit);
 	git_config(git_default_config, NULL);
 	shortlog_init(&log);
 	init_revisions(&rev, prefix);
@@ -292,7 +290,7 @@ parse_done:
 	log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;
 
 	/* assume HEAD if from a tty */
-	if (!nongit && !rev.pending.nr && isatty(0))
+	if (startup_info->have_repository && !rev.pending.nr && isatty(0))
 		add_head_to_pending(&rev);
 	if (rev.pending.nr == 0) {
 		read_from_stdin(&log);
diff --git a/git.c b/git.c
index a165b43..c7af80e 100644
--- a/git.c
+++ b/git.c
@@ -386,7 +386,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
 		{ "rm", cmd_rm, RUN_SETUP },
 		{ "send-pack", cmd_send_pack, RUN_SETUP },
-		{ "shortlog", cmd_shortlog, USE_PAGER },
+		{ "shortlog", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },
 		{ "show-branch", cmd_show_branch, RUN_SETUP },
 		{ "show", cmd_show, RUN_SETUP | USE_PAGER },
 		{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh
index a01e55b..7ae327a 100755
--- a/t/t4201-shortlog.sh
+++ b/t/t4201-shortlog.sh
@@ -8,6 +8,8 @@ test_description='git shortlog
 
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 echo 1 > a1
 git add a1
 tree=$(git write-tree)
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 11/26] Do not look for .git/info/exclude when gitdir is not set up
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (9 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 10/26] shortlog: move up " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 12/26] grep: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
                   ` (14 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/dir.c b/dir.c
index 67c3af6..a8fcbce 100644
--- a/dir.c
+++ b/dir.c
@@ -1024,9 +1024,11 @@ void setup_standard_excludes(struct dir_struct *dir)
 	const char *path;
 
 	dir->exclude_per_dir = ".gitignore";
-	path = git_path("info/exclude");
-	if (!access(path, R_OK))
-		add_excludes_from_file(dir, path);
+	if (!startup_info || startup_info->have_repository) {
+		path = git_path("info/exclude");
+		if (!access(path, R_OK))
+			add_excludes_from_file(dir, path);
+	}
 	if (excludes_file && !access(excludes_file, R_OK))
 		add_excludes_from_file(dir, excludes_file);
 }
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 12/26] grep: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (10 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 11/26] Do not look for .git/info/exclude when gitdir is not set up Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 13/26] USE_PAGER should not be used without RUN_SETUP* Nguyễn Thái Ngọc Duy
                   ` (13 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

grep has USE_PAGER set. setup_pager() may read config even
setup_git_dir* is not run yet. When the config path is required,
setup_git_env() plays hero and set gitdir to ".git". Shortly after,
setup_git_dir* is run inside cmd_shortlog() and may move gitdir
to somewhere else.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-grep.c  |    9 +++------
 git.c           |    2 +-
 t/t7002-grep.sh |    2 ++
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index 46ffc1d..84c05e0 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -758,7 +758,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	const char **paths = NULL;
 	int i;
 	int dummy;
-	int nongit = 0, use_index = 1;
+	int use_index = 1;
 	struct option options[] = {
 		OPT_BOOLEAN(0, "cached", &cached,
 			"search in index instead of in the work tree"),
@@ -846,8 +846,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
-	prefix = setup_git_directory_gently(&nongit);
-
 	/*
 	 * 'git grep -h', unlike 'git grep -h <pattern>', is a request
 	 * to show usage information and exit.
@@ -885,9 +883,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			     PARSE_OPT_STOP_AT_NON_OPTION |
 			     PARSE_OPT_NO_INTERNAL_HELP);
 
-	if (use_index && nongit)
-		/* die the same way as if we did it at the beginning */
-		setup_git_directory();
+	if (use_index && !startup_info->have_repository)
+		die("No git repository found");
 
 	/*
 	 * skip a -- separator; we know it cannot be
diff --git a/git.c b/git.c
index c7af80e..3462b49 100644
--- a/git.c
+++ b/git.c
@@ -339,7 +339,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "fsck-objects", cmd_fsck, RUN_SETUP },
 		{ "gc", cmd_gc, RUN_SETUP },
 		{ "get-tar-commit-id", cmd_get_tar_commit_id },
-		{ "grep", cmd_grep, USE_PAGER },
+		{ "grep", cmd_grep, RUN_SETUP_GENTLY | USE_PAGER },
 		{ "hash-object", cmd_hash_object, RUN_SETUP_GENTLY },
 		{ "help", cmd_help },
 		{ "index-pack", cmd_index_pack },
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index ebae152..67afb42 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -8,6 +8,8 @@ test_description='git grep various.
 
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 cat >hello.c <<EOF
 #include <stdio.h>
 int main(int argc, const char **argv)
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 13/26] USE_PAGER should not be used without RUN_SETUP*
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (11 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 12/26] grep: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 14/26] Do not try to read $GIT_DIR/info/attributes if there is no repository Nguyễn Thái Ngọc Duy
                   ` (12 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 git.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/git.c b/git.c
index 3462b49..1d1ad1a 100644
--- a/git.c
+++ b/git.c
@@ -266,8 +266,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 
 		if (use_pager == -1 && p->option & RUN_SETUP)
 			use_pager = check_pager_config(p->cmd);
-		if (use_pager == -1 && p->option & USE_PAGER)
+		if (use_pager == -1 && p->option & USE_PAGER) {
+			if ((p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) == 0)
+				die("Internal error: USE_PAGER must be together with RUN_SETUP*");
 			use_pager = 1;
+		}
 	}
 	commit_pager_choice();
 
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 14/26] Do not try to read $GIT_DIR/info/attributes if there is no repository
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (12 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 13/26] USE_PAGER should not be used without RUN_SETUP* Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 15/26] archive: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
                   ` (11 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 attr.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/attr.c b/attr.c
index f5346ed..f1362de 100644
--- a/attr.c
+++ b/attr.c
@@ -480,7 +480,10 @@ static void bootstrap_attr_stack(void)
 			debug_push(elem);
 		}
 
-		elem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);
+		if (!startup_info || startup_info->have_repository)
+			elem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);
+		else
+			elem = NULL;
 		if (!elem)
 			elem = xcalloc(1, sizeof(*elem));
 		elem->origin = NULL;
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 15/26] archive: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (13 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 14/26] Do not try to read $GIT_DIR/info/attributes if there is no repository Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 16/26] mailinfo: " Nguyễn Thái Ngọc Duy
                   ` (10 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-archive.c       |    2 +-
 git.c                   |    4 ++--
 t/t0024-crlf-archive.sh |    3 +++
 t/t5000-tar-tree.sh     |    2 ++
 t/t5001-archive-attr.sh |    2 ++
 5 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/builtin-archive.c b/builtin-archive.c
index 6a887f5..ef0bef8 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -125,5 +125,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 
 	setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
 
-	return write_archive(argc, argv, prefix, 1);
+	return write_archive(argc, argv, prefix, 0);
 }
diff --git a/git.c b/git.c
index 1d1ad1a..24fc0fc 100644
--- a/git.c
+++ b/git.c
@@ -308,7 +308,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE },
 		{ "annotate", cmd_annotate, RUN_SETUP },
 		{ "apply", cmd_apply },
-		{ "archive", cmd_archive },
+		{ "archive", cmd_archive, RUN_SETUP_GENTLY },
 		{ "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },
 		{ "blame", cmd_blame, RUN_SETUP },
 		{ "branch", cmd_branch, RUN_SETUP },
@@ -396,7 +396,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "stripspace", cmd_stripspace },
 		{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
 		{ "tag", cmd_tag, RUN_SETUP },
-		{ "tar-tree", cmd_tar_tree },
+		{ "tar-tree", cmd_tar_tree, RUN_SETUP_GENTLY },
 		{ "unpack-file", cmd_unpack_file, RUN_SETUP },
 		{ "unpack-objects", cmd_unpack_objects, RUN_SETUP },
 		{ "update-index", cmd_update_index, RUN_SETUP },
diff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh
index c7d0324..f96db4d 100755
--- a/t/t0024-crlf-archive.sh
+++ b/t/t0024-crlf-archive.sh
@@ -3,6 +3,9 @@
 test_description='respect crlf in git archive'
 
 . ./test-lib.sh
+
+export GIT_HARDENED_SETUP=1
+
 UNZIP=${UNZIP:-unzip}
 
 test_expect_success setup '
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index 27bfba5..4c69dd2 100755
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -29,6 +29,8 @@ UNZIP=${UNZIP:-unzip}
 
 SUBSTFORMAT=%H%n
 
+export GIT_HARDENED_SETUP=1
+
 test_expect_success \
     'populate workdir' \
     'mkdir a b c &&
diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh
index 426b319..80e1e72 100755
--- a/t/t5001-archive-attr.sh
+++ b/t/t5001-archive-attr.sh
@@ -4,6 +4,8 @@ test_description='git archive attribute tests'
 
 . ./test-lib.sh
 
+export GIT_HARDENED_SETUP=1
+
 SUBSTFORMAT=%H%n
 
 test_expect_exists() {
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 16/26] mailinfo: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (14 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 15/26] archive: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 17/26] check-ref-format: setup gitdir gently Nguyễn Thái Ngọc Duy
                   ` (9 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

mailinfo may use repo config, so setup gitdir first.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-mailinfo.c |    3 ---
 git.c              |    2 +-
 2 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index a50ac22..af72151 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -1027,9 +1027,6 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 {
 	const char *def_charset;
 
-	/* NEEDSWORK: might want to do the optional .git/ directory
-	 * discovery
-	 */
 	git_config(git_mailinfo_config, NULL);
 
 	def_charset = (git_commit_encoding ? git_commit_encoding : "UTF-8");
diff --git a/git.c b/git.c
index 24fc0fc..8386a3a 100644
--- a/git.c
+++ b/git.c
@@ -352,7 +352,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "ls-files", cmd_ls_files, RUN_SETUP },
 		{ "ls-tree", cmd_ls_tree, RUN_SETUP },
 		{ "ls-remote", cmd_ls_remote },
-		{ "mailinfo", cmd_mailinfo },
+		{ "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },
 		{ "mailsplit", cmd_mailsplit },
 		{ "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
 		{ "merge-base", cmd_merge_base, RUN_SETUP },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 17/26] check-ref-format: setup gitdir gently
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (15 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 16/26] mailinfo: " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 18/26] verify-pack: set up " Nguyễn Thái Ngọc Duy
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 git.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git.c b/git.c
index 8386a3a..8892d5a 100644
--- a/git.c
+++ b/git.c
@@ -317,7 +317,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
 		{ "checkout-index", cmd_checkout_index,
 			RUN_SETUP | NEED_WORK_TREE},
-		{ "check-ref-format", cmd_check_ref_format },
+		{ "check-ref-format", cmd_check_ref_format, RUN_SETUP_GENTLY },
 		{ "check-attr", cmd_check_attr, RUN_SETUP },
 		{ "cherry", cmd_cherry, RUN_SETUP },
 		{ "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 18/26] verify-pack: set up gitdir gently
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (16 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 17/26] check-ref-format: setup gitdir gently Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 19/26] apply: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 git.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git.c b/git.c
index 8892d5a..ee596bb 100644
--- a/git.c
+++ b/git.c
@@ -408,7 +408,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "version", cmd_version },
 		{ "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER },
 		{ "write-tree", cmd_write_tree, RUN_SETUP },
-		{ "verify-pack", cmd_verify_pack },
+		{ "verify-pack", cmd_verify_pack, RUN_SETUP_GENTLY },
 		{ "show-ref", cmd_show_ref, RUN_SETUP },
 		{ "pack-refs", cmd_pack_refs, RUN_SETUP },
 	};
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 19/26] apply: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (17 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 18/26] verify-pack: set up " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 20/26] bundle: " Nguyễn Thái Ngọc Duy
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-apply.c |   13 ++++++-------
 git.c           |    2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index 2a1004d..44bb74f 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -26,7 +26,7 @@
  *  --cached updates only the cache without ever touching the working tree.
  */
 static const char *prefix;
-static int prefix_length = -1;
+static int prefix_length;
 static int newfd = -1;
 
 static int unidiff_zero;
@@ -2441,7 +2441,7 @@ static int apply_binary(struct image *img, struct patch *patch)
 		return 0; /* deletion patch */
 	}
 
-	if (has_sha1_file(sha1)) {
+	if (startup_info->have_repository && has_sha1_file(sha1)) {
 		/* We already have the postimage */
 		enum object_type type;
 		unsigned long size;
@@ -3512,11 +3512,10 @@ static int option_parse_directory(const struct option *opt,
 	return 0;
 }
 
-int cmd_apply(int argc, const char **argv, const char *unused_prefix)
+int cmd_apply(int argc, const char **argv, const char *prefix_)
 {
 	int i;
 	int errs = 0;
-	int is_not_gitdir;
 	int binary;
 	int force_apply = 0;
 
@@ -3589,7 +3588,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
 		OPT_END()
 	};
 
-	prefix = setup_git_directory_gently(&is_not_gitdir);
+	prefix = prefix_;
 	prefix_length = prefix ? strlen(prefix) : 0;
 	git_config(git_apply_config, NULL);
 	if (apply_default_whitespace)
@@ -3604,10 +3603,10 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
 		apply = apply_verbosely = 1;
 	if (!force_apply && (diffstat || numstat || summary || check || fake_ancestor))
 		apply = 0;
-	if (check_index && is_not_gitdir)
+	if (check_index && !startup_info->have_repository)
 		die("--index outside a repository");
 	if (cached) {
-		if (is_not_gitdir)
+		if (!startup_info->have_repository)
 			die("--cached outside a repository");
 		check_index = 1;
 	}
diff --git a/git.c b/git.c
index ee596bb..96ccedd 100644
--- a/git.c
+++ b/git.c
@@ -307,7 +307,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
 		{ "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE },
 		{ "annotate", cmd_annotate, RUN_SETUP },
-		{ "apply", cmd_apply },
+		{ "apply", cmd_apply, RUN_SETUP_GENTLY },
 		{ "archive", cmd_archive, RUN_SETUP_GENTLY },
 		{ "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },
 		{ "blame", cmd_blame, RUN_SETUP },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 20/26] bundle: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (18 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 19/26] apply: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 21/26] diff: " Nguyễn Thái Ngọc Duy
                   ` (5 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-bundle.c |    6 ++----
 git.c            |    2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/builtin-bundle.c b/builtin-bundle.c
index 2006cc5..80649ba 100644
--- a/builtin-bundle.c
+++ b/builtin-bundle.c
@@ -18,7 +18,6 @@ static const char builtin_bundle_usage[] =
 int cmd_bundle(int argc, const char **argv, const char *prefix)
 {
 	struct bundle_header header;
-	int nongit;
 	const char *cmd, *bundle_file;
 	int bundle_fd = -1;
 	char buffer[PATH_MAX];
@@ -31,7 +30,6 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
 	argc -= 2;
 	argv += 2;
 
-	prefix = setup_git_directory_gently(&nongit);
 	if (prefix && bundle_file[0] != '/') {
 		snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file);
 		bundle_file = buffer;
@@ -54,11 +52,11 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
 		return !!list_bundle_refs(&header, argc, argv);
 	}
 	if (!strcmp(cmd, "create")) {
-		if (nongit)
+		if (!startup_info->have_repository)
 			die("Need a repository to create a bundle.");
 		return !!create_bundle(&header, bundle_file, argc, argv);
 	} else if (!strcmp(cmd, "unbundle")) {
-		if (nongit)
+		if (!startup_info->have_repository)
 			die("Need a repository to unbundle.");
 		return !!unbundle(&header, bundle_fd) ||
 			list_bundle_refs(&header, argc, argv);
diff --git a/git.c b/git.c
index 96ccedd..9a85619 100644
--- a/git.c
+++ b/git.c
@@ -312,7 +312,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },
 		{ "blame", cmd_blame, RUN_SETUP },
 		{ "branch", cmd_branch, RUN_SETUP },
-		{ "bundle", cmd_bundle },
+		{ "bundle", cmd_bundle, RUN_SETUP_GENTLY },
 		{ "cat-file", cmd_cat_file, RUN_SETUP },
 		{ "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
 		{ "checkout-index", cmd_checkout_index,
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 21/26] diff: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (19 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 20/26] bundle: " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 22/26] help: " Nguyễn Thái Ngọc Duy
                   ` (4 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-diff.c |    6 ++----
 git.c          |    2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/builtin-diff.c b/builtin-diff.c
index ffcdd05..e4bd855 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -252,7 +252,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	int ents = 0, blobs = 0, paths = 0;
 	const char *path = NULL;
 	struct blobinfo blob[2];
-	int nongit;
 	int result = 0;
 
 	/*
@@ -278,7 +277,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	 * Other cases are errors.
 	 */
 
-	prefix = setup_git_directory_gently(&nongit);
 	git_config(git_diff_ui_config, NULL);
 
 	if (diff_use_color_default == -1)
@@ -287,7 +285,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	init_revisions(&rev, prefix);
 
 	/* If this is a no-index diff, just run it and exit there. */
-	diff_no_index(&rev, argc, argv, nongit, prefix);
+	diff_no_index(&rev, argc, argv, !startup_info->have_repository, prefix);
 
 	/* Otherwise, we are doing the usual "git" diff */
 	rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
@@ -296,7 +294,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
 	DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
 
-	if (nongit)
+	if (!startup_info->have_repository)
 		die("Not a git repository");
 	argc = setup_revisions(argc, argv, &rev, NULL);
 	if (!rev.diffopt.output_format) {
diff --git a/git.c b/git.c
index 9a85619..0a0588b 100644
--- a/git.c
+++ b/git.c
@@ -328,7 +328,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "config", cmd_config, RUN_SETUP_GENTLY },
 		{ "count-objects", cmd_count_objects, RUN_SETUP },
 		{ "describe", cmd_describe, RUN_SETUP },
-		{ "diff", cmd_diff },
+		{ "diff", cmd_diff, RUN_SETUP_GENTLY },
 		{ "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE },
 		{ "diff-index", cmd_diff_index, RUN_SETUP },
 		{ "diff-tree", cmd_diff_tree, RUN_SETUP },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 22/26] help: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (20 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 21/26] diff: " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 23/26] ls-remote: " Nguyễn Thái Ngọc Duy
                   ` (3 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-help.c |    2 --
 git.c          |    2 +-
 2 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/builtin-help.c b/builtin-help.c
index 3182a2b..4988629 100644
--- a/builtin-help.c
+++ b/builtin-help.c
@@ -414,7 +414,6 @@ static void show_html_page(const char *git_cmd)
 
 int cmd_help(int argc, const char **argv, const char *prefix)
 {
-	int nongit;
 	const char *alias;
 	enum help_format parsed_help_format;
 	load_command_list("git-", &main_cmds, &other_cmds);
@@ -437,7 +436,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 		return 0;
 	}
 
-	setup_git_directory_gently(&nongit);
 	git_config(git_help_config, NULL);
 
 	if (parsed_help_format != HELP_FORMAT_NONE)
diff --git a/git.c b/git.c
index 0a0588b..c922400 100644
--- a/git.c
+++ b/git.c
@@ -344,7 +344,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "get-tar-commit-id", cmd_get_tar_commit_id },
 		{ "grep", cmd_grep, RUN_SETUP_GENTLY | USE_PAGER },
 		{ "hash-object", cmd_hash_object, RUN_SETUP_GENTLY },
-		{ "help", cmd_help },
+		{ "help", cmd_help, RUN_SETUP_GENTLY },
 		{ "index-pack", cmd_index_pack },
 		{ "init", cmd_init_db },
 		{ "init-db", cmd_init_db },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 23/26] ls-remote: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (21 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 22/26] help: " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 24/26] var: " Nguyễn Thái Ngọc Duy
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-ls-remote.c |    3 ---
 git.c               |    4 ++--
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/builtin-ls-remote.c b/builtin-ls-remote.c
index 70f5622..998f2c8 100644
--- a/builtin-ls-remote.c
+++ b/builtin-ls-remote.c
@@ -31,7 +31,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 {
 	int i;
 	const char *dest = NULL;
-	int nongit;
 	unsigned flags = 0;
 	const char *uploadpack = NULL;
 	const char **pattern = NULL;
@@ -40,8 +39,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 	struct transport *transport;
 	const struct ref *ref;
 
-	setup_git_directory_gently(&nongit);
-
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 
diff --git a/git.c b/git.c
index c922400..8d23f75 100644
--- a/git.c
+++ b/git.c
@@ -351,7 +351,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "log", cmd_log, RUN_SETUP | USE_PAGER },
 		{ "ls-files", cmd_ls_files, RUN_SETUP },
 		{ "ls-tree", cmd_ls_tree, RUN_SETUP },
-		{ "ls-remote", cmd_ls_remote },
+		{ "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
 		{ "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },
 		{ "mailsplit", cmd_mailsplit },
 		{ "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
@@ -371,7 +371,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "pack-objects", cmd_pack_objects, RUN_SETUP },
 		{ "pack-redundant", cmd_pack_redundant, RUN_SETUP },
 		{ "patch-id", cmd_patch_id },
-		{ "peek-remote", cmd_ls_remote },
+		{ "peek-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
 		{ "pickaxe", cmd_blame, RUN_SETUP },
 		{ "prune", cmd_prune, RUN_SETUP },
 		{ "prune-packed", cmd_prune_packed, RUN_SETUP },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 24/26] var: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (22 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 23/26] ls-remote: " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 25/26] merge-file: " Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 26/26] Turn on GIT_HARDENED_SETUP for the whole test suite Nguyễn Thái Ngọc Duy
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-var.c |    2 --
 git.c         |    2 +-
 2 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/builtin-var.c b/builtin-var.c
index 2280518..f1e1fe3 100644
--- a/builtin-var.c
+++ b/builtin-var.c
@@ -75,12 +75,10 @@ static int show_config(const char *var, const char *value, void *cb)
 int cmd_var(int argc, const char **argv, const char *prefix)
 {
 	const char *val;
-	int nongit;
 	if (argc != 2) {
 		usage(var_usage);
 	}
 
-	setup_git_directory_gently(&nongit);
 	val = NULL;
 
 	if (strcmp(argv[1], "-l") == 0) {
diff --git a/git.c b/git.c
index 8d23f75..7f715ba 100644
--- a/git.c
+++ b/git.c
@@ -403,7 +403,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "update-ref", cmd_update_ref, RUN_SETUP },
 		{ "update-server-info", cmd_update_server_info, RUN_SETUP },
 		{ "upload-archive", cmd_upload_archive },
-		{ "var", cmd_var },
+		{ "var", cmd_var, RUN_SETUP_GENTLY },
 		{ "verify-tag", cmd_verify_tag, RUN_SETUP },
 		{ "version", cmd_version },
 		{ "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 25/26] merge-file: move up gitdir setup to run_builtin()
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (23 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 24/26] var: " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  2010-02-16 16:05 ` [WIP PATCH 26/26] Turn on GIT_HARDENED_SETUP for the whole test suite Nguyễn Thái Ngọc Duy
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-merge-file.c |    4 +---
 git.c                |    2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/builtin-merge-file.c b/builtin-merge-file.c
index 1e70073..474c6c2 100644
--- a/builtin-merge-file.c
+++ b/builtin-merge-file.c
@@ -30,7 +30,6 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
 	int level = XDL_MERGE_ZEALOUS_ALNUM;
 	int style = 0, quiet = 0;
 	int favor = 0;
-	int nongit;
 
 	struct option options[] = {
 		OPT_BOOLEAN('p', "stdout", &to_stdout, "send results to standard output"),
@@ -45,8 +44,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
 		OPT_END(),
 	};
 
-	prefix = setup_git_directory_gently(&nongit);
-	if (!nongit) {
+	if (startup_info->have_repository) {
 		/* Read the configuration file */
 		git_config(git_xmerge_config, NULL);
 		if (0 <= git_xmerge_style)
diff --git a/git.c b/git.c
index 7f715ba..3bbcca2 100644
--- a/git.c
+++ b/git.c
@@ -356,7 +356,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "mailsplit", cmd_mailsplit },
 		{ "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
 		{ "merge-base", cmd_merge_base, RUN_SETUP },
-		{ "merge-file", cmd_merge_file },
+		{ "merge-file", cmd_merge_file, RUN_SETUP_GENTLY },
 		{ "merge-index", cmd_merge_index, RUN_SETUP },
 		{ "merge-ours", cmd_merge_ours, RUN_SETUP },
 		{ "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [WIP PATCH 26/26] Turn on GIT_HARDENED_SETUP for the whole test suite
  2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
                   ` (24 preceding siblings ...)
  2010-02-16 16:05 ` [WIP PATCH 25/26] merge-file: " Nguyễn Thái Ngọc Duy
@ 2010-02-16 16:05 ` Nguyễn Thái Ngọc Duy
  25 siblings, 0 replies; 27+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-02-16 16:05 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 t/t0000-basic.sh              |    2 --
 t/t0001-init.sh               |    2 --
 t/t0003-attributes.sh         |    2 --
 t/t0024-crlf-archive.sh       |    2 --
 t/t4201-shortlog.sh           |    2 --
 t/t5000-tar-tree.sh           |    2 --
 t/t5001-archive-attr.sh       |    2 --
 t/t5600-clone-fail-cleanup.sh |    2 --
 t/t5601-clone.sh              |    2 --
 t/t5602-clone-remote-exec.sh  |    2 --
 t/t5700-clone-reference.sh    |    2 --
 t/t5701-clone-local.sh        |    2 --
 t/t5702-clone-options.sh      |    2 --
 t/t5704-bundle.sh             |    2 --
 t/t5705-clone-2gb.sh          |    2 --
 t/t5706-clone-branch.sh       |    2 --
 t/t7002-grep.sh               |    2 --
 t/test-lib.sh                 |    3 +++
 18 files changed, 3 insertions(+), 34 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 0a4be17..f4ca4fc 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -28,8 +28,6 @@ then
 	exit 1
 fi
 
-export GIT_HARDENED_SETUP=1
-
 . ./test-lib.sh
 
 ################################################################
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 0dd6ffa..5386504 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -4,8 +4,6 @@ test_description='git init'
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 check_config () {
 	if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
 	then
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 2ebb345..1c77192 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -4,8 +4,6 @@ test_description=gitattributes
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 attr_check () {
 
 	path="$1"
diff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh
index f96db4d..ff345ea 100755
--- a/t/t0024-crlf-archive.sh
+++ b/t/t0024-crlf-archive.sh
@@ -4,8 +4,6 @@ test_description='respect crlf in git archive'
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 UNZIP=${UNZIP:-unzip}
 
 test_expect_success setup '
diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh
index 7ae327a..a01e55b 100755
--- a/t/t4201-shortlog.sh
+++ b/t/t4201-shortlog.sh
@@ -8,8 +8,6 @@ test_description='git shortlog
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 echo 1 > a1
 git add a1
 tree=$(git write-tree)
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index 4c69dd2..27bfba5 100755
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -29,8 +29,6 @@ UNZIP=${UNZIP:-unzip}
 
 SUBSTFORMAT=%H%n
 
-export GIT_HARDENED_SETUP=1
-
 test_expect_success \
     'populate workdir' \
     'mkdir a b c &&
diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh
index 80e1e72..426b319 100755
--- a/t/t5001-archive-attr.sh
+++ b/t/t5001-archive-attr.sh
@@ -4,8 +4,6 @@ test_description='git archive attribute tests'
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 SUBSTFORMAT=%H%n
 
 test_expect_exists() {
diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh
index 424e6ad..ee06d28 100755
--- a/t/t5600-clone-fail-cleanup.sh
+++ b/t/t5600-clone-fail-cleanup.sh
@@ -11,8 +11,6 @@ remove the directory before attempting a clone again.'
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 test_expect_success \
     'clone of non-existent source should fail' \
     'test_must_fail git clone foo bar'
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index a598f75..2147567 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -4,8 +4,6 @@ test_description=clone
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 test_expect_success setup '
 
 	rm -fr .git &&
diff --git a/t/t5602-clone-remote-exec.sh b/t/t5602-clone-remote-exec.sh
index a94c528..deffdae 100755
--- a/t/t5602-clone-remote-exec.sh
+++ b/t/t5602-clone-remote-exec.sh
@@ -4,8 +4,6 @@ test_description=clone
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 test_expect_success setup '
 	echo "#!/bin/sh" > not_ssh
 	echo "echo \"\$*\" > not_ssh_output" >> not_ssh
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 2464f57..1c10916 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -6,8 +6,6 @@
 test_description='test clone --reference'
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 base_dir=`pwd`
 
 U=$base_dir/UPLOAD_LOG
diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh
index 3c3d6ed..8b4c356 100755
--- a/t/t5701-clone-local.sh
+++ b/t/t5701-clone-local.sh
@@ -3,8 +3,6 @@
 test_description='test local clone'
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 D=`pwd`
 
 test_expect_success 'preparing origin repository' '
diff --git a/t/t5702-clone-options.sh b/t/t5702-clone-options.sh
index 63f59ba..02cb024 100755
--- a/t/t5702-clone-options.sh
+++ b/t/t5702-clone-options.sh
@@ -3,8 +3,6 @@
 test_description='basic clone options'
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 test_expect_success 'setup' '
 
 	mkdir parent &&
diff --git a/t/t5704-bundle.sh b/t/t5704-bundle.sh
index 507c838..a8f4419 100755
--- a/t/t5704-bundle.sh
+++ b/t/t5704-bundle.sh
@@ -3,8 +3,6 @@
 test_description='some bundle related tests'
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 test_expect_success 'setup' '
 
 	: > file &&
diff --git a/t/t5705-clone-2gb.sh b/t/t5705-clone-2gb.sh
index f63a557..adfaae8 100755
--- a/t/t5705-clone-2gb.sh
+++ b/t/t5705-clone-2gb.sh
@@ -3,8 +3,6 @@
 test_description='Test cloning a repository larger than 2 gigabyte'
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 test -z "$GIT_TEST_CLONE_2GB" &&
 say "Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t" &&
 test_done &&
diff --git a/t/t5706-clone-branch.sh b/t/t5706-clone-branch.sh
index fbee0d0..f3f9a76 100755
--- a/t/t5706-clone-branch.sh
+++ b/t/t5706-clone-branch.sh
@@ -3,8 +3,6 @@
 test_description='clone --branch option'
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 check_HEAD() {
 	echo refs/heads/"$1" >expect &&
 	git symbolic-ref HEAD >actual &&
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index 67afb42..ebae152 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -8,8 +8,6 @@ test_description='git grep various.
 
 . ./test-lib.sh
 
-export GIT_HARDENED_SETUP=1
-
 cat >hello.c <<EOF
 #include <stdio.h>
 int main(int argc, const char **argv)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index afd3053..e3e3084 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -61,6 +61,9 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
 export EDITOR
 GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
 
+GIT_HARDENED_SETUP=1
+export GIT_HARDENED_SETUP
+
 # Protect ourselves from common misconfiguration to export
 # CDPATH into the environment
 unset CDPATH
-- 
1.7.0.195.g637a2

^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2010-02-16 16:38 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-16 16:04 [WIP PATCH 00/26] Git setup cleanup series Nguyễn Thái Ngọc Duy
2010-02-16 16:04 ` [WIP PATCH 01/26] rev-parse --git-dir: print relative gitdir correctly Nguyễn Thái Ngọc Duy
2010-02-16 16:04 ` [WIP PATCH 02/26] setup_git_directory*: Explicitly set git dir Nguyễn Thái Ngọc Duy
2010-02-16 16:04 ` [WIP PATCH 03/26] Save setup_git_dir* info globally for later use Nguyễn Thái Ngọc Duy
2010-02-16 16:04 ` [WIP PATCH 04/26] Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors Nguyễn Thái Ngọc Duy
2010-02-16 16:04 ` [WIP PATCH 05/26] enter_repo(): use setup_git_directory_gently internally Nguyễn Thái Ngọc Duy
2010-02-16 16:04 ` [WIP PATCH 06/26] Tweak init/clone to work properly with GIT_HARDENED_SETUP=1 Nguyễn Thái Ngọc Duy
2010-02-16 16:04 ` [WIP PATCH 07/26] Support running setup_git_dir_gently() from the beginning for builtin commands Nguyễn Thái Ngọc Duy
2010-02-16 16:04 ` [WIP PATCH 08/26] config: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 09/26] hash-object: move " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 10/26] shortlog: move up " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 11/26] Do not look for .git/info/exclude when gitdir is not set up Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 12/26] grep: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 13/26] USE_PAGER should not be used without RUN_SETUP* Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 14/26] Do not try to read $GIT_DIR/info/attributes if there is no repository Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 15/26] archive: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 16/26] mailinfo: " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 17/26] check-ref-format: setup gitdir gently Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 18/26] verify-pack: set up " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 19/26] apply: move up gitdir setup to run_builtin() Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 20/26] bundle: " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 21/26] diff: " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 22/26] help: " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 23/26] ls-remote: " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 24/26] var: " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 25/26] merge-file: " Nguyễn Thái Ngọc Duy
2010-02-16 16:05 ` [WIP PATCH 26/26] Turn on GIT_HARDENED_SETUP for the whole test suite Nguyễn Thái Ngọc Duy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.