diff options
| author | Russell Belfer <rb@github.com> | 2012-04-13 15:00:29 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2012-04-13 15:00:29 -0700 |
| commit | 14a513e05866721f5ceba18cf425568d2f6af143 (patch) | |
| tree | 4c31553a2c971adf579d2c5c287749ce45949c8c /tests-clar | |
| parent | d1f331564da9d6110b80b538a501da0c66e59142 (diff) | |
| download | libgit2-14a513e05866721f5ceba18cf425568d2f6af143.tar.gz | |
Add support for pathspec to diff and status
This adds preliminary support for pathspecs to diff and status.
The implementation is not very optimized (it still looks at
every single file and evaluated the the pathspec match against
them), but it works.
Diffstat (limited to 'tests-clar')
| -rw-r--r-- | tests-clar/attr/file.c | 6 | ||||
| -rw-r--r-- | tests-clar/diff/workdir.c | 73 |
2 files changed, 77 insertions, 2 deletions
diff --git a/tests-clar/attr/file.c b/tests-clar/attr/file.c index 132b906cd..6aeaa5135 100644 --- a/tests-clar/attr/file.c +++ b/tests-clar/attr/file.c @@ -20,7 +20,7 @@ void test_attr_file__simple_read(void) cl_assert(rule != NULL); cl_assert_strequal("*", rule->match.pattern); cl_assert(rule->match.length == 1); - cl_assert(rule->match.flags == 0); + cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0); cl_assert(rule->assigns.length == 1); assign = get_assign(rule, 0); @@ -74,14 +74,16 @@ void test_attr_file__match_variants(void) rule = get_rule(4); cl_assert_strequal("pat4.*", rule->match.pattern); - cl_assert(rule->match.flags == 0); + cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0); rule = get_rule(5); cl_assert_strequal("*.pat5", rule->match.pattern); + cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0); rule = get_rule(7); cl_assert_strequal("pat7[a-e]??[xyz]", rule->match.pattern); cl_assert(rule->assigns.length == 1); + cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0); assign = get_assign(rule,0); cl_assert_strequal("attr7", assign->name); cl_assert(GIT_ATTR_TRUE(assign->value)); diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c index 9fefdbb03..2a93039f1 100644 --- a/tests-clar/diff/workdir.c +++ b/tests-clar/diff/workdir.c @@ -164,6 +164,79 @@ void test_diff_workdir__to_tree(void) git_tree_free(b); } +void test_diff_workdir__to_index_with_pathspec(void) +{ + git_diff_options opts = {0}; + git_diff_list *diff = NULL; + diff_expects exp; + char *pathspec = NULL; + + opts.context_lines = 3; + opts.interhunk_lines = 1; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; + opts.pathspec.strings = &pathspec; + opts.pathspec.count = 1; + + memset(&exp, 0, sizeof(exp)); + + cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); + cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL)); + + cl_assert_equal_i(12, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(4, exp.file_dels); + cl_assert_equal_i(4, exp.file_mods); + cl_assert_equal_i(1, exp.file_ignored); + cl_assert_equal_i(3, exp.file_untracked); + + git_diff_list_free(diff); + + memset(&exp, 0, sizeof(exp)); + pathspec = "modified_file"; + + cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); + cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL)); + + cl_assert_equal_i(1, 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(0, exp.file_untracked); + + git_diff_list_free(diff); + + memset(&exp, 0, sizeof(exp)); + pathspec = "subdir"; + + cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); + cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL)); + + cl_assert_equal_i(3, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(1, exp.file_dels); + cl_assert_equal_i(1, exp.file_mods); + cl_assert_equal_i(0, exp.file_ignored); + cl_assert_equal_i(1, exp.file_untracked); + + git_diff_list_free(diff); + + memset(&exp, 0, sizeof(exp)); + pathspec = "*_deleted"; + + cl_git_pass(git_diff_workdir_to_index(g_repo, &opts, &diff)); + cl_git_pass(git_diff_foreach(diff, &exp, diff_file_fn, NULL, NULL)); + + cl_assert_equal_i(2, exp.files); + cl_assert_equal_i(0, exp.file_adds); + cl_assert_equal_i(2, exp.file_dels); + cl_assert_equal_i(0, exp.file_mods); + cl_assert_equal_i(0, exp.file_ignored); + cl_assert_equal_i(0, exp.file_untracked); + + git_diff_list_free(diff); +} + /* PREPARATION OF TEST DATA * * Since there is no command line equivalent of git_diff_workdir_to_tree, |
