It can be surprising to some users that pointing GIT_DIR to a ".git" directory does not use the working tree that surrounds the .git directory, but rather uses the current working directory as the working tree. Git has always worked this way, and for the most part it has not been a big problem. However, given that one way of the user finding this out is by having a destructive git command impact an unexpected area of the filesystem, it would be nice to default to something less surprising and likely to cause problems (namely, having no working directory). This breaks existing users of the feature, of course; they can adapt by setting GIT_WORK_TREE explicitly to ".", but they need to be told to do so. Therefore we'll start with a deprecation period and a warning to give them time to fix their scripts and workflows. Signed-off-by: Jeff King <peff@xxxxxxxx> --- setup.c | 21 ++++++++++++++++++++- t/t1510-repo-setup.sh | 8 ++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/setup.c b/setup.c index 01c5476..afc245f 100644 --- a/setup.c +++ b/setup.c @@ -437,6 +437,23 @@ const char *read_gitfile(const char *path) return path; } +static const char warn_implicit_work_tree_msg[] = +N_("You have set GIT_DIR (or used --git-dir) without specifying\n" + "a working tree. In Git 2.0, the behavior will change from using current\n" + "working directory as the working tree to having no working tree at all.\n" + "If you wish to continue the current behavior, please set GIT_WORK_TREE\n" + "or core.worktree explicitly. See `git help git` for more details."); + +static void warn_implicit_work_tree(void) +{ + static int warn_once; + + if (warn_once++) + return; + + warning("%s", _(warn_implicit_work_tree_msg)); +} + static const char *setup_explicit_git_dir(const char *gitdirenv, char *cwd, int len, int *nongit_ok) @@ -503,8 +520,10 @@ static const char *setup_explicit_git_dir(const char *gitdirenv, free(gitfile); return NULL; } - else /* #2, #10 */ + else { /* #2, #10 */ + warn_implicit_work_tree(); set_git_work_tree("."); + } /* set_git_work_tree() must have been called by now */ worktree = get_git_work_tree(); diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh index cf2ee78..0910de1 100755 --- a/t/t1510-repo-setup.sh +++ b/t/t1510-repo-setup.sh @@ -243,7 +243,9 @@ test_expect_success '#2: worktree defaults to cwd with explicit GIT_DIR' ' test_expect_success '#2: worktree defaults to cwd with explicit GIT_DIR' ' try_repo 2 unset "$here/2/.git" unset "" unset \ "$here/2/.git" "$here/2" "$here/2" "(null)" \ - "$here/2/.git" "$here/2/sub" "$here/2/sub" "(null)" + "$here/2/.git" "$here/2/sub" "$here/2/sub" "(null)" \ + 2>message && + test_i18ngrep "warning:.*GIT_DIR" message ' test_expect_success '#2b: relative GIT_DIR' ' @@ -378,7 +380,9 @@ test_expect_success '#10: GIT_DIR can point to gitfile' ' test_expect_success '#10: GIT_DIR can point to gitfile' ' try_repo 10 unset "$here/10/.git" unset gitfile unset \ "$here/10.git" "$here/10" "$here/10" "(null)" \ - "$here/10.git" "$here/10/sub" "$here/10/sub" "(null)" + "$here/10.git" "$here/10/sub" "$here/10/sub" "(null)" \ + 2>message && + test_i18ngrep "warning:.*GIT_DIR" message ' test_expect_success '#10b: relative GIT_DIR can point to gitfile' ' -- 1.8.2.13.g0f18d3c -- 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