Skip to content

Commit df380d5

Browse files
dschogitster
authored andcommitted
setup: prepare setup_discovered_git_dir() for the root directory
Currently, the offset parameter (indicating what part of the cwd parameter corresponds to the current directory after discovering the .git/ directory) is set to 0 when we are running in the root directory. However, in the next patches we will avoid changing the current working directory while searching for the .git/ directory, meaning that the offset corresponding to the root directory will have to be 1 to reflect that this directory is characterized by the path "/" (and not ""). So let's make sure that setup_discovered_git_directory() only tries to append the trailing slash to non-root directories. Note: the setup_bare_git_directory() does not need a corresponding change, as it does not want to return a prefix. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c1e654 commit df380d5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

setup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,10 @@ static const char *setup_discovered_git_dir(const char *gitdir,
721721
if (offset == cwd->len)
722722
return NULL;
723723

724-
/* Make "offset" point to past the '/', and add a '/' at the end */
725-
offset++;
724+
/* Make "offset" point past the '/' (already the case for root dirs) */
725+
if (offset != offset_1st_component(cwd->buf))
726+
offset++;
727+
/* Add a '/' at the end */
726728
strbuf_addch(cwd, '/');
727729
return cwd->buf + offset;
728730
}

0 commit comments

Comments
 (0)