Skip to content

Commit dbfe535

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 61b2ae7 + 65ec1c5 commit dbfe535

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
@@ -797,7 +797,7 @@ static const char *setup_discovered_git_dir(const char *gitdir,
797797
set_git_dir(gitdir);
798798
inside_git_dir = 0;
799799
inside_work_tree = 1;
800-
if (offset == cwd->len)
800+
if (offset >= cwd->len)
801801
return NULL;
802802

803803
/* Make "offset" point past the '/' (already the case for root dirs) */
@@ -919,7 +919,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
919919
const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT);
920920
struct string_list ceiling_dirs = STRING_LIST_INIT_DUP;
921921
const char *gitdirenv;
922-
int ceil_offset = -1, min_offset = has_dos_drive_prefix(dir->buf) ? 3 : 1;
922+
int ceil_offset = -1, min_offset = offset_1st_component(dir->buf);
923923
dev_t current_device = 0;
924924
int one_filesystem = 1;
925925

@@ -947,6 +947,12 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
947947
if (ceil_offset < 0)
948948
ceil_offset = min_offset - 2;
949949

950+
if (min_offset && min_offset == dir->len &&
951+
!is_dir_sep(dir->buf[min_offset - 1])) {
952+
strbuf_addch(dir, '/');
953+
min_offset++;
954+
}
955+
950956
/*
951957
* Test in the following order (relative to the dir):
952958
* - .git (file containing "gitdir: <path>")

0 commit comments

Comments
 (0)