Skip to content

Commit 33d4669

Browse files
committed
Merge branch 'ss/safe-create-leading-dir-with-slash'
"git clone $origin foo\bar\baz" on Windows failed to create the leading directories (i.e. a moral-equivalent of "mkdir -p"). * ss/safe-create-leading-dir-with-slash: safe_create_leading_directories(): on Windows, \ can separate path components
2 parents d0956cf + 0f52740 commit 33d4669

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)