diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/clar_libgit2.c | 5 | ||||
-rw-r--r-- | tests/clar_libgit2.h | 1 | ||||
-rw-r--r-- | tests/diff/rename.c | 54 |
3 files changed, 41 insertions, 19 deletions
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c index 10f37ad5c..a8a8ba6ab 100644 --- a/tests/clar_libgit2.c +++ b/tests/clar_libgit2.c @@ -53,6 +53,11 @@ void cl_git_rewritefile(const char *path, const char *content) cl_git_write2file(path, content, 0, O_WRONLY | O_CREAT | O_TRUNC, 0644); } +void cl_git_rmfile(const char *filename) +{ + cl_must_pass(p_unlink(filename)); +} + #ifdef GIT_WIN32 #include "win32/utf-conv.h" diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h index f51554293..e1d62c820 100644 --- a/tests/clar_libgit2.h +++ b/tests/clar_libgit2.h @@ -112,6 +112,7 @@ 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 *path, const char *data, size_t datalen, int flags, unsigned int mode); +void cl_git_rmfile(const char *filename); bool cl_toggle_filemode(const char *filename); bool cl_is_chmod_supported(void); diff --git a/tests/diff/rename.c b/tests/diff/rename.c index 4bc3eb54c..28e0bf149 100644 --- a/tests/diff/rename.c +++ b/tests/diff/rename.c @@ -381,37 +381,53 @@ void test_diff_rename__not_exact_match(void) git_tree_free(new_tree); } -void test_diff_rename__handles_small_files(void) +void test_diff_rename__test_small_files(void) { - const char *tree_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a"; git_index *index; - git_tree *tree; + git_reference *head_reference; + git_commit *head_commit; + git_tree *head_tree; + git_tree *commit_tree; + git_signature *signature; git_diff *diff; - git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT; - git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT; + git_oid oid; + const git_diff_delta *delta; + git_diff_options diff_options = GIT_DIFF_OPTIONS_INIT; + git_diff_find_options find_options = GIT_DIFF_FIND_OPTIONS_INIT; cl_git_pass(git_repository_index(&index, g_repo)); - tree = resolve_commit_oid_to_tree(g_repo, tree_sha); + cl_git_mkfile("renames/small.txt", "Hello World!\n"); + cl_git_pass(git_index_add_bypath(index, "small.txt")); - cl_git_rewritefile("renames/songof7cities.txt", "single line\n"); - cl_git_pass(git_index_add_bypath(index, "songof7cities.txt")); + cl_git_pass(git_repository_head(&head_reference, g_repo)); + cl_git_pass(git_reference_peel((git_object**)&head_commit, head_reference, GIT_OBJ_COMMIT)); + cl_git_pass(git_commit_tree(&head_tree, head_commit)); + cl_git_pass(git_index_write_tree(&oid, index)); + cl_git_pass(git_tree_lookup(&commit_tree, g_repo, &oid)); + cl_git_pass(git_signature_new(&signature, "Rename", "rename@example.com", 1404157834, 0)); + cl_git_pass(git_commit_create(&oid, g_repo, "HEAD", signature, signature, NULL, "Test commit", commit_tree, 1, (const git_commit**)&head_commit)); - cl_git_rewritefile("renames/untimely.txt", "untimely\n"); - cl_git_pass(git_index_add_bypath(index, "untimely.txt")); + cl_git_mkfile("renames/copy.txt", "Hello World!\n"); + cl_git_rmfile("renames/small.txt"); - /* Tests that we can invoke find_similar on small files - * and that the GIT_EBUFS (too small) error code is not - * propagated to the caller. - */ - cl_git_pass(git_diff_tree_to_index(&diff, g_repo, tree, index, &diffopts)); + diff_options.flags = GIT_DIFF_INCLUDE_UNTRACKED; + cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, commit_tree, &diff_options)); + find_options.flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_FOR_UNTRACKED; + cl_git_pass(git_diff_find_similar(diff, &find_options)); - opts.flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES | - GIT_DIFF_FIND_AND_BREAK_REWRITES; - cl_git_pass(git_diff_find_similar(diff, &opts)); + cl_assert_equal_i(git_diff_num_deltas(diff), 1); + delta = git_diff_get_delta(diff, 0); + cl_assert_equal_i(delta->status, GIT_DELTA_RENAMED); + cl_assert_equal_s(delta->old_file.path, "small.txt"); + cl_assert_equal_s(delta->new_file.path, "copy.txt"); git_diff_free(diff); - git_tree_free(tree); + git_signature_free(signature); + git_tree_free(commit_tree); + git_tree_free(head_tree); + git_commit_free(head_commit); + git_reference_free(head_reference); git_index_free(index); } |