diff options
author | Vicent Martà <tanoku@gmail.com> | 2012-03-16 12:41:09 -0700 |
---|---|---|
committer | Vicent Martà <tanoku@gmail.com> | 2012-03-16 12:41:09 -0700 |
commit | 4cfe2ab60b1e26554b2bf753b06f538cb3475bd0 (patch) | |
tree | a57958a3f68e326fe657aacd3e63c39ac725a9d9 | |
parent | e24fbba94862fdb602846771f2ae41ef15834d10 (diff) | |
parent | 7b93079b5b7c5f58de321bb9846e93b1717d3e4c (diff) | |
download | libgit2-4cfe2ab60b1e26554b2bf753b06f538cb3475bd0.tar.gz |
Merge pull request #600 from nulltoken/fix/windows-network-paths
Fix windows network paths
-rw-r--r-- | src/path.c | 9 | ||||
-rw-r--r-- | tests-clar/core/path.c | 15 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c index 0f45d7130..45cc94e82 100644 --- a/src/path.c +++ b/src/path.c @@ -171,6 +171,15 @@ int git_path_root(const char *path) /* Does the root of the path look like a windows drive ? */ if (isalpha(path[0]) && (path[1] == ':')) offset += 2; + + /* Are we dealing with a network path? */ + else if (path[0] == '/' && path[1] == '/') { + offset += 2; + + /* Skip the computer name segment */ + while (*(path + offset) && *(path + offset) != '/') + offset++; + } #endif if (*(path + offset) == '/') diff --git a/tests-clar/core/path.c b/tests-clar/core/path.c index c07362f1d..c1e3ef29c 100644 --- a/tests-clar/core/path.c +++ b/tests-clar/core/path.c @@ -388,3 +388,18 @@ void test_core_path__11_walkup(void) git_buf_free(&p); } + +void test_core_path__12_offset_to_path_root(void) +{ + cl_assert(git_path_root("non/rooted/path") == -1); + cl_assert(git_path_root("/rooted/path") == 0); + +#ifdef GIT_WIN32 + /* Windows specific tests */ + cl_assert(git_path_root("C:non/rooted/path") == -1); + cl_assert(git_path_root("C:/rooted/path") == 2); + cl_assert(git_path_root("//computername/sharefolder/resource") == 14); + cl_assert(git_path_root("//computername/sharefolder") == 14); + cl_assert(git_path_root("//computername") == -1); +#endif +} |