Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 0f52740

Browse files
mhaggergitster
authored andcommitted
safe_create_leading_directories(): on Windows, \ can separate path components
When cloning to a directory "C:\foo\bar" from Windows' cmd.exe where "foo" does not exist yet, Git would throw an error like fatal: could not create work tree dir 'c:\foo\bar'.: No such file or directory Fix this by not hard-coding a platform specific directory separator into safe_create_leading_directories(). This patch, including its entire commit message, is derived from a patch by Sebastian Schuberth. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Sebastian Schuberth <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 08f555c commit 0f52740

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sha1_file.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,21 @@ enum scld_error safe_create_leading_directories(char *path)
112112

113113
while (ret == SCLD_OK && next_component) {
114114
struct stat st;
115-
char *slash = strchr(next_component, '/');
115+
char *slash = next_component, slash_character;
116116

117-
if (!slash)
117+
while (*slash && !is_dir_sep(*slash))
118+
slash++;
119+
120+
if (!*slash)
118121
break;
119122

120123
next_component = slash + 1;
121-
while (*next_component == '/')
124+
while (is_dir_sep(*next_component))
122125
next_component++;
123126
if (!*next_component)
124127
break;
125128

129+
slash_character = *slash;
126130
*slash = '\0';
127131
if (!stat(path, &st)) {
128132
/* path exists */
@@ -148,7 +152,7 @@ enum scld_error safe_create_leading_directories(char *path)
148152
} else if (adjust_shared_perm(path)) {
149153
ret = SCLD_PERMS;
150154
}
151-
*slash = '/';
155+
*slash = slash_character;
152156
}
153157
return ret;
154158
}

0 commit comments

Comments
 (0)