git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] git-init does not respect existing separate-git-dir

From
Duy Nguyen <pclouds@gmail.com>
Date
Aug 29, 2013, 13:04 UTC
Message-ID
<20130829130450.GA9323@lanh>
In-Reply-To
<521F40E6.4040102@gmx.com>
On Thu, Aug 29, 2013 at 01:39:02PM +0100, Ximin Luo wrote:
Show 8 quoted lines
> It should not be necessary to re-specify --separate-git-dir when re-initialising a git repo.
> 
> $ git init --separate-git-dir ../repo
> Initialized empty Git repository in /home/infinity0/tmp/repo/
> 
> $ git init
> /home/infinity0/tmp/wtree/.git/refs: Not a directory
> 1
This patch seems to work. Lightly tested.
-- 8< --
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 78aa387..d0e5b2e 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -192,6 +192,15 @@ static int create_default_files(const char *template_path)
 		die(_("insane git directory %s"), git_dir);
 	memcpy(path, git_dir, len);
 
+	if (!lstat(path, &st1) && S_ISREG(st1.st_mode)) {
+		git_dir = read_gitfile(git_dir);
+		len = strlen(git_dir);
+		if (len > sizeof(path)-50)
+			die(_("insane git directory %s"), git_dir);
+		set_git_dir(git_dir);
+		memcpy(path, git_dir, len);
+	}
+
 	if (len && path[len-1] != '/')
 		path[len++] = '/';
-- 8< -- 

> One big motivation is so "git init" can be a good "fire-and-forget"
> invocation that should work anywhere. Currently, one has to do "git
> init --separate-git-dir $(git rev-parse --git-dir)" which is a lot
> less elegant.
--
Duy
Previous: Ximin LuoNext: Junio C Hamano
Message 2 of 5 in “[BUG] git-init does not respect existing separate-git-dir”
  1. Ximin LuoAug 29, 2013
  2. Duy NguyenAug 29, 2013
  3. Junio C HamanoAug 29, 2013
  4. Make setup_git_env() resolve .git file when $GIT_DIR is not specifiedNguyễn Thái Ngọc Duy, Aug 31, 2013
  5. Junio C HamanoSep 3, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.