On Thu, Aug 29, 2013 at 01:39:02PM +0100, Ximin Luo wrote: > 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html