diff options
author | Russell Belfer <rb@github.com> | 2013-12-02 13:27:06 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-12-02 13:27:06 -0800 |
commit | 2123a17f83cc95adee4e7259d0686b07f074de4c (patch) | |
tree | b04541454e33323e77d1f3e58eee32e8abb3df16 /tests/diff/rename.c | |
parent | 14984af6cb9906746d2c64c5df7542ecd7406b16 (diff) | |
download | libgit2-2123a17f83cc95adee4e7259d0686b07f074de4c.tar.gz |
Fix bug making split deltas a COPIED targets
When FIND_COPIES is used in combination with BREAK_REWRITES for
rename detection, there was a bug where the split MODIFIED delta
was only used as a target for RENAME records and not for COPIED
records. This fixes that, converting the split into a pair of
DELETED and COPIED deltas when that circumstance arises.
Diffstat (limited to 'tests/diff/rename.c')
-rw-r--r-- | tests/diff/rename.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/diff/rename.c b/tests/diff/rename.c index 42bb65aa8..7f033936e 100644 --- a/tests/diff/rename.c +++ b/tests/diff/rename.c @@ -1284,3 +1284,52 @@ void test_diff_rename__rewrite_on_single_file(void) git_diff_free(diff); git_index_free(index); } + +void test_diff_rename__can_find_copy_to_split(void) +{ + git_buf c1 = GIT_BUF_INIT; + git_index *index; + git_tree *tree; + git_diff *diff; + git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT; + git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT; + diff_expects exp; + + cl_git_pass(git_futils_readbuffer(&c1, "renames/songof7cities.txt")); + cl_git_pass(git_futils_writebuffer(&c1, "renames/untimely.txt", 0, 0)); + + cl_git_pass( + git_revparse_single((git_object **)&tree, g_repo, "HEAD^{tree}")); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_read_tree(index, tree)); + cl_git_pass(git_index_add_bypath(index, "untimely.txt")); + + diffopts.flags = GIT_DIFF_INCLUDE_UNMODIFIED; + + cl_git_pass(git_diff_tree_to_index(&diff, g_repo, tree, index, &diffopts)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp)); + cl_assert_equal_i(4, exp.files); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNMODIFIED]); + + opts.flags = GIT_DIFF_FIND_ALL; + cl_git_pass(git_diff_find_similar(diff, &opts)); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp)); + cl_assert_equal_i(5, exp.files); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]); + cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNMODIFIED]); + + git_diff_free(diff); + git_tree_free(tree); + git_index_free(index); + + git_buf_free(&c1); +} |