Merge pull request #2867 from ethomson/8dot3 Handle 8dot3 filenames being disabled on Win32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/src/repository.c b/src/repository.c
index d87ce73..4337544 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -808,7 +808,8 @@ const char *git_repository__8dot3_name(git_repository *repo)
/* We anticipate the 8.3 name is "GIT~1", so use a static for
* easy testing in the common case */
- if (strcasecmp(repo->name_8dot3, git_repository__8dot3_default) == 0)
+ if (repo->name_8dot3 &&
+ strcasecmp(repo->name_8dot3, git_repository__8dot3_default) == 0)
repo->has_8dot3_default = 1;
}
#endif
diff --git a/tests/checkout/nasty.c b/tests/checkout/nasty.c
index bc25a3b..952a6a1 100644
--- a/tests/checkout/nasty.c
+++ b/tests/checkout/nasty.c
@@ -217,6 +217,9 @@ void test_checkout_nasty__git_tilde1(void)
void test_checkout_nasty__git_custom_shortname(void)
{
#ifdef GIT_WIN32
+ if (!cl_sandbox_supports_8dot3())
+ clar__skip();
+
cl_must_pass(p_rename("nasty/.git", "nasty/_temp"));
cl_git_write2file("nasty/git~1", "", 0, O_RDWR|O_CREAT, 0666);
cl_must_pass(p_rename("nasty/_temp", "nasty/.git"));
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c
index a8a8ba6..6087c2a 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -538,3 +538,25 @@ void cl_sandbox_set_search_path_defaults(void)
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, sandbox_path);
}
+#ifdef GIT_WIN32
+bool cl_sandbox_supports_8dot3(void)
+{
+ git_buf longpath = GIT_BUF_INIT;
+ char *shortname;
+ bool supported;
+
+ cl_git_pass(
+ git_buf_joinpath(&longpath, clar_sandbox_path(), "longer_than_8dot3"));
+
+ cl_git_write2file(longpath.ptr, "", 0, O_RDWR|O_CREAT, 0666);
+ shortname = git_win32_path_8dot3_name(longpath.ptr);
+
+ supported = (shortname != NULL);
+
+ git__free(shortname);
+ git_buf_free(&longpath);
+
+ return supported;
+}
+#endif
+
diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h
index e1d62c8..86c90b0 100644
--- a/tests/clar_libgit2.h
+++ b/tests/clar_libgit2.h
@@ -161,4 +161,8 @@ void cl_fake_home_cleanup(void *);
void cl_sandbox_set_search_path_defaults(void);
+#ifdef GIT_WIN32
+bool cl_sandbox_supports_8dot3(void);
+#endif
+
#endif
diff --git a/tests/path/win32.c b/tests/path/win32.c
index 22742f8..4ff0397 100644
--- a/tests/path/win32.c
+++ b/tests/path/win32.c
@@ -194,6 +194,9 @@ void test_path_win32__8dot3_name(void)
#ifdef GIT_WIN32
char *shortname;
+ if (!cl_sandbox_supports_8dot3())
+ clar__skip();
+
/* Some guaranteed short names */
cl_assert_equal_s("PROGRA~1", (shortname = git_win32_path_8dot3_name("C:\\Program Files")));
git__free(shortname);