Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorGoss Geppert <ggossdev@gmail.com>2022-06-17 02:19:55 +0300
committerJunio C Hamano <gitster@pobox.com>2022-06-22 08:47:33 +0300
commit27128996b88f3dd0624324f8eb9648c0754cfa20 (patch)
treee8637f0c41193f7627d4247b8a058b4f9d74ba2a /dir.c
parent6cd33dceed60949e2dbc32e3f0f5e67c4c882e1e (diff)
dir: traverse into repository
Since 8d92fb2927 (dir: replace exponential algorithm with a linear one, 2020-04-01) traversing into a repository's directory tree when the traversal began outside the repository's standard location has failed because the encountered repository was identified as a nested foreign repository. Prior to this commit, the failure to traverse into a repository's default worktree location was observable from a user's perspective under either of the following conditions (there may be others): 1) Set the `core.worktree` location to a parent directory of the default worktree; or 2) Use the `--git_dir` option while the working directory is outside the repository's default worktree location Under either of these conditions, symptoms of the failure to traverse into the repository's default worktree location include the inability to add files to the index or get a list of untracked files via ls-files. This commit adds a check to determine whether a nested repository that is encountered in recursing a path is actually `the_repository`. If so, we simply treat the directory as if it doesn't contain a nested repository. The commit includes test-cases to reduce the likelihood of future regressions. Signed-off-by: Goss Geppert <ggossdev@gmail.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/dir.c b/dir.c
index f2b0f24210..0fd5912b39 100644
--- a/dir.c
+++ b/dir.c
@@ -1893,9 +1893,28 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
!(dir->flags & DIR_NO_GITLINKS)) {
+ /*
+ * Determine if `dirname` is a nested repo by confirming that:
+ * 1) we are in a nonbare repository, and
+ * 2) `dirname` is not an immediate parent of `the_repository->gitdir`,
+ * which could occur if the git_dir or worktree location was
+ * manually configured by the user; see t2205 testcases 1-3 for
+ * examples where this matters
+ */
struct strbuf sb = STRBUF_INIT;
strbuf_addstr(&sb, dirname);
nested_repo = is_nonbare_repository_dir(&sb);
+
+ if (nested_repo) {
+ char *real_dirname, *real_gitdir;
+ strbuf_addstr(&sb, ".git");
+ real_dirname = real_pathdup(sb.buf, 1);
+ real_gitdir = real_pathdup(the_repository->gitdir, 1);
+
+ nested_repo = !!strcmp(real_dirname, real_gitdir);
+ free(real_gitdir);
+ free(real_dirname);
+ }
strbuf_release(&sb);
}
if (nested_repo) {