diff options
author | Russell Belfer <rb@github.com> | 2013-06-30 10:22:31 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-07-10 23:15:03 +0400 |
commit | f9775a37aa4ed042839a6b2f9d8e0dfbd73a2f09 (patch) | |
tree | d4e0fde8c090bf7d301dfa673538dd17d9a77f96 /tests-clar/diff | |
parent | 2e3e273e33894bc1089cfc09d89bd2cb144b108d (diff) |
Add ignore_submodules to diff options
This adds correct support for an equivalent to --ignore-submodules
in diff, where an actual ignore value can be passed to diff to
override the per submodule settings in the configuration.
This required tweaking the constants for ignore values so that
zero would not be used and could represent an unset option to the
diff. This was an opportunity to move the submodule values into
include/git2/types.h and to rename the poorly named DEFAULT values
for ignore and update constants to RESET instead.
Now the GIT_DIFF_IGNORE_SUBMODULES flag is exactly the same as
setting the ignore_submodules option to GIT_SUBMODULE_IGNORE_ALL
(which is actually a minor change from the old behavior in that
submodules will now be treated as UNMODIFIED deltas instead of
being left out totally - if you set GIT_DIFF_INCLUDE_UNMODIFIED).
This includes tests for the various new settings.
Diffstat (limited to 'tests-clar/diff')
-rw-r--r-- | tests-clar/diff/submodules.c | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/tests-clar/diff/submodules.c b/tests-clar/diff/submodules.c index 4a40affb2..2e425bb11 100644 --- a/tests-clar/diff/submodules.c +++ b/tests-clar/diff/submodules.c @@ -49,7 +49,7 @@ static void check_diff_patches_at_line( cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d)); if (delta->status == GIT_DELTA_UNMODIFIED) { - clar__assert(expected[d] == NULL, file, line, "found UNMODIFIED delta where modified was expected", NULL, 1); + cl_assert_at_line(expected[d] == NULL, file, line); continue; } @@ -57,7 +57,7 @@ static void check_diff_patches_at_line( continue; if (expected[d] && !strcmp(expected[d], "<END>")) { cl_git_pass(git_diff_patch_to_str(&patch_text, patch)); - clar__assert(0, file, line, "expected end of deltas, but found more", patch_text, 1); + cl_assert_at_line(!strcmp(expected[d], "<END>"), file, line); } cl_git_pass(git_diff_patch_to_str(&patch_text, patch)); @@ -67,7 +67,7 @@ static void check_diff_patches_at_line( git__free(patch_text); } - clar__assert(expected[d] && !strcmp(expected[d], "<END>"), file, line, "found fewer deltas than expected", expected[d], 1); + cl_assert_at_line(expected[d] && !strcmp(expected[d], "<END>"), file, line); } #define check_diff_patches(diff, exp) \ @@ -382,3 +382,62 @@ void test_diff_submodules__invalid_cache(void) git_index_free(smindex); git_repository_free(smrepo); } + +void test_diff_submodules__diff_ignore_options(void) +{ + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_diff_list *diff = NULL; + static const char *expected_normal[] = { + "<SKIP>", /* .gitmodules */ + NULL, /* not-submodule */ + NULL, /* not */ + "diff --git a/sm_changed_file b/sm_changed_file\nindex 4800958..4800958 160000\n--- a/sm_changed_file\n+++ b/sm_changed_file\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_file */ + "diff --git a/sm_changed_head b/sm_changed_head\nindex 4800958..3d9386c 160000\n--- a/sm_changed_head\n+++ b/sm_changed_head\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 3d9386c507f6b093471a3e324085657a3c2b4247\n", /* sm_changed_head */ + "diff --git a/sm_changed_index b/sm_changed_index\nindex 4800958..4800958 160000\n--- a/sm_changed_index\n+++ b/sm_changed_index\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_index */ + "diff --git a/sm_changed_untracked_file b/sm_changed_untracked_file\nindex 4800958..4800958 160000\n--- a/sm_changed_untracked_file\n+++ b/sm_changed_untracked_file\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0-dirty\n", /* sm_changed_untracked_file */ + "diff --git a/sm_missing_commits b/sm_missing_commits\nindex 4800958..5e49635 160000\n--- a/sm_missing_commits\n+++ b/sm_missing_commits\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 5e4963595a9774b90524d35a807169049de8ccad\n", /* sm_missing_commits */ + "<END>" + }; + static const char *expected_ignore_all[] = { + "<SKIP>", /* .gitmodules */ + NULL, /* not-submodule */ + NULL, /* not */ + "<END>" + }; + static const char *expected_ignore_dirty[] = { + "<SKIP>", /* .gitmodules */ + NULL, /* not-submodule */ + NULL, /* not */ + "diff --git a/sm_changed_head b/sm_changed_head\nindex 4800958..3d9386c 160000\n--- a/sm_changed_head\n+++ b/sm_changed_head\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 3d9386c507f6b093471a3e324085657a3c2b4247\n", /* sm_changed_head */ + "diff --git a/sm_missing_commits b/sm_missing_commits\nindex 4800958..5e49635 160000\n--- a/sm_missing_commits\n+++ b/sm_missing_commits\n@@ -1 +1 @@\n-Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n+Subproject commit 5e4963595a9774b90524d35a807169049de8ccad\n", /* sm_missing_commits */ + "<END>" + }; + + setup_submodules2(); + + opts.flags = GIT_DIFF_INCLUDE_UNTRACKED; + opts.old_prefix = "a"; opts.new_prefix = "b"; + + cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); + check_diff_patches(diff, expected_normal); + git_diff_list_free(diff); + + opts.flags |= GIT_DIFF_IGNORE_SUBMODULES; + + cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); + check_diff_patches(diff, expected_ignore_all); + git_diff_list_free(diff); + + opts.flags &= ~GIT_DIFF_IGNORE_SUBMODULES; + opts.ignore_submodules = GIT_SUBMODULE_IGNORE_ALL; + + cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); + check_diff_patches(diff, expected_ignore_all); + git_diff_list_free(diff); + + opts.ignore_submodules = GIT_SUBMODULE_IGNORE_DIRTY; + + cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); + check_diff_patches(diff, expected_ignore_dirty); + git_diff_list_free(diff); +} |