Fix compile and workings on msvc. Signed-off-by: Ben Straub <bstraub@github.com>
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 86 87 88 89 90
diff --git a/src/checkout.c b/src/checkout.c
index b9b5bc1..907253f 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -36,16 +36,16 @@ static int apply_filters(git_buf *out,
size_t len)
{
int retcode = GIT_ERROR;
+ git_buf origblob = GIT_BUF_INIT;
git_buf_clear(out);
if (!filters->length) {
/* No filters to apply; just copy the result */
- git_buf_put(out, data, len);
+ git_buf_put(out, (const char *)data, len);
return 0;
}
- git_buf origblob = GIT_BUF_INIT;
git_buf_attach(&origblob, (char*)data, len);
retcode = git_filters_apply(out, &origblob, filters);
git_buf_detach(&origblob);
diff --git a/src/path.c b/src/path.c
index e667ec3..e640675 100644
--- a/src/path.c
+++ b/src/path.c
@@ -391,8 +391,16 @@ bool git_path_isfile(const char *path)
#ifdef GIT_WIN32
+static bool is_dot_or_dotdotW(const wchar_t *name)
+{
+ return (name[0] == L'.' &&
+ (name[1] == L'\0' ||
+ (name[1] == L'.' && name[2] == L'\0')));
+}
+
bool git_path_is_empty_dir(const char *path)
{
+ git_buf pathbuf = GIT_BUF_INIT;
HANDLE hFind = INVALID_HANDLE_VALUE;
wchar_t *wbuf;
WIN32_FIND_DATAW ffd;
@@ -400,13 +408,23 @@ bool git_path_is_empty_dir(const char *path)
if (!git_path_isdir(path)) return false;
- wbuf = gitwin_to_utf16(path);
- gitwin_append_utf16(wbuf, "\\*", 2);
+ git_buf_printf(&pathbuf, "%s\\*", path);
+ wbuf = gitwin_to_utf16(git_buf_cstr(&pathbuf));
+
hFind = FindFirstFileW(wbuf, &ffd);
- if (INVALID_HANDLE_VALUE != hFind) {
- retval = false;
- FindClose(hFind);
+ if (INVALID_HANDLE_VALUE == hFind) {
+ giterr_set(GITERR_OS, "Couldn't open '%s'", path);
+ return false;
}
+
+ do {
+ if (!is_dot_or_dotdotW(ffd.cFileName)) {
+ retval = false;
+ }
+ } while (FindNextFileW(hFind, &ffd) != 0);
+
+ FindClose(hFind);
+ git_buf_free(&pathbuf);
git__free(wbuf);
return retval;
}
diff --git a/tests-clar/clone/clone.c b/tests-clar/clone/clone.c
index 49deeaa..3fba91c 100644
--- a/tests-clar/clone/clone.c
+++ b/tests-clar/clone/clone.c
@@ -96,10 +96,10 @@ void test_clone_clone__network_full(void)
#if DO_LIVE_NETWORK_TESTS
git_remote *origin;
- cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test", NULL));
+ cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL));
cl_assert(!git_repository_is_bare(g_repo));
cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
- git_futils_rmdir_r("./test", GIT_DIRREMOVAL_FILES_AND_DIRS);
+ git_futils_rmdir_r("./test2", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif
}