aboutsummaryrefslogtreecommitdiff
path: root/builtin/init-db.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-05-05 21:00:26 -0700
committerJunio C Hamano <gitster@pobox.com>2015-05-05 21:00:27 -0700
commit7502b230ced2de7398a292f3da79467065398044 (patch)
tree1dd93d5f73085bf2bb10a4a40cc99d115c084fb4 /builtin/init-db.c
parentb02a94d6631bd2169d11d3dc7d2ebc21e2dfca30 (diff)
parent84ccad8dec1b8675699d70412def098d61456c55 (diff)
downloadgit-7502b230ced2de7398a292f3da79467065398044.tar.gz
git-7502b230ced2de7398a292f3da79467065398044.tar.xz
Merge branch 'jk/init-core-worktree-at-root'
We avoid setting core.worktree when the repository location is the ".git" directory directly at the top level of the working tree, but the code misdetected the case in which the working tree is at the root level of the filesystem (which arguably is a silly thing to do, but still valid). * jk/init-core-worktree-at-root: init: don't set core.worktree when initializing /.git
Diffstat (limited to 'builtin/init-db.c')
-rw-r--r--builtin/init-db.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 6723d39c3..ab9f86b88 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -182,6 +182,20 @@ static int git_init_db_config(const char *k, const char *v, void *cb)
return 0;
}
+/*
+ * If the git_dir is not directly inside the working tree, then git will not
+ * find it by default, and we need to set the worktree explicitly.
+ */
+static int needs_work_tree_config(const char *git_dir, const char *work_tree)
+{
+ if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
+ return 0;
+ if (skip_prefix(git_dir, work_tree, &git_dir) &&
+ !strcmp(git_dir, "/.git"))
+ return 0;
+ return 1;
+}
+
static int create_default_files(const char *template_path)
{
const char *git_dir = get_git_dir();
@@ -274,10 +288,8 @@ static int create_default_files(const char *template_path)
/* allow template config file to override the default */
if (log_all_ref_updates == -1)
git_config_set("core.logallrefupdates", "true");
- if (!starts_with(git_dir, work_tree) ||
- strcmp(git_dir + strlen(work_tree), "/.git")) {
+ if (needs_work_tree_config(git_dir, work_tree))
git_config_set("core.worktree", work_tree);
- }
}
if (!reinit) {