diff options
| author | Russell Belfer <rb@github.com> | 2013-02-26 13:15:06 -0800 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-02-26 13:15:06 -0800 |
| commit | 0d1b094b07d836a657ad9e458e04490d1e72d365 (patch) | |
| tree | 418248c23ebf7705164460704412980de509ef5e /tests-clar/repo/init.c | |
| parent | 3c42e4ef7428de18784e04c9cac18de3613144cb (diff) | |
| download | libgit2-0d1b094b07d836a657ad9e458e04490d1e72d365.tar.gz | |
Fix portability issues on Windows
The new tests were not taking core.filemode into account when
testing file modes after repo initialization. Fixed that and some
other Windows warnings that have crept in.
Diffstat (limited to 'tests-clar/repo/init.c')
| -rw-r--r-- | tests-clar/repo/init.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c index c69ea76ca..085d65f86 100644 --- a/tests-clar/repo/init.c +++ b/tests-clar/repo/init.c @@ -363,10 +363,23 @@ void test_repo_init__extended_1(void) cl_fixture_cleanup("root"); } +static uint32_t normalize_filemode(uint32_t mode, bool core_filemode) +{ + /* if no filemode support, strip SETGID, exec, and low-order bits */ + + /* cannot use constants because on platform without SETGID, that + * will have been defined to zero - must use hardcoded value to + * clear it effectively from the expected value + */ + + return core_filemode ? mode : (mode & ~02177); +} + static void assert_hooks_match( const char *template_dir, const char *repo_dir, const char *hook_path, + bool core_filemode, uint32_t expected_mode) { git_buf expected = GIT_BUF_INIT; @@ -384,6 +397,8 @@ static void assert_hooks_match( if (!expected_mode) expected_mode = (uint32_t)expected_st.st_mode; + expected_mode = normalize_filemode(expected_mode, core_filemode); + cl_assert_equal_i((int)expected_mode, (int)st.st_mode); git_buf_free(&expected); @@ -391,7 +406,7 @@ static void assert_hooks_match( } static void assert_has_mode( - const char *base, const char *path, uint32_t expected) + const char *base, const char *path, bool core_filemode, uint32_t expected) { git_buf full = GIT_BUF_INIT; struct stat st; @@ -400,6 +415,8 @@ static void assert_has_mode( cl_git_pass(git_path_lstat(full.ptr, &st)); git_buf_free(&full); + expected = normalize_filemode(expected, core_filemode); + cl_assert_equal_i((int)expected, (int)st.st_mode); } @@ -433,11 +450,11 @@ void test_repo_init__extended_with_template(void) assert_hooks_match( cl_fixture("template"), git_repository_path(_repo), - "hooks/update.sample", 0); + "hooks/update.sample", true, 0); assert_hooks_match( cl_fixture("template"), git_repository_path(_repo), - "hooks/link.sample", 0); + "hooks/link.sample", true, 0); } void test_repo_init__extended_with_template_and_shared_mode(void) @@ -445,6 +462,8 @@ void test_repo_init__extended_with_template_and_shared_mode(void) git_buf expected = GIT_BUF_INIT; git_buf actual = GIT_BUF_INIT; git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; + git_config *config; + int filemode = true; cl_set_cleanup(&cleanup_repository, "init_shared_from_tpl"); @@ -458,6 +477,10 @@ void test_repo_init__extended_with_template_and_shared_mode(void) cl_assert(!git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/init_shared_from_tpl/.git/")); + cl_git_pass(git_repository_config(&config, _repo)); + cl_git_pass(git_config_get_bool(&filemode, config, "core.filemode")); + git_config_free(config); + cl_git_pass(git_futils_readbuffer( &expected, cl_fixture("template/description"))); cl_git_pass(git_futils_readbuffer( @@ -468,17 +491,17 @@ void test_repo_init__extended_with_template_and_shared_mode(void) git_buf_free(&expected); git_buf_free(&actual); - assert_has_mode(git_repository_path(_repo), "hooks", + assert_has_mode(git_repository_path(_repo), "hooks", filemode, GIT_REPOSITORY_INIT_SHARED_GROUP | S_IFDIR); - assert_has_mode(git_repository_path(_repo), "info", + assert_has_mode(git_repository_path(_repo), "info", filemode, GIT_REPOSITORY_INIT_SHARED_GROUP | S_IFDIR); - assert_has_mode(git_repository_path(_repo), "description", + assert_has_mode(git_repository_path(_repo), "description", filemode, (GIT_REPOSITORY_INIT_SHARED_GROUP | S_IFREG) & ~(S_ISGID | 0111)); /* for a non-symlinked hook, it should have shared permissions now */ assert_hooks_match( cl_fixture("template"), git_repository_path(_repo), - "hooks/update.sample", + "hooks/update.sample", filemode, (GIT_REPOSITORY_INIT_SHARED_GROUP | S_IFREG) & ~S_ISGID); /* for a symlinked hook, the permissions still should match the @@ -486,7 +509,7 @@ void test_repo_init__extended_with_template_and_shared_mode(void) */ assert_hooks_match( cl_fixture("template"), git_repository_path(_repo), - "hooks/link.sample", 0); + "hooks/link.sample", filemode, 0); } void test_repo_init__can_reinit_an_initialized_repository(void) |
