summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-08-24 22:10:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-08-26 17:03:41 (GMT)
commite2683d51d96f5e95489d29ee6dfafdde790579e4 (patch)
treed9541af473ce436ba947072aaaea83ae7d572a22
parentd17f2124a7860c2f37eaba574a867dbb4f506c27 (diff)
downloadgit-e2683d51d96f5e95489d29ee6dfafdde790579e4.zip
git-e2683d51d96f5e95489d29ee6dfafdde790579e4.tar.gz
git-e2683d51d96f5e95489d29ee6dfafdde790579e4.tar.bz2
Fix .git/ discovery at the root of UNC shares
A very common assumption in Git's source code base is that offset_1st_component() returns either 0 for relative paths, or 1 for absolute paths that start with a slash. In other words, the return value is either 0 or points just after the dir separator. This assumption is not fulfilled when calling offset_1st_component() e.g. on UNC paths on Windows, e.g. "//my-server/my-share". In this case, offset_1st_component() returns the length of the entire string (which is correct, because stripping the last "component" would not result in a valid directory), yet the return value still does not point just after a dir separator. This assumption is most prominently seen in the setup_git_directory_gently_1() function, where we want to append a ".git" component and simply assume that there is already a dir separator. In the UNC example given above, this assumption is incorrect. As a consequence, Git will fail to handle a worktree at the top of a UNC share correctly. Let's fix this by adding a dir separator specifically for that case: we found that there is no first component in the path and it does not end in a dir separator? Then add it. This fixes https://github.com/git-for-windows/git/issues/1320 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--setup.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/setup.c b/setup.c
index bb039ee..a0cb42c 100644
--- a/setup.c
+++ b/setup.c
@@ -947,6 +947,12 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
if (ceil_offset < 0)
ceil_offset = min_offset - 2;
+ if (min_offset && min_offset == dir->len &&
+ !is_dir_sep(dir->buf[min_offset - 1])) {
+ strbuf_addch(dir, '/');
+ min_offset++;
+ }
+
/*
* Test in the following order (relative to the dir):
* - .git (file containing "gitdir: <path>")