diff options
author | Russell Belfer <rb@github.com> | 2012-10-08 15:19:00 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-10-08 15:22:40 -0700 |
commit | 5d1308f25ff36d03f0a22451642cc0f2a931daae (patch) | |
tree | 1d9c581f1a2b756a35c95f15077630a9fac34a2c /tests-clar | |
parent | 71966e2f1bdfb75b7e57942d572ea089ce32e463 (diff) | |
download | libgit2-5d1308f25ff36d03f0a22451642cc0f2a931daae.tar.gz |
Add test for diffs with submodules and bug fixes
The adds a test for the submodule diff capabilities and then
fixes a few bugs with how the output is generated. It improves
the accuracy of OIDs in the diff delta object and makes the
submodule output more closely mirror the OIDs that will be used
by core git.
Diffstat (limited to 'tests-clar')
-rw-r--r-- | tests-clar/diff/workdir.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c index 916113178..e184c28b4 100644 --- a/tests-clar/diff/workdir.c +++ b/tests-clar/diff/workdir.c @@ -744,3 +744,77 @@ void test_diff_workdir__larger_hunks(void) git_tree_free(a); git_tree_free(b); } + +/* Set up a test that exercises this code. The easiest test using existing + * test data is probably to create a sandbox of submod2 and then run a + * git_diff_workdir_to_tree against tree + * 873585b94bdeabccea991ea5e3ec1a277895b698. As for what you should actually + * test, you can start by just checking that the number of lines of diff + * content matches the actual output of git diff. That will at least + * demonstrate that the submodule content is being used to generate somewhat + * comparable outputs. It is a test that would fail without this code and + * will succeed with it. + */ + +#include "../submodule/submodule_helpers.h" + +void test_diff_workdir__submodules(void) +{ + const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698"; + git_tree *a; + git_diff_options opts = {0}; + git_diff_list *diff = NULL; + diff_expects exp; + + g_repo = cl_git_sandbox_init("submod2"); + + cl_fixture_sandbox("submod2_target"); + p_rename("submod2_target/.gitted", "submod2_target/.git"); + + rewrite_gitmodules(git_repository_workdir(g_repo)); + p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git"); + + cl_fixture_cleanup("submod2_target"); + + a = resolve_commit_oid_to_tree(g_repo, a_commit); + + opts.flags = + GIT_DIFF_INCLUDE_UNTRACKED | + GIT_DIFF_RECURSE_UNTRACKED_DIRS | + GIT_DIFF_INCLUDE_UNTRACKED_CONTENT; + + cl_git_pass(git_diff_workdir_to_tree(g_repo, &opts, a, &diff)); + + /* diff_print(stderr, diff); */ + + /* essentially doing: git diff 873585b94bdeabccea991ea5e3ec1a277895b698 */ + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_foreach( + diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + /* the following differs from "git diff 873585" by one "untracked" file + * because the diff list includes the "not_submodule/" directory which + * is not displayed in the text diff. + */ + + cl_assert_equal_i(10, 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(0, exp.file_ignored); + cl_assert_equal_i(9, exp.file_untracked); + + /* the following numbers match "git diff 873585" exactly */ + + cl_assert_equal_i(9, exp.hunks); + + cl_assert_equal_i(33, exp.lines); + cl_assert_equal_i(2, exp.line_ctxt); + cl_assert_equal_i(30, exp.line_adds); + cl_assert_equal_i(1, exp.line_dels); + + git_diff_list_free(diff); + git_tree_free(a); +} |