[PATCH] Fix initialization of a bare repository

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The recent work-tree cleanup broke it; core.bare was set to false
erroneously when calling "git --bare init".  Coincidentally, this
fixes "git clone --bare", too.

Noticed by Junio Hamano.

Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx>
---

	On Wed, 15 Aug 2007, Junio C Hamano wrote:

	> It appears that with 1.5.3-rc5
	> 
	> 	$ git clone --bare $origin_url target.git
	> 
	> does not set "core.bare = true" in target.git/config.  We used
	> to, at least with 1.5.2.2.  I am strongly suspecting that this
	> is another fallout from the worktree series.

	Sorry.  Yes, this is another fallout.

	Maybe this is not enough, though.  Maybe we need to check if the 
	GIT_DIR=. too, since 7efeb8f0 would set the work tree to ".", too.

	But maybe this would merit a separate fix in set_work_tree(), like

		if (!strcmp(getenv(GIT_DIR_ENVIRONMENT), ".")) {
			inside_work_tree = 0;
			return NULL;
		}

	Hmm?

 builtin-init-db.c |   13 ++++++++-----
 git.c             |    1 +
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/builtin-init-db.c b/builtin-init-db.c
index 75fb227..2e45a7e 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -302,11 +302,14 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 			usage(init_db_usage);
 	}
 
-	git_work_tree_cfg = xcalloc(PATH_MAX, 1);
-	if (!getcwd(git_work_tree_cfg, PATH_MAX))
-		die ("Cannot access current working directory.");
-	if (access(get_git_work_tree(), X_OK))
-		die ("Cannot access work tree '%s'", get_git_work_tree());
+	if (!is_bare_repository_cfg) {
+		git_work_tree_cfg = xcalloc(PATH_MAX, 1);
+		if (!getcwd(git_work_tree_cfg, PATH_MAX))
+			die ("Cannot access current working directory.");
+		if (access(get_git_work_tree(), X_OK))
+			die ("Cannot access work tree '%s'",
+					get_git_work_tree());
+	}
 
 	/*
 	 * Set up the default .git directory contents
diff --git a/git.c b/git.c
index 1bf2744..f0062a0 100644
--- a/git.c
+++ b/git.c
@@ -100,6 +100,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
 		} else if (!strcmp(cmd, "--bare")) {
 			static char git_dir[PATH_MAX+1];
 			setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 1);
+			is_bare_repository_cfg = 1;
 		} else if (!strcmp(cmd, "-2") ||
 				!strcmp(cmd, "--redirect-stderr")) {
 			if (dup2(1, 2) < 0)
-- 
1.5.1.rc1.4887.ga4a43-dirty

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux