diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/path.c | 16 | ||||
-rw-r--r-- | src/path.h | 5 | ||||
-rw-r--r-- | src/submodule.c | 11 |
3 files changed, 32 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c index 3e63f06d4..8317aaaa7 100644 --- a/src/path.c +++ b/src/path.c @@ -1676,3 +1676,19 @@ bool git_path_isvalid( return verify_component(repo, start, (c - start), flags); } + +int git_path_normalize_slashes(git_buf *out, const char *path) +{ + int error; + char *p; + + if ((error = git_buf_puts(out, path)) < 0) + return error; + + for (p = out->ptr; *p; p++) { + if (*p == '\\') + *p = '/'; + } + + return 0; +} diff --git a/src/path.h b/src/path.h index 5927a5381..adb76865e 100644 --- a/src/path.h +++ b/src/path.h @@ -591,4 +591,9 @@ extern bool git_path_isvalid( const char *path, unsigned int flags); +/** + * Convert any backslashes into slashes + */ +int git_path_normalize_slashes(git_buf *out, const char *path); + #endif diff --git a/src/submodule.c b/src/submodule.c index 892c98304..991ebc8f3 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -781,11 +781,21 @@ const char *git_submodule_url(git_submodule *submodule) int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *url) { int error = 0; + git_buf normalized = GIT_BUF_INIT; assert(out && repo && url); git_buf_sanitize(out); + /* We do this in all platforms in case someone on Windows created the .gitmodules */ + if (strchr(url, '\\')) { + if ((error = git_path_normalize_slashes(&normalized, url)) < 0) + return error; + + url = normalized.ptr; + } + + if (git_path_is_relative(url)) { if (!(error = get_url_base(out, repo))) error = git_path_apply_relative(out, url); @@ -796,6 +806,7 @@ int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *ur error = -1; } + git_buf_free(&normalized); return error; } |