diff options
author | Russell Belfer <rb@github.com> | 2013-12-02 13:30:05 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-12-02 13:30:05 -0800 |
commit | 97ad85b88d7a2f6d1c31a07de3c3c0b4b504d4ee (patch) | |
tree | 969ed56c8410d3f5f30145b3ce16335cb356075a /tests/diff | |
parent | 2123a17f83cc95adee4e7259d0686b07f074de4c (diff) | |
download | libgit2-97ad85b88d7a2f6d1c31a07de3c3c0b4b504d4ee.tar.gz |
Add GIT_DIFF_FIND_DELETE_UNMODIFIED flag
When doing copy detection, it is often necessary to include
UNMODIFIED records in the git_diff so they are available as source
records for GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED. Yet in the final
diff, often you will not want to have these UNMODIFIED records.
This adds a flag which marks these UNMODIFIED records for deletion
from the diff list so they will be removed after the rename detect
phase is over.
Diffstat (limited to 'tests/diff')
-rw-r--r-- | tests/diff/rename.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/diff/rename.c b/tests/diff/rename.c index 7f033936e..e081d616f 100644 --- a/tests/diff/rename.c +++ b/tests/diff/rename.c @@ -1333,3 +1333,51 @@ void test_diff_rename__can_find_copy_to_split(void) git_buf_free(&c1); } + +void test_diff_rename__can_delete_unmodified_deltas(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 | GIT_DIFF_FIND_DELETE_UNMODIFIED; + 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(2, exp.files); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]); + + git_diff_free(diff); + git_tree_free(tree); + git_index_free(index); + + git_buf_free(&c1); +} |