Fix errors on Win32 with new repo init
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
diff --git a/src/fileops.c b/src/fileops.c
index 5df3123..eecfc28 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -604,7 +604,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
return -1;
if (p_lstat(info->to.ptr, &to_st) < 0) {
- if (errno != ENOENT) {
+ if (errno != ENOENT && errno != ENOTDIR) {
giterr_set(GITERR_OS,
"Could not access %s while copying files", info->to.ptr);
return -1;
diff --git a/src/repository.c b/src/repository.c
index bf19d07..18788d1 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -914,17 +914,20 @@ static int repo_init_structure(
mode_t dmode = pick_dir_mode(opts);
/* Hide the ".git" directory */
- if ((opts->flags & GIT_REPOSITORY_INIT_BARE) != 0) {
#ifdef GIT_WIN32
+ if ((opts->flags & GIT_REPOSITORY_INIT__HAS_DOTGIT) != 0) {
if (p_hide_directory__w32(repo_dir) < 0) {
giterr_set(GITERR_REPOSITORY,
"Failed to mark Git repository folder as hidden");
return -1;
}
-#endif
}
- /* Create .git gitlink if appropriate */
- else if ((opts->flags & GIT_REPOSITORY_INIT__NATURAL_WD) == 0) {
+#endif
+
+ /* Create the .git gitlink if appropriate */
+ if ((opts->flags & GIT_REPOSITORY_INIT_BARE) == 0 &&
+ (opts->flags & GIT_REPOSITORY_INIT__NATURAL_WD) == 0)
+ {
if (repo_write_gitlink(work_dir, repo_dir) < 0)
return -1;
}
diff --git a/tests-clar/core/mkdir.c b/tests-clar/core/mkdir.c
index d7723be..08ba241 100644
--- a/tests-clar/core/mkdir.c
+++ b/tests-clar/core/mkdir.c
@@ -111,6 +111,16 @@ static void cleanup_chmod_root(void *ref)
git_futils_rmdir_r("r", GIT_DIRREMOVAL_EMPTY_HIERARCHY);
}
+static void check_mode(mode_t expected, mode_t actual)
+{
+#ifdef GIT_WIN32
+ /* chmod on Win32 doesn't support exec bit, not group/world bits */
+ cl_assert((expected & 0600) == (actual & 0777));
+#else
+ cl_assert(expected == (actual & 0777));
+#endif
+}
+
void test_core_mkdir__chmods(void)
{
struct stat st;
@@ -124,49 +134,49 @@ void test_core_mkdir__chmods(void)
cl_git_pass(git_futils_mkdir("mode/is/important", "r", 0777, GIT_MKDIR_PATH));
cl_git_pass(git_path_lstat("r/mode", &st));
- cl_assert((st.st_mode & 0777) == 0755);
+ check_mode(0755, st.st_mode);
cl_git_pass(git_path_lstat("r/mode/is", &st));
- cl_assert((st.st_mode & 0777) == 0755);
+ check_mode(0755, st.st_mode);
cl_git_pass(git_path_lstat("r/mode/is/important", &st));
- cl_assert((st.st_mode & 0777) == 0755);
+ check_mode(0755, st.st_mode);
cl_git_pass(git_futils_mkdir("mode2/is2/important2", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD));
cl_git_pass(git_path_lstat("r/mode2", &st));
- cl_assert((st.st_mode & 0777) == 0755);
+ check_mode(0755, st.st_mode);
cl_git_pass(git_path_lstat("r/mode2/is2", &st));
- cl_assert((st.st_mode & 0777) == 0755);
+ check_mode(0755, st.st_mode);
cl_git_pass(git_path_lstat("r/mode2/is2/important2", &st));
- cl_assert((st.st_mode & 0777) == 0777);
+ check_mode(0777, st.st_mode);
cl_git_pass(git_futils_mkdir("mode3/is3/important3", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH));
cl_git_pass(git_path_lstat("r/mode3", &st));
- cl_assert((st.st_mode & 0777) == 0777);
+ check_mode(0777, st.st_mode);
cl_git_pass(git_path_lstat("r/mode3/is3", &st));
- cl_assert((st.st_mode & 0777) == 0777);
+ check_mode(0777, st.st_mode);
cl_git_pass(git_path_lstat("r/mode3/is3/important3", &st));
- cl_assert((st.st_mode & 0777) == 0777);
+ check_mode(0777, st.st_mode);
/* test that we chmod existing dir */
cl_git_pass(git_futils_mkdir("mode/is/important", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD));
cl_git_pass(git_path_lstat("r/mode", &st));
- cl_assert((st.st_mode & 0777) == 0755);
+ check_mode(0755, st.st_mode);
cl_git_pass(git_path_lstat("r/mode/is", &st));
- cl_assert((st.st_mode & 0777) == 0755);
+ check_mode(0755, st.st_mode);
cl_git_pass(git_path_lstat("r/mode/is/important", &st));
- cl_assert((st.st_mode & 0777) == 0777);
+ check_mode(0777, st.st_mode);
/* test that we chmod even existing dirs if CHMOD_PATH is set */
cl_git_pass(git_futils_mkdir("mode2/is2/important2.1", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH));
cl_git_pass(git_path_lstat("r/mode2", &st));
- cl_assert((st.st_mode & 0777) == 0777);
+ check_mode(0777, st.st_mode);
cl_git_pass(git_path_lstat("r/mode2/is2", &st));
- cl_assert((st.st_mode & 0777) == 0777);
+ check_mode(0777, st.st_mode);
cl_git_pass(git_path_lstat("r/mode2/is2/important2.1", &st));
- cl_assert((st.st_mode & 0777) == 0777);
+ check_mode(0777, st.st_mode);
}
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c
index 9cbc02b..67a9917 100644
--- a/tests-clar/repo/init.c
+++ b/tests-clar/repo/init.c
@@ -30,6 +30,8 @@ static void ensure_repository_init(
{
const char *workdir;
+ cl_assert(!git_path_isdir(working_directory));
+
cl_git_pass(git_repository_init(&_repo, working_directory, is_bare));
workdir = git_repository_workdir(_repo);
@@ -47,7 +49,8 @@ static void ensure_repository_init(
#ifdef GIT_WIN32
if (!is_bare) {
- cl_assert((GetFileAttributes(git_repository_path(_repo)) & FILE_ATTRIBUTE_HIDDEN) != 0);
+ DWORD fattrs = GetFileAttributes(git_repository_path(_repo));
+ cl_assert((fattrs & FILE_ATTRIBUTE_HIDDEN) != 0);
}
#endif