Skip to content

Commit d0d9f61

Browse files
committed
Merge branch 'gitdir-at-unc-root'
This fixes a bug where a .git directory at the root of a network share (e.g. \\MYSERVER\sharedfolder\.git) was not handled correctly. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 6eca67d + 8ff8c5b commit d0d9f61

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

setup.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ static const char *setup_discovered_git_dir(const char *gitdir,
784784
set_git_dir(gitdir);
785785
inside_git_dir = 0;
786786
inside_work_tree = 1;
787-
if (offset == cwd->len)
787+
if (offset >= cwd->len)
788788
return NULL;
789789

790790
/* Make "offset" point past the '/' (already the case for root dirs) */
@@ -906,7 +906,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
906906
const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
907907
struct string_list ceiling_dirs = STRING_LIST_INIT_DUP;
908908
const char *gitdirenv;
909-
int ceil_offset = -1, min_offset = has_dos_drive_prefix(dir->buf) ? 3 : 1;
909+
int ceil_offset = -1, min_offset = offset_1st_component(dir->buf);
910910
dev_t current_device = 0;
911911
int one_filesystem = 1;
912912

@@ -934,6 +934,12 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
934934
if (ceil_offset < 0)
935935
ceil_offset = min_offset - 2;
936936

937+
if (min_offset && min_offset == dir->len &&
938+
!is_dir_sep(dir->buf[min_offset - 1])) {
939+
strbuf_addch(dir, '/');
940+
min_offset++;
941+
}
942+
937943
/*
938944
* Test in the following order (relative to the dir):
939945
* - .git (file containing "gitdir: <path>")

0 commit comments

Comments
 (0)