summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-08-24 10:48:48 -0700
committerRussell Belfer <rb@github.com>2012-08-24 10:48:48 -0700
commit2eb4edf5f269f60b188ff72d350ee321d1cbaf79 (patch)
tree8f0217382b94730cb7692653a313c526020bfe6f
parentc920e162325d0f9acba46a19c4619e6bfa17707e (diff)
downloadlibgit2-2eb4edf5f269f60b188ff72d350ee321d1cbaf79.tar.gz
Fix errors on Win32 with new repo init
-rw-r--r--src/fileops.c2
-rw-r--r--src/repository.c11
-rw-r--r--tests-clar/core/mkdir.c40
-rw-r--r--tests-clar/repo/init.c5
4 files changed, 37 insertions, 21 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 5df312360..eecfc2847 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 bf19d0706..18788d187 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 d7723be8d..08ba2419e 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 9cbc02b8f..67a9917db 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