diff options
Diffstat (limited to 'tests-clar')
51 files changed, 902 insertions, 102 deletions
diff --git a/tests-clar/clar_helpers.c b/tests-clar/clar_helpers.c index d180285b8..1275d1620 100644 --- a/tests-clar/clar_helpers.c +++ b/tests-clar/clar_helpers.c @@ -48,6 +48,62 @@ void cl_git_rewritefile(const char *filename, const char *new_content) cl_git_write2file(filename, new_content, O_WRONLY | O_CREAT | O_TRUNC); } +#ifdef GIT_WIN32 + +#include "win32/utf-conv.h" + +char *cl_getenv(const char *name) +{ + wchar_t *name_utf16 = gitwin_to_utf16(name); + DWORD value_len, alloc_len; + wchar_t *value_utf16; + char *value_utf8; + + cl_assert(name_utf16); + alloc_len = GetEnvironmentVariableW(name_utf16, NULL, 0); + if (alloc_len <= 0) + return NULL; + + cl_assert(value_utf16 = git__calloc(alloc_len, sizeof(wchar_t))); + + value_len = GetEnvironmentVariableW(name_utf16, value_utf16, alloc_len); + cl_assert_equal_i(value_len, alloc_len - 1); + + cl_assert(value_utf8 = gitwin_from_utf16(value_utf16)); + + git__free(value_utf16); + + return value_utf8; +} + +int cl_setenv(const char *name, const char *value) +{ + wchar_t *name_utf16 = gitwin_to_utf16(name); + wchar_t *value_utf16 = value ? gitwin_to_utf16(value) : NULL; + + cl_assert(name_utf16); + cl_assert(SetEnvironmentVariableW(name_utf16, value_utf16)); + + git__free(name_utf16); + git__free(value_utf16); + + return 0; + +} +#else + +#include <stdlib.h> +char *cl_getenv(const char *name) +{ + return getenv(name); +} + +int cl_setenv(const char *name, const char *value) +{ + return (value == NULL) ? unsetenv(name) : setenv(name, value, 1); +} +#endif + static const char *_cl_sandbox = NULL; static git_repository *_cl_repo = NULL; @@ -98,3 +154,28 @@ void cl_git_sandbox_cleanup(void) _cl_sandbox = NULL; } } + +bool cl_toggle_filemode(const char *filename) +{ + struct stat st1, st2; + + cl_must_pass(p_stat(filename, &st1)); + cl_must_pass(p_chmod(filename, st1.st_mode ^ 0100)); + cl_must_pass(p_stat(filename, &st2)); + + return (st1.st_mode != st2.st_mode); +} + +bool cl_is_chmod_supported(void) +{ + static int _is_supported = -1; + + if (_is_supported < 0) { + cl_git_mkfile("filemode.t", "Test if filemode can be modified"); + _is_supported = cl_toggle_filemode("filemode.t"); + cl_must_pass(p_unlink("filemode.t")); + } + + return _is_supported; +} + diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h index d250494f5..a3b03bbb3 100644 --- a/tests-clar/clar_libgit2.h +++ b/tests-clar/clar_libgit2.h @@ -40,6 +40,13 @@ void cl_git_append2file(const char *filename, const char *new_content); void cl_git_rewritefile(const char *filename, const char *new_content); void cl_git_write2file(const char *filename, const char *new_content, int mode); +bool cl_toggle_filemode(const char *filename); +bool cl_is_chmod_supported(void); + +/* Environment wrappers */ +char *cl_getenv(const char *name); +int cl_setenv(const char *name, const char *value); + /* Git sandbox setup helpers */ git_repository *cl_git_sandbox_init(const char *sandbox); diff --git a/tests-clar/core/env.c b/tests-clar/core/env.c index 15d431f01..9361341eb 100644 --- a/tests-clar/core/env.c +++ b/tests-clar/core/env.c @@ -3,59 +3,6 @@ #include "path.h" #ifdef GIT_WIN32 - -#include "win32/utf-conv.h" - -static char *cl_getenv(const char *name) -{ - wchar_t *name_utf16 = gitwin_to_utf16(name); - DWORD value_len, alloc_len; - wchar_t *value_utf16; - char *value_utf8; - - cl_assert(name_utf16); - alloc_len = GetEnvironmentVariableW(name_utf16, NULL, 0); - if (alloc_len <= 0) - return NULL; - - cl_assert(value_utf16 = git__calloc(alloc_len, sizeof(wchar_t))); - - value_len = GetEnvironmentVariableW(name_utf16, value_utf16, alloc_len); - cl_assert_equal_i(value_len, alloc_len - 1); - - cl_assert(value_utf8 = gitwin_from_utf16(value_utf16)); - - git__free(value_utf16); - - return value_utf8; -} - -static int cl_setenv(const char *name, const char *value) -{ - wchar_t *name_utf16 = gitwin_to_utf16(name); - wchar_t *value_utf16 = value ? gitwin_to_utf16(value) : NULL; - - cl_assert(name_utf16); - cl_assert(SetEnvironmentVariableW(name_utf16, value_utf16)); - - git__free(name_utf16); - git__free(value_utf16); - - return 0; - -} -#else - -#include <stdlib.h> -#define cl_getenv(n) getenv(n) - -static int cl_setenv(const char *name, const char *value) -{ - return (value == NULL) ? unsetenv(name) : setenv(name, value, 1); -} -#endif - -#ifdef GIT_WIN32 static char *env_userprofile = NULL; static char *env_programfiles = NULL; #else diff --git a/tests-clar/core/filebuf.c b/tests-clar/core/filebuf.c index eab8a26eb..4451c01c7 100644 --- a/tests-clar/core/filebuf.c +++ b/tests-clar/core/filebuf.c @@ -8,7 +8,7 @@ void test_core_filebuf__0(void) int fd; char test[] = "test", testlock[] = "test.lock"; - fd = p_creat(testlock, 0744); + fd = p_creat(testlock, 0744); //-V536 cl_must_pass(fd); cl_must_pass(p_close(fd)); @@ -27,7 +27,7 @@ void test_core_filebuf__1(void) int fd; char test[] = "test"; - fd = p_creat(test, 0666); + fd = p_creat(test, 0666); //-V536 cl_must_pass(fd); cl_must_pass(p_write(fd, "libgit2 rocks\n", 14)); cl_must_pass(p_close(fd)); diff --git a/tests-clar/date/date.c b/tests-clar/date/date.c new file mode 100644 index 000000000..88881d1e1 --- /dev/null +++ b/tests-clar/date/date.c @@ -0,0 +1,15 @@ +#include "clar_libgit2.h" + +#include "util.h" + +void test_date_date__overflow(void) +{ +#ifdef __LP64__ + git_time_t d2038, d2039; + + /* This is expected to fail on a 32-bit machine. */ + cl_git_pass(git__date_parse(&d2038, "2038-1-1")); + cl_git_pass(git__date_parse(&d2039, "2039-1-1")); + cl_assert(d2038 < d2039); +#endif +} diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c index 8587be9b1..1d9f6121c 100644 --- a/tests-clar/diff/diff_helpers.c +++ b/tests-clar/diff/diff_helpers.c @@ -85,11 +85,16 @@ int diff_line_fn( e->line_ctxt++; break; case GIT_DIFF_LINE_ADDITION: - case GIT_DIFF_LINE_ADD_EOFNL: e->line_adds++; break; + case GIT_DIFF_LINE_ADD_EOFNL: + assert(0); + break; case GIT_DIFF_LINE_DELETION: + e->line_dels++; + break; case GIT_DIFF_LINE_DEL_EOFNL: + /* technically not a line delete, but we'll count it as such */ e->line_dels++; break; default: diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index b932fa10e..4201ad2a7 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -116,7 +116,7 @@ void test_diff_tree__options(void) { 5, 3, 0, 2, 0, 0, 0, 4, 0, 0, 51, 2, 46, 3 }, { 5, 3, 0, 2, 0, 0, 0, 4, 0, 0, 53, 4, 46, 3 }, { 5, 0, 3, 2, 0, 0, 0, 4, 0, 0, 52, 3, 3, 46 }, - { 5, 3, 0, 2, 0, 0, 0, 5, 0, 0, 54, 3, 48, 3 }, + { 5, 3, 0, 2, 0, 0, 0, 5, 0, 0, 54, 3, 47, 4 }, /* c vs d tests */ { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 22, 9, 10, 3 }, { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 19, 12, 7, 0 }, diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c index 42152f1ad..0c17eeb4a 100644 --- a/tests-clar/diff/workdir.c +++ b/tests-clar/diff/workdir.c @@ -5,7 +5,6 @@ static git_repository *g_repo = NULL; void test_diff_workdir__initialize(void) { - g_repo = cl_git_sandbox_init("status"); } void test_diff_workdir__cleanup(void) @@ -19,6 +18,8 @@ void test_diff_workdir__to_index(void) git_diff_list *diff = NULL; diff_expects exp; + g_repo = cl_git_sandbox_init("status"); + opts.context_lines = 3; opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; @@ -59,13 +60,17 @@ void test_diff_workdir__to_tree(void) /* grabbed a couple of commit oids from the history of the attr repo */ const char *a_commit = "26a125ee1bf"; /* the current HEAD */ const char *b_commit = "0017bd4ab1ec3"; /* the start */ - git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit); - git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit); + git_tree *a, *b; git_diff_options opts = {0}; git_diff_list *diff = NULL; git_diff_list *diff2 = NULL; diff_expects exp; + g_repo = cl_git_sandbox_init("status"); + + a = resolve_commit_oid_to_tree(g_repo, a_commit); + b = resolve_commit_oid_to_tree(g_repo, b_commit); + opts.context_lines = 3; opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; @@ -87,12 +92,12 @@ void test_diff_workdir__to_tree(void) cl_git_pass(git_diff_foreach( diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); - cl_assert(exp.files == 14); - cl_assert(exp.file_adds == 0); - cl_assert(exp.file_dels == 4); - cl_assert(exp.file_mods == 4); - cl_assert(exp.file_ignored == 1); - cl_assert(exp.file_untracked == 5); + cl_assert_equal_i(14, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(4, exp.file_dels); + cl_assert_equal_i(4, exp.file_mods); + cl_assert_equal_i(1, exp.file_ignored); + cl_assert_equal_i(5, exp.file_untracked); /* Since there is no git diff equivalent, let's just assume that the * text diffs produced by git_diff_foreach are accurate here. We will @@ -115,19 +120,19 @@ void test_diff_workdir__to_tree(void) cl_git_pass(git_diff_foreach( diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); - cl_assert(exp.files == 15); - cl_assert(exp.file_adds == 2); - cl_assert(exp.file_dels == 5); - cl_assert(exp.file_mods == 4); - cl_assert(exp.file_ignored == 1); - cl_assert(exp.file_untracked == 3); + cl_assert_equal_i(15, exp.files); + cl_assert_equal_i(2, exp.file_adds); + cl_assert_equal_i(5, exp.file_dels); + cl_assert_equal_i(4, exp.file_mods); + cl_assert_equal_i(1, exp.file_ignored); + cl_assert_equal_i(3, exp.file_untracked); - cl_assert(exp.hunks == 11); + cl_assert_equal_i(11, exp.hunks); - cl_assert(exp.lines == 17); - cl_assert(exp.line_ctxt == 4); - cl_assert(exp.line_adds == 8); - cl_assert(exp.line_dels == 5); + cl_assert_equal_i(17, exp.lines); + cl_assert_equal_i(4, exp.line_ctxt); + cl_assert_equal_i(8, exp.line_adds); + cl_assert_equal_i(5, exp.line_dels); git_diff_list_free(diff); diff = NULL; @@ -144,19 +149,19 @@ void test_diff_workdir__to_tree(void) cl_git_pass(git_diff_foreach( diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); - cl_assert(exp.files == 16); - cl_assert(exp.file_adds == 5); - cl_assert(exp.file_dels == 4); - cl_assert(exp.file_mods == 3); - cl_assert(exp.file_ignored == 1); - cl_assert(exp.file_untracked == 3); + cl_assert_equal_i(16, exp.files); + cl_assert_equal_i(5, exp.file_adds); + cl_assert_equal_i(4, exp.file_dels); + cl_assert_equal_i(3, exp.file_mods); + cl_assert_equal_i(1, exp.file_ignored); + cl_assert_equal_i(3, exp.file_untracked); - cl_assert(exp.hunks == 12); + cl_assert_equal_i(12, exp.hunks); - cl_assert(exp.lines == 19); - cl_assert(exp.line_ctxt == 3); - cl_assert(exp.line_adds == 12); - cl_assert(exp.line_dels == 4); + cl_assert_equal_i(19, exp.lines); + cl_assert_equal_i(3, exp.line_ctxt); + cl_assert_equal_i(12, exp.line_adds); + cl_assert_equal_i(4, exp.line_dels); git_diff_list_free(diff); @@ -171,6 +176,8 @@ void test_diff_workdir__to_index_with_pathspec(void) diff_expects exp; char *pathspec = NULL; + g_repo = cl_git_sandbox_init("status"); + opts.context_lines = 3; opts.interhunk_lines = 1; opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; @@ -237,6 +244,241 @@ void test_diff_workdir__to_index_with_pathspec(void) git_diff_list_free(diff); } +void test_diff_workdir__filemode_changes(void) +{ + git_config *cfg; + git_diff_list *diff = NULL; + diff_expects exp; + + if (!cl_is_chmod_supported()) + return; + + g_repo = cl_git_sandbox_init("issue_592"); + + cl_git_pass(git_repository_config(&cfg, g_repo)); + cl_git_pass(git_config_set_bool(cfg, "core.filemode", true)); + + /* test once with no mods */ + + cl_git_pass(git_diff_workdir_to_index(g_repo, NULL, &diff)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert_equal_i(0, exp.files); + cl_assert_equal_i(0, exp.file_mods); + cl_assert_equal_i(0, exp.hunks); + + git_diff_list_free(diff); + + /* chmod file and test again */ + + cl_assert(cl_toggle_filemode("issue_592/a.txt")); + + cl_git_pass(git_diff_workdir_to_index(g_repo, NULL, &diff)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert_equal_i(1, exp.files); + cl_assert_equal_i(1, exp.file_mods); + cl_assert_equal_i(0, exp.hunks); + + git_diff_list_free(diff); + + cl_assert(cl_toggle_filemode("issue_592/a.txt")); + git_config_free(cfg); +} + +void test_diff_workdir__filemode_changes_with_filemode_false(void) +{ + git_config *cfg; + git_diff_list *diff = NULL; + diff_expects exp; + + if (!cl_is_chmod_supported()) + return; + + g_repo = cl_git_sandbox_init("issue_592"); + + cl_git_pass(git_repository_config(&cfg, g_repo)); + cl_git_pass(git_config_set_bool(cfg, "core.filemode", false)); + + /* test once with no mods */ + + cl_git_pass(git_diff_workdir_to_index(g_repo, NULL, &diff)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert_equal_i(0, exp.files); + cl_assert_equal_i(0, exp.file_mods); + cl_assert_equal_i(0, exp.hunks); + + git_diff_list_free(diff); + + /* chmod file and test again */ + + cl_assert(cl_toggle_filemode("issue_592/a.txt")); + + cl_git_pass(git_diff_workdir_to_index(g_repo, NULL, &diff)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert_equal_i(0, exp.files); + cl_assert_equal_i(0, exp.file_mods); + cl_assert_equal_i(0, exp.hunks); + + git_diff_list_free(diff); + + cl_assert(cl_toggle_filemode("issue_592/a.txt")); + git_config_free(cfg); +} + +void test_diff_workdir__head_index_and_workdir_all_differ(void) +{ + git_diff_options opts = {0}; + git_diff_list *diff_i2t = NULL, *diff_w2i = NULL; + diff_expects exp; + char *pathspec = "staged_changes_modified_file"; + git_tree *tree; + + /* For this file, + * - head->index diff has 1 line of context, 1 line of diff + * - index->workdir diff has 2 lines of context, 1 line of diff + * but + * - head->workdir diff has 1 line of context, 2 lines of diff + * Let's make sure the right one is returned from each fn. + */ + + g_repo = cl_git_sandbox_init("status"); + + tree = resolve_commit_oid_to_tree(g_repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f"); + + opts.pathspec.strings = &pathspec; + opts.pathspec.count = 1; + + cl_git_pass(git_diff_index_to_tree(g_repo, &opts, tree, &diff_i2t)); + cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff_w2i)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff_i2t, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + cl_assert_equal_i(1, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(0, exp.file_dels); + cl_assert_equal_i(1, exp.file_mods); + cl_assert_equal_i(1, exp.hunks); + cl_assert_equal_i(2, exp.lines); + cl_assert_equal_i(1, exp.line_ctxt); + cl_assert_equal_i(1, exp.line_adds); + cl_assert_equal_i(0, exp.line_dels); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff_w2i, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + cl_assert_equal_i(1, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(0, exp.file_dels); + cl_assert_equal_i(1, exp.file_mods); + cl_assert_equal_i(1, exp.hunks); + cl_assert_equal_i(3, exp.lines); + cl_assert_equal_i(2, exp.line_ctxt); + cl_assert_equal_i(1, exp.line_adds); + cl_assert_equal_i(0, exp.line_dels); + + cl_git_pass(git_diff_merge(diff_i2t, diff_w2i)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff_i2t, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + cl_assert_equal_i(1, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(0, exp.file_dels); + cl_assert_equal_i(1, exp.file_mods); + cl_assert_equal_i(1, exp.hunks); + cl_assert_equal_i(3, exp.lines); + cl_assert_equal_i(1, exp.line_ctxt); + cl_assert_equal_i(2, exp.line_adds); + cl_assert_equal_i(0, exp.line_dels); + + git_diff_list_free(diff_i2t); + git_diff_list_free(diff_w2i); +} + +void test_diff_workdir__eof_newline_changes(void) +{ + git_diff_options opts = {0}; + git_diff_list *diff = NULL; + diff_expects exp; + char *pathspec = "current_file"; + + g_repo = cl_git_sandbox_init("status"); + + opts.pathspec.strings = &pathspec; + opts.pathspec.count = 1; + + cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + cl_assert_equal_i(0, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(0, exp.file_dels); + cl_assert_equal_i(0, exp.file_mods); + cl_assert_equal_i(0, exp.hunks); + cl_assert_equal_i(0, exp.lines); + cl_assert_equal_i(0, exp.line_ctxt); + cl_assert_equal_i(0, exp.line_adds); + cl_assert_equal_i(0, exp.line_dels); + + git_diff_list_free(diff); + + cl_git_append2file("status/current_file", "\n"); + + cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + cl_assert_equal_i(1, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(0, exp.file_dels); + cl_assert_equal_i(1, exp.file_mods); + cl_assert_equal_i(1, exp.hunks); + cl_assert_equal_i(2, exp.lines); + cl_assert_equal_i(1, exp.line_ctxt); + cl_assert_equal_i(1, exp.line_adds); + cl_assert_equal_i(0, exp.line_dels); + + git_diff_list_free(diff); + + cl_git_rewritefile("status/current_file", "current_file"); + + cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + cl_assert_equal_i(1, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(0, exp.file_dels); + cl_assert_equal_i(1, exp.file_mods); + cl_assert_equal_i(1, exp.hunks); + cl_assert_equal_i(3, exp.lines); + cl_assert_equal_i(0, exp.line_ctxt); + cl_assert_equal_i(1, exp.line_adds); + cl_assert_equal_i(2, exp.line_dels); + + git_diff_list_free(diff); +} + /* PREPARATION OF TEST DATA * * Since there is no command line equivalent of git_diff_workdir_to_tree, diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c index 3436f8d1e..a535d6815 100644 --- a/tests-clar/index/tests.c +++ b/tests-clar/index/tests.c @@ -33,7 +33,7 @@ static void copy_file(const char *src, const char *dst) cl_git_pass(git_futils_readbuffer(&source_buf, src)); - dst_fd = git_futils_creat_withpath(dst, 0777, 0666); + dst_fd = git_futils_creat_withpath(dst, 0777, 0666); //-V536 if (dst_fd < 0) goto cleanup; diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c index 8cee7ce08..e66ea118f 100644 --- a/tests-clar/network/remotelocal.c +++ b/tests-clar/network/remotelocal.c @@ -107,7 +107,7 @@ void test_network_remotelocal__retrieve_advertised_references(void) cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); - cl_assert(how_many_refs == 14); /* 1 HEAD + 6 heads + 1 lightweight tag + 3 annotated tags + 3 peeled target */ + cl_assert_equal_i(how_many_refs, 20); } void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void) @@ -121,7 +121,7 @@ void test_network_remotelocal__retrieve_advertised_references_from_spaced_reposi cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); - cl_assert(how_many_refs == 14); /* 1 HEAD + 6 heads + 1 lightweight tag + 3 annotated tags + 3 peeled target */ + cl_assert_equal_i(how_many_refs, 20); git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */ remote = NULL; diff --git a/tests-clar/object/tree/write.c b/tests-clar/object/tree/write.c index 3911f6f0e..e6dc549a5 100644 --- a/tests-clar/object/tree/write.c +++ b/tests-clar/object/tree/write.c @@ -63,14 +63,14 @@ void test_object_tree_write__subtree(void) //create subtree cl_git_pass(git_treebuilder_create(&builder, NULL)); - cl_git_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644)); + cl_git_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644)); //-V536 cl_git_pass(git_treebuilder_write(&subtree_id, g_repo, builder)); git_treebuilder_free(builder); // create parent tree cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); cl_git_pass(git_treebuilder_create(&builder, tree)); - cl_git_pass(git_treebuilder_insert(NULL,builder,"new",&subtree_id,040000)); + cl_git_pass(git_treebuilder_insert(NULL,builder,"new",&subtree_id,040000)); //-V536 cl_git_pass(git_treebuilder_write(&id_hiearar, g_repo, builder)); git_treebuilder_free(builder); git_tree_free(tree); diff --git a/tests-clar/refs/branches/listall.c b/tests-clar/refs/branches/listall.c index 0a5634fb4..77f8270fb 100644 --- a/tests-clar/refs/branches/listall.c +++ b/tests-clar/refs/branches/listall.c @@ -30,22 +30,22 @@ static void assert_retrieval(unsigned int flags, unsigned int expected_count) { cl_git_pass(git_branch_list(&branch_list, repo, flags)); - cl_assert_equal_i(expected_count, branch_list.count); + cl_assert_equal_i(branch_list.count, expected_count); } void test_refs_branches_listall__retrieve_all_branches(void) { - assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 6 + 1); + assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 9); } void test_refs_branches_listall__retrieve_remote_branches(void) { - assert_retrieval(GIT_BRANCH_REMOTE, 1); + assert_retrieval(GIT_BRANCH_REMOTE, 2); } void test_refs_branches_listall__retrieve_local_branches(void) { - assert_retrieval(GIT_BRANCH_LOCAL, 6); + assert_retrieval(GIT_BRANCH_LOCAL, 7); } static void assert_branch_list_contains(git_strarray *branches, const char* expected_branch_name) @@ -72,7 +72,7 @@ void test_refs_branches_listall__retrieve_remote_symbolic_HEAD_when_present(void cl_git_pass(git_branch_list(&branch_list, repo, GIT_BRANCH_REMOTE)); - cl_assert_equal_i(2, branch_list.count); - assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/HEAD"); - assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/master"); + cl_assert_equal_i(3, branch_list.count); + assert_branch_list_contains(&branch_list, "remotes/nulltoken/HEAD"); + assert_branch_list_contains(&branch_list, "remotes/nulltoken/master"); } diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c new file mode 100644 index 000000000..fda99e9da --- /dev/null +++ b/tests-clar/refs/revparse.c @@ -0,0 +1,174 @@ +#include "clar_libgit2.h" + +#include "git2/revparse.h" + +static git_repository *g_repo; +static git_object *g_obj; +static char g_orig_tz[16] = {0}; + + + +/* Helpers */ +static void test_object(const char *spec, const char *expected_oid) +{ + char objstr[64] = {0}; + + cl_git_pass(git_revparse_single(&g_obj, g_repo, spec)); + git_oid_fmt(objstr, git_object_id(g_obj)); + cl_assert_equal_s(objstr, expected_oid); + + git_object_free(g_obj); + g_obj = NULL; +} + + +void test_refs_revparse__initialize(void) +{ + char *tz = cl_getenv("TZ"); + if (tz) + strcpy(g_orig_tz, tz); + cl_setenv("TZ", "UTC"); + g_repo = cl_git_sandbox_init("testrepo.git"); +} + +void test_refs_revparse__cleanup(void) +{ + cl_git_sandbox_cleanup(); + g_obj = NULL; + cl_setenv("TZ", g_orig_tz); +} + + +void test_refs_revparse__nonexistant_object(void) +{ + cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't exist")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't exist^1")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't exist~2")); +} + +void test_refs_revparse__shas(void) +{ + test_object("c47800c7266a2be04c571c04d5a6614691ea99bd", "c47800c7266a2be04c571c04d5a6614691ea99bd"); + test_object("c47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd"); +} + +void test_refs_revparse__head(void) +{ + test_object("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); +} + +void test_refs_revparse__full_refs(void) +{ + test_object("refs/heads/master", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("refs/heads/test", "e90810b8df3e80c413d903f631643c716887138d"); + test_object("refs/tags/test", "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); +} + +void test_refs_revparse__partial_refs(void) +{ + test_object("point_to_blob", "1385f264afb75a56a5bec74243be9b367ba4ca08"); + test_object("packed-test", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"); + test_object("br2", "a4a7dce85cf63874e984719f4fdd239f5145052f"); +} + +void test_refs_revparse__describe_output(void) +{ + test_object("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd"); + test_object("not-good", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); +} + +void test_refs_revparse__nth_parent(void) +{ + test_object("be3563a^1", "9fd738e8f7967c078dceed8190330fc8648ee56a"); + test_object("be3563a^", "9fd738e8f7967c078dceed8190330fc8648ee56a"); + test_object("be3563a^2", "c47800c7266a2be04c571c04d5a6614691ea99bd"); + test_object("be3563a^1^1", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"); + test_object("be3563a^2^1", "5b5b025afb0b4c913b4c338a42934a3863bf3644"); + test_object("be3563a^0", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); +} + +void test_refs_revparse__not_tag(void) +{ + test_object("point_to_blob^{}", "1385f264afb75a56a5bec74243be9b367ba4ca08"); + test_object("wrapped_tag^{}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); +} + +void test_refs_revparse__to_type(void) +{ + test_object("wrapped_tag^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("wrapped_tag^{tree}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"); + test_object("point_to_blob^{blob}", "1385f264afb75a56a5bec74243be9b367ba4ca08"); + + cl_git_fail(git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}")); +} + +void test_refs_revparse__linear_history(void) +{ + test_object("master~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("master~1", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("master~2", "9fd738e8f7967c078dceed8190330fc8648ee56a"); + test_object("master~1~1", "9fd738e8f7967c078dceed8190330fc8648ee56a"); +} + +void test_refs_revparse__chaining(void) +{ + test_object("master~1^1", "9fd738e8f7967c078dceed8190330fc8648ee56a"); + test_object("master~1^2", "c47800c7266a2be04c571c04d5a6614691ea99bd"); + test_object("master^1^2~1", "5b5b025afb0b4c913b4c338a42934a3863bf3644"); + test_object("master^1^1^1^1^1", "8496071c1b46c854b31185ea97743be6a8774479"); +} + +void test_refs_revparse__reflog(void) +{ + cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-xyz}")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-0}")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{1000}")); + + test_object("@{-2}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("@{-1}", "a4a7dce85cf63874e984719f4fdd239f5145052f"); + test_object("master@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("master@{upstream}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("master@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); +} + +void test_refs_revparse__revwalk(void) +{ + cl_git_fail(git_revparse_single(&g_obj, g_repo, "master^{/not found in any commit}")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, "master^{/merge}")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, "master^{/((}")); + + test_object("master^{/anoth}", "5b5b025afb0b4c913b4c338a42934a3863bf3644"); + test_object("master^{/Merge}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("br2^{/Merge}", "a4a7dce85cf63874e984719f4fdd239f5145052f"); + test_object("master^{/fo.rth}", "9fd738e8f7967c078dceed8190330fc8648ee56a"); +} + +void test_refs_revparse__date(void) +{ + test_object("HEAD@{10 years ago}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("HEAD@{1 second}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("master@{2012-4-30 10:23:20 -0800}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("master@{2012-4-30 18:24 -0800}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("master@{2012-4-30 23:24 -0300}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + + /* Core git gives a65fedf, because they don't take time zones into account. */ + test_object("master@{1335806640}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); +} + +void test_refs_revparse__colon(void) +{ + cl_git_fail(git_revparse_single(&g_obj, g_repo, ":/")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, ":/not found in any commit")); + cl_git_fail(git_revparse_single(&g_obj, g_repo, ":2:README")); + + test_object("subtrees:ab/4.txt", "d6c93164c249c8000205dd4ec5cbca1b516d487f"); + test_object("subtrees:ab/de/fgh/1.txt", "1f67fc4386b2d171e0d21be1c447e12660561f9b"); + test_object("master:README", "a8233120f6ad708f843d861ce2b7228ec4e3dec6"); + test_object("master:new.txt", "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"); + test_object(":/Merge", "a4a7dce85cf63874e984719f4fdd239f5145052f"); + test_object(":/one", "c47800c7266a2be04c571c04d5a6614691ea99bd"); + test_object(":/packed commit t", "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9"); +} diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c index af54b2266..2e70c511e 100644 --- a/tests-clar/repo/init.c +++ b/tests-clar/repo/init.c @@ -166,14 +166,14 @@ void test_repo_init__additional_templates(void) git_buf_free(&path); } -static void assert_config_entry_on_init(const char *config_key, int expected_value) +static void assert_config_entry_on_init_bytype(const char *config_key, int expected_value, bool is_bare) { git_config *config; int current_value; cl_set_cleanup(&cleanup_repository, "config_entry"); - cl_git_pass(git_repository_init(&_repo, "config_entry/test.git", 1)); + cl_git_pass(git_repository_init(&_repo, "config_entry/test.git", is_bare)); git_repository_config(&config, _repo); if (expected_value >= 0) { @@ -189,6 +189,14 @@ static void assert_config_entry_on_init(const char *config_key, int expected_val git_config_free(config); } +static void assert_config_entry_on_init(const char *config_key, int expected_value) +{ + assert_config_entry_on_init_bytype(config_key, expected_value, true); + git_repository_free(_repo); + + assert_config_entry_on_init_bytype(config_key, expected_value, false); +} + void test_repo_init__detect_filemode(void) { #ifdef GIT_WIN32 @@ -233,3 +241,9 @@ void test_repo_init__reinit_doesnot_overwrite_ignorecase(void) git_config_free(config); } + +void test_repo_init__sets_logAllRefUpdates_according_to_type_of_repository(void) +{ + assert_config_entry_on_init_bytype("core.logallrefupdates", GIT_ENOTFOUND, true); + assert_config_entry_on_init_bytype("core.logallrefupdates", true, false); +} diff --git a/tests-clar/reset/mixed.c b/tests-clar/reset/mixed.c new file mode 100644 index 000000000..7cfff65d4 --- /dev/null +++ b/tests-clar/reset/mixed.c @@ -0,0 +1,47 @@ +#include "clar_libgit2.h" +#include "posix.h" +#include "reset_helpers.h" +#include "path.h" + +static git_repository *repo; +static git_object *target; + +void test_reset_mixed__initialize(void) +{ + repo = cl_git_sandbox_init("attr"); + target = NULL; +} + +void test_reset_mixed__cleanup(void) +{ + git_object_free(target); + cl_git_sandbox_cleanup(); +} + +void test_reset_mixed__cannot_reset_in_a_bare_repository(void) +{ + git_repository *bare; + + cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git"))); + cl_assert(git_repository_is_bare(bare) == true); + + retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO); + + cl_git_fail(git_reset(bare, target, GIT_RESET_MIXED)); + + git_repository_free(bare); +} + +void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void) +{ + unsigned int status; + + cl_git_pass(git_status_file(&status, repo, "macro_bad")); + cl_assert(status == GIT_STATUS_CURRENT); + retrieve_target_from_oid(&target, repo, "605812ab7fe421fdd325a935d35cb06a9234a7d7"); + + cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED)); + + cl_git_pass(git_status_file(&status, repo, "macro_bad")); + cl_assert(status == GIT_STATUS_WT_NEW); +} diff --git a/tests-clar/reset/reset_helpers.c b/tests-clar/reset/reset_helpers.c new file mode 100644 index 000000000..17edca4e9 --- /dev/null +++ b/tests-clar/reset/reset_helpers.c @@ -0,0 +1,10 @@ +#include "clar_libgit2.h" +#include "reset_helpers.h" + +void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha) +{ + git_oid oid; + + cl_git_pass(git_oid_fromstr(&oid, sha)); + cl_git_pass(git_object_lookup(object_out, repo, &oid, GIT_OBJ_ANY)); +} diff --git a/tests-clar/reset/reset_helpers.h b/tests-clar/reset/reset_helpers.h new file mode 100644 index 000000000..5dbe9d2c7 --- /dev/null +++ b/tests-clar/reset/reset_helpers.h @@ -0,0 +1,6 @@ +#include "common.h" + +#define KNOWN_COMMIT_IN_BARE_REPO "e90810b8df3e80c413d903f631643c716887138d" +#define KNOWN_COMMIT_IN_ATTR_REPO "217878ab49e1314388ea2e32dc6fdb58a1b969e0" + +extern void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha); diff --git a/tests-clar/reset/soft.c b/tests-clar/reset/soft.c new file mode 100644 index 000000000..3200c1591 --- /dev/null +++ b/tests-clar/reset/soft.c @@ -0,0 +1,102 @@ +#include "clar_libgit2.h" +#include "reset_helpers.h" + +static git_repository *repo; +static git_object *target; + +void test_reset_soft__initialize(void) +{ + repo = cl_git_sandbox_init("testrepo.git"); +} + +void test_reset_soft__cleanup(void) +{ + git_object_free(target); + cl_git_sandbox_cleanup(); +} + +static void assert_reset_soft(bool should_be_detached) +{ + git_oid oid; + + cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD")); + cl_git_fail(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO)); + + retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO); + + cl_assert(git_repository_head_detached(repo) == should_be_detached); + + cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); + + cl_assert(git_repository_head_detached(repo) == should_be_detached); + + cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD")); + cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO)); +} + +void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(void) +{ + assert_reset_soft(false); +} + +static void detach_head(void) +{ + git_reference *head; + git_oid oid; + + cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD")); + + cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", &oid, true)); + git_reference_free(head); +} + +void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void) +{ + detach_head(); + + assert_reset_soft(true); +} + +void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_change_the_target_of_the_Head(void) +{ + git_oid oid; + char raw_head_oid[GIT_OID_HEXSZ + 1]; + + cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD")); + git_oid_fmt(raw_head_oid, &oid); + raw_head_oid[GIT_OID_HEXSZ] = '\0'; + + retrieve_target_from_oid(&target, repo, raw_head_oid); + + cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); + + cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD")); + cl_git_pass(git_oid_streq(&oid, raw_head_oid)); +} + +void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void) +{ + git_oid oid; + + /* b25fa35 is a tag, pointing to another tag which points to commit e90810b */ + retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); + + cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); + + cl_assert(git_repository_head_detached(repo) == false); + cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD")); + cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO)); +} + +void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void) +{ + /* 53fc32d is the tree of commit e90810b */ + retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016"); + + cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT)); + git_object_free(target); + + /* 521d87c is an annotated tag pointing to a blob */ + retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91"); + cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT)); +} diff --git a/tests-clar/resources/filemodes/.gitted/HEAD b/tests-clar/resources/filemodes/.gitted/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests-clar/resources/filemodes/.gitted/config b/tests-clar/resources/filemodes/.gitted/config new file mode 100644 index 000000000..af107929f --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true diff --git a/tests-clar/resources/filemodes/.gitted/description b/tests-clar/resources/filemodes/.gitted/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests-clar/resources/filemodes/.gitted/hooks/commit-msg.sample b/tests-clar/resources/filemodes/.gitted/hooks/commit-msg.sample new file mode 100755 index 000000000..b58d1184a --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/tests-clar/resources/filemodes/.gitted/index b/tests-clar/resources/filemodes/.gitted/index Binary files differnew file mode 100644 index 000000000..b1b175a9b --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/index diff --git a/tests-clar/resources/filemodes/.gitted/info/exclude b/tests-clar/resources/filemodes/.gitted/info/exclude new file mode 100644 index 000000000..a5196d1be --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/tests-clar/resources/filemodes/.gitted/logs/HEAD b/tests-clar/resources/filemodes/.gitted/logs/HEAD new file mode 100644 index 000000000..1cb6a84c1 --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/logs/HEAD @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 9962c8453ba6f0cf8dac7c5dcc2fa2897fa9964a Russell Belfer <rb@github.com> 1338847682 -0700 commit (initial): Initial commit of test data diff --git a/tests-clar/resources/filemodes/.gitted/logs/refs/heads/master b/tests-clar/resources/filemodes/.gitted/logs/refs/heads/master new file mode 100644 index 000000000..1cb6a84c1 --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/logs/refs/heads/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 9962c8453ba6f0cf8dac7c5dcc2fa2897fa9964a Russell Belfer <rb@github.com> 1338847682 -0700 commit (initial): Initial commit of test data diff --git a/tests-clar/resources/filemodes/.gitted/objects/99/62c8453ba6f0cf8dac7c5dcc2fa2897fa9964a b/tests-clar/resources/filemodes/.gitted/objects/99/62c8453ba6f0cf8dac7c5dcc2fa2897fa9964a Binary files differnew file mode 100644 index 000000000..cbd2b557a --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/objects/99/62c8453ba6f0cf8dac7c5dcc2fa2897fa9964a diff --git a/tests-clar/resources/filemodes/.gitted/objects/a5/c5dd0fc6c313159a69b1d19d7f61a9f978e8f1 b/tests-clar/resources/filemodes/.gitted/objects/a5/c5dd0fc6c313159a69b1d19d7f61a9f978e8f1 Binary files differnew file mode 100644 index 000000000..a9eaf2cba --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/objects/a5/c5dd0fc6c313159a69b1d19d7f61a9f978e8f1 diff --git a/tests-clar/resources/filemodes/.gitted/objects/e7/48d196331bcb20267eaaee4ff3326cb73b8182 b/tests-clar/resources/filemodes/.gitted/objects/e7/48d196331bcb20267eaaee4ff3326cb73b8182 Binary files differnew file mode 100644 index 000000000..98066029c --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/objects/e7/48d196331bcb20267eaaee4ff3326cb73b8182 diff --git a/tests-clar/resources/filemodes/.gitted/refs/heads/master b/tests-clar/resources/filemodes/.gitted/refs/heads/master new file mode 100644 index 000000000..9822d2d3f --- /dev/null +++ b/tests-clar/resources/filemodes/.gitted/refs/heads/master @@ -0,0 +1 @@ +9962c8453ba6f0cf8dac7c5dcc2fa2897fa9964a diff --git a/tests-clar/resources/filemodes/exec_off b/tests-clar/resources/filemodes/exec_off new file mode 100644 index 000000000..a5c5dd0fc --- /dev/null +++ b/tests-clar/resources/filemodes/exec_off @@ -0,0 +1 @@ +Howdy diff --git a/tests-clar/resources/filemodes/exec_off2on_staged b/tests-clar/resources/filemodes/exec_off2on_staged new file mode 100755 index 000000000..a5c5dd0fc --- /dev/null +++ b/tests-clar/resources/filemodes/exec_off2on_staged @@ -0,0 +1 @@ +Howdy diff --git a/tests-clar/resources/filemodes/exec_off2on_workdir b/tests-clar/resources/filemodes/exec_off2on_workdir new file mode 100755 index 000000000..a5c5dd0fc --- /dev/null +++ b/tests-clar/resources/filemodes/exec_off2on_workdir @@ -0,0 +1 @@ +Howdy diff --git a/tests-clar/resources/filemodes/exec_off_untracked b/tests-clar/resources/filemodes/exec_off_untracked new file mode 100644 index 000000000..a5c5dd0fc --- /dev/null +++ b/tests-clar/resources/filemodes/exec_off_untracked @@ -0,0 +1 @@ +Howdy diff --git a/tests-clar/resources/filemodes/exec_on b/tests-clar/resources/filemodes/exec_on new file mode 100755 index 000000000..a5c5dd0fc --- /dev/null +++ b/tests-clar/resources/filemodes/exec_on @@ -0,0 +1 @@ +Howdy diff --git a/tests-clar/resources/filemodes/exec_on2off_staged b/tests-clar/resources/filemodes/exec_on2off_staged new file mode 100644 index 000000000..a5c5dd0fc --- /dev/null +++ b/tests-clar/resources/filemodes/exec_on2off_staged @@ -0,0 +1 @@ +Howdy diff --git a/tests-clar/resources/filemodes/exec_on2off_workdir b/tests-clar/resources/filemodes/exec_on2off_workdir new file mode 100644 index 000000000..a5c5dd0fc --- /dev/null +++ b/tests-clar/resources/filemodes/exec_on2off_workdir @@ -0,0 +1 @@ +Howdy diff --git a/tests-clar/resources/filemodes/exec_on_untracked b/tests-clar/resources/filemodes/exec_on_untracked new file mode 100755 index 000000000..a5c5dd0fc --- /dev/null +++ b/tests-clar/resources/filemodes/exec_on_untracked @@ -0,0 +1 @@ +Howdy diff --git a/tests-clar/resources/testrepo.git/config b/tests-clar/resources/testrepo.git/config index 1a5aacdfa..b4fdac6c2 100644 --- a/tests-clar/resources/testrepo.git/config +++ b/tests-clar/resources/testrepo.git/config @@ -6,3 +6,7 @@ [remote "test"] url = git://github.com/libgit2/libgit2 fetch = +refs/heads/*:refs/remotes/test/* + +[branch "master"] + remote = test + merge = refs/heads/master diff --git a/tests-clar/resources/testrepo.git/logs/HEAD b/tests-clar/resources/testrepo.git/logs/HEAD new file mode 100644 index 000000000..b16c9b313 --- /dev/null +++ b/tests-clar/resources/testrepo.git/logs/HEAD @@ -0,0 +1,5 @@ +0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806563 -0700 clone: from /Users/ben/src/libgit2/tests/resources/testrepo.git +be3563ae3f795b2b4353bcce3a527ad0a4f7f644 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806603 -0900 commit: +a65fedf39aefe402d3bb6e24df4d4f5fe4547750 c47800c7266a2be04c571c04d5a6614691ea99bd Ben Straub <bstraub@github.com> 1335806608 -0900 checkout: moving from master to br2 +c47800c7266a2be04c571c04d5a6614691ea99bd a4a7dce85cf63874e984719f4fdd239f5145052f Ben Straub <bstraub@github.com> 1335806617 -0900 commit: checking in +a4a7dce85cf63874e984719f4fdd239f5145052f a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806621 -0900 checkout: moving from br2 to master diff --git a/tests-clar/resources/testrepo.git/logs/refs/heads/br2 b/tests-clar/resources/testrepo.git/logs/refs/heads/br2 new file mode 100644 index 000000000..4e27f6b8d --- /dev/null +++ b/tests-clar/resources/testrepo.git/logs/refs/heads/br2 @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 c47800c7266a2be04c571c04d5a6614691ea99bd Ben Straub <bstraub@github.com> 1335806608 -0700 branch: Created from refs/remotes/origin/br2 +a4a7dce85cf63874e984719f4fdd239f5145052f a4a7dce85cf63874e984719f4fdd239f5145052f Ben Straub <bstraub@github.com> 1335806617 -0700 commit: checking in diff --git a/tests-clar/resources/testrepo.git/logs/refs/heads/master b/tests-clar/resources/testrepo.git/logs/refs/heads/master new file mode 100644 index 000000000..e1c729a45 --- /dev/null +++ b/tests-clar/resources/testrepo.git/logs/refs/heads/master @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806563 -0800 clone: from /Users/ben/src/libgit2/tests/resources/testrepo.git +be3563ae3f795b2b4353bcce3a527ad0a4f7f644 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1335806603 -0800 commit: checking in diff --git a/tests-clar/resources/testrepo.git/logs/refs/heads/not-good b/tests-clar/resources/testrepo.git/logs/refs/heads/not-good new file mode 100644 index 000000000..bfbeacb8a --- /dev/null +++ b/tests-clar/resources/testrepo.git/logs/refs/heads/not-good @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub <bstraub@github.com> 1336761944 -0700 branch: Created from master diff --git a/tests-clar/resources/testrepo.git/logs/refs/remotes/origin/HEAD b/tests-clar/resources/testrepo.git/logs/refs/remotes/origin/HEAD new file mode 100644 index 000000000..f1aac6d0f --- /dev/null +++ b/tests-clar/resources/testrepo.git/logs/refs/remotes/origin/HEAD @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub <bstraub@github.com> 1335806563 -0700 clone: from /Users/ben/src/libgit2/tests/resources/testrepo.git diff --git a/tests-clar/resources/testrepo.git/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe b/tests-clar/resources/testrepo.git/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe new file mode 100644 index 000000000..71019a636 --- /dev/null +++ b/tests-clar/resources/testrepo.git/objects/84/9a5e34a26815e821f865b8479f5815a47af0fe @@ -0,0 +1,2 @@ +xM F]s41x(IKݽ/_P@!8)es + N&FGSƄh{+CZzvF7Z-kx\[P8GK/^l>.4
\ No newline at end of file diff --git a/tests-clar/resources/testrepo.git/refs/heads/not-good b/tests-clar/resources/testrepo.git/refs/heads/not-good new file mode 100644 index 000000000..3d8f0a402 --- /dev/null +++ b/tests-clar/resources/testrepo.git/refs/heads/not-good @@ -0,0 +1 @@ +a65fedf39aefe402d3bb6e24df4d4f5fe4547750 diff --git a/tests-clar/resources/testrepo.git/refs/remotes/test/master b/tests-clar/resources/testrepo.git/refs/remotes/test/master new file mode 100644 index 000000000..9536ad89c --- /dev/null +++ b/tests-clar/resources/testrepo.git/refs/remotes/test/master @@ -0,0 +1 @@ +be3563ae3f795b2b4353bcce3a527ad0a4f7f644 diff --git a/tests-clar/resources/testrepo.git/refs/tags/hard_tag b/tests-clar/resources/testrepo.git/refs/tags/hard_tag new file mode 100644 index 000000000..59ce65649 --- /dev/null +++ b/tests-clar/resources/testrepo.git/refs/tags/hard_tag @@ -0,0 +1 @@ +849a5e34a26815e821f865b8479f5815a47af0fe diff --git a/tests-clar/resources/testrepo.git/refs/tags/wrapped_tag b/tests-clar/resources/testrepo.git/refs/tags/wrapped_tag new file mode 100644 index 000000000..59ce65649 --- /dev/null +++ b/tests-clar/resources/testrepo.git/refs/tags/wrapped_tag @@ -0,0 +1 @@ +849a5e34a26815e821f865b8479f5815a47af0fe diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c index 369b25bda..0384306c1 100644 --- a/tests-clar/status/ignore.c +++ b/tests-clar/status/ignore.c @@ -131,3 +131,17 @@ void test_status_ignore__empty_repo_with_gitignore_rewrite(void) cl_assert(ignored); } +void test_status_ignore__ignore_pattern_contains_space(void) +{ + unsigned int flags; + const mode_t mode = 0777; + + g_repo = cl_git_sandbox_init("empty_standard_repo"); + cl_git_rewritefile("empty_standard_repo/.gitignore", "foo bar.txt\n"); + + cl_git_pass(git_futils_mkdir_r("empty_standard_repo/foo", NULL, mode)); + cl_git_mkfile("empty_standard_repo/foo/look-ma.txt", "I'm not going to be ignored!"); + + cl_git_pass(git_status_file(&flags, g_repo, "foo/look-ma.txt")); + cl_assert(flags == GIT_STATUS_WT_NEW); +} diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c index b3ebdb781..3670b72a8 100644 --- a/tests-clar/status/worktree.c +++ b/tests-clar/status/worktree.c @@ -581,3 +581,69 @@ void test_status_worktree__space_in_filename(void) git_index_free(index); git_repository_free(repo); } + +static const char *filemode_paths[] = { + "exec_off", + "exec_off2on_staged", + "exec_off2on_workdir", + "exec_off_untracked", + "exec_on", + "exec_on2off_staged", + "exec_on2off_workdir", + "exec_on_untracked", +}; + +static unsigned int filemode_statuses[] = { + GIT_STATUS_CURRENT, + GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_WT_MODIFIED, + GIT_STATUS_WT_NEW, + GIT_STATUS_CURRENT, + GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_WT_MODIFIED, + GIT_STATUS_WT_NEW +}; + +static const size_t filemode_count = 8; + +void test_status_worktree__filemode_changes(void) +{ + git_repository *repo = cl_git_sandbox_init("filemodes"); + status_entry_counts counts; + git_status_options opts; + git_config *cfg; + + /* overwrite stored filemode with platform appropriate value */ + cl_git_pass(git_repository_config(&cfg, repo)); + if (cl_is_chmod_supported()) + cl_git_pass(git_config_set_bool(cfg, "core.filemode", true)); + else { + unsigned int i; + cl_git_pass(git_config_set_bool(cfg, "core.filemode", false)); + + /* won't trust filesystem mode diffs, so these will appear unchanged */ + for (i = 0; i < filemode_count; ++i) + if (filemode_statuses[i] == GIT_STATUS_WT_MODIFIED) + filemode_statuses[i] = GIT_STATUS_CURRENT; + } + + memset(&opts, 0, sizeof(opts)); + opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | + GIT_STATUS_OPT_INCLUDE_IGNORED | + GIT_STATUS_OPT_INCLUDE_UNMODIFIED; + + memset(&counts, 0, sizeof(counts)); + counts.expected_entry_count = filemode_count; + counts.expected_paths = filemode_paths; + counts.expected_statuses = filemode_statuses; + + cl_git_pass( + git_status_foreach_ext(repo, &opts, cb_status__normal, &counts) + ); + + cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); + cl_assert_equal_i(0, counts.wrong_status_flags_count); + cl_assert_equal_i(0, counts.wrong_sorted_path); + + git_config_free(cfg); +} |