summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-04-02 11:33:00 -0700
committerEdward Thomson <ethomson@github.com>2016-04-02 13:02:41 -0700
commit2e0391f4f1d088a9d9748a1b3bcab8ac576d63de (patch)
tree8014944c7f445fcb65f3451014161f478250a11c
parent36fc25572ca042372b1a58f07bc721b2b827e8be (diff)
downloadlibgit2-2e0391f4f1d088a9d9748a1b3bcab8ac576d63de.tar.gz
diff: test submodules are found with trailing `/`
Test that submodules are found when the are included in a pathspec but have a trailing slash.
-rw-r--r--tests/diff/submodules.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c
index 08682cd4b..eebfef3a2 100644
--- a/tests/diff/submodules.c
+++ b/tests/diff/submodules.c
@@ -493,3 +493,50 @@ void test_diff_submodules__skips_empty_includes_used(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
git_diff_free(diff);
}
+
+static void ensure_submodules_found(
+ git_repository *repo,
+ const char **paths,
+ size_t cnt)
+{
+ git_diff *diff = NULL;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ const git_diff_delta *delta;
+ size_t i, pathlen;
+
+ opts.pathspec.strings = (char **)paths;
+ opts.pathspec.count = cnt;
+
+ git_diff_index_to_workdir(&diff, repo, NULL, &opts);
+
+ cl_assert_equal_i(cnt, git_diff_num_deltas(diff));
+
+ for (i = 0; i < cnt; i++) {
+ delta = git_diff_get_delta(diff, i);
+
+ /* ensure that the given path is returned w/o trailing slashes. */
+ pathlen = strlen(opts.pathspec.strings[i]);
+
+ while (pathlen && opts.pathspec.strings[i][pathlen - 1] == '/')
+ pathlen--;
+
+ cl_assert_equal_strn(opts.pathspec.strings[i], delta->new_file.path, pathlen);
+ }
+
+ git_diff_free(diff);
+}
+
+void test_diff_submodules__can_be_identified_by_trailing_slash_in_pathspec(void)
+{
+ const char *one_path_without_slash[] = { "sm_changed_head" };
+ const char *one_path_with_slash[] = { "sm_changed_head/" };
+ const char *many_paths_without_slashes[] = { "sm_changed_head", "sm_changed_index" };
+ const char *many_paths_with_slashes[] = { "sm_changed_head/", "sm_changed_index/" };
+
+ g_repo = setup_fixture_submod2();
+
+ ensure_submodules_found(g_repo, one_path_without_slash, ARRAY_SIZE(one_path_without_slash));
+ ensure_submodules_found(g_repo, one_path_with_slash, ARRAY_SIZE(one_path_with_slash));
+ ensure_submodules_found(g_repo, many_paths_without_slashes, ARRAY_SIZE(many_paths_without_slashes));
+ ensure_submodules_found(g_repo, many_paths_with_slashes, ARRAY_SIZE(many_paths_with_slashes));
+}