From: Duy Nguyen <pclouds@gmail.com>
To: Ximin Luo <infinity0@gmx.com>
Cc: git@vger.kernel.org
Subject: Re: [BUG] git-init does not respect existing separate-git-dir
Date: Thu, 29 Aug 2013 20:04:50 +0700 [thread overview]
Message-ID: <20130829130450.GA9323@lanh> (raw)
In-Reply-To: <521F40E6.4040102@gmx.com>
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
next prev parent reply other threads:[~2013-08-29 13:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-29 12:39 [BUG] git-init does not respect existing separate-git-dir Ximin Luo
2013-08-29 13:04 ` Duy Nguyen [this message]
2013-08-29 17:12 ` Junio C Hamano
2013-08-31 1:04 ` [PATCH] Make setup_git_env() resolve .git file when $GIT_DIR is not specified Nguyễn Thái Ngọc Duy
2013-09-03 18:14 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130829130450.GA9323@lanh \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=infinity0@gmx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).