Skip to content

Commit

Permalink
safe_create_leading_directories(): on Windows, \ can separate path co…
Browse files Browse the repository at this point in the history
…mponents

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 <johannes.schindelin@gmx.de>
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Jan 22, 2014
1 parent 08f555c commit 0f52740
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,21 @@ enum scld_error safe_create_leading_directories(char *path)

while (ret == SCLD_OK && next_component) {
struct stat st;
char *slash = strchr(next_component, '/');
char *slash = next_component, slash_character;

if (!slash)
while (*slash && !is_dir_sep(*slash))
slash++;

if (!*slash)
break;

next_component = slash + 1;
while (*next_component == '/')
while (is_dir_sep(*next_component))
next_component++;
if (!*next_component)
break;

slash_character = *slash;
*slash = '\0';
if (!stat(path, &st)) {
/* path exists */
Expand All @@ -148,7 +152,7 @@ enum scld_error safe_create_leading_directories(char *path)
} else if (adjust_shared_perm(path)) {
ret = SCLD_PERMS;
}
*slash = '/';
*slash = slash_character;
}
return ret;
}
Expand Down

0 comments on commit 0f52740

Please sign in to comment.