Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diff/submodules.c')
-rw-r--r--tests/diff/submodules.c94
1 files changed, 83 insertions, 11 deletions
diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c
index 24545b2c7..02870ac86 100644
--- a/tests/diff/submodules.c
+++ b/tests/diff/submodules.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "repository.h"
#include "posix.h"
+#include "diff_helpers.h"
#include "../submodule/submodule_helpers.h"
static git_repository *g_repo = NULL;
@@ -11,15 +12,18 @@ void test_diff_submodules__initialize(void)
void test_diff_submodules__cleanup(void)
{
+ cl_git_sandbox_cleanup();
}
+#define get_buf_ptr(buf) ((buf)->asize ? (buf)->ptr : NULL)
+
static void check_diff_patches_at_line(
git_diff *diff, const char **expected, const char *file, int line)
{
const git_diff_delta *delta;
git_patch *patch = NULL;
size_t d, num_d = git_diff_num_deltas(diff);
- char *patch_text;
+ git_buf buf = GIT_BUF_INIT;
for (d = 0; d < num_d; ++d, git_patch_free(patch)) {
cl_git_pass(git_patch_from_diff(&patch, diff, d));
@@ -32,17 +36,21 @@ static void check_diff_patches_at_line(
if (expected[d] && !strcmp(expected[d], "<SKIP>"))
continue;
+ if (expected[d] && !strcmp(expected[d], "<UNTRACKED>")) {
+ cl_assert_at_line(delta->status == GIT_DELTA_UNTRACKED, file, line);
+ continue;
+ }
if (expected[d] && !strcmp(expected[d], "<END>")) {
- cl_git_pass(git_patch_to_str(&patch_text, patch));
+ cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_at_line(!strcmp(expected[d], "<END>"), file, line);
}
- cl_git_pass(git_patch_to_str(&patch_text, patch));
+ cl_git_pass(git_patch_to_buf(&buf, patch));
clar__assert_equal(
file, line, "expected diff did not match actual diff", 1,
- "%s", expected[d], patch_text);
- git__free(patch_text);
+ "%s", expected[d], get_buf_ptr(&buf));
+ git_buf_free(&buf);
}
cl_assert_at_line(expected[d] && !strcmp(expected[d], "<END>"), file, line);
@@ -113,7 +121,9 @@ void test_diff_submodules__dirty_submodule_2(void)
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff *diff = NULL, *diff2 = NULL;
char *smpath = "testrepo";
- static const char *expected_none[] = { "<END>" };
+ static const char *expected_none[] = {
+ "<END>"
+ };
static const char *expected_dirty[] = {
"diff --git a/testrepo b/testrepo\nindex a65fedf..a65fedf 160000\n--- a/testrepo\n+++ b/testrepo\n@@ -1 +1 @@\n-Subproject commit a65fedf39aefe402d3bb6e24df4d4f5fe4547750\n+Subproject commit a65fedf39aefe402d3bb6e24df4d4f5fe4547750-dirty\n", /* testrepo.git */
"<END>"
@@ -121,8 +131,6 @@ void test_diff_submodules__dirty_submodule_2(void)
g_repo = setup_fixture_submodules();
- cl_git_pass(git_submodule_reload_all(g_repo));
-
opts.flags = GIT_DIFF_INCLUDE_UNTRACKED |
GIT_DIFF_SHOW_UNTRACKED_CONTENT |
GIT_DIFF_RECURSE_UNTRACKED_DIRS |
@@ -155,8 +163,6 @@ void test_diff_submodules__dirty_submodule_2(void)
git_diff_free(diff);
- cl_git_pass(git_submodule_reload_all(g_repo));
-
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
git_diff_free(diff);
@@ -168,8 +174,12 @@ void test_diff_submodules__submod2_index_to_wd(void)
git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
+ "<UNTRACKED>", /* not-submodule */
+ "<UNTRACKED>", /* 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 */
+ "<UNTRACKED>", /* sm_changed_head- */
+ "<UNTRACKED>", /* 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 */
@@ -178,6 +188,10 @@ void test_diff_submodules__submod2_index_to_wd(void)
g_repo = setup_fixture_submod2();
+ /* bracket existing submodule with similarly named items */
+ cl_git_mkfile("submod2/sm_changed_head-", "hello");
+ cl_git_mkfile("submod2/sm_changed_head_", "hello");
+
opts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
opts.old_prefix = "a"; opts.new_prefix = "b";
@@ -279,7 +293,8 @@ void test_diff_submodules__invalid_cache(void)
check_diff_patches(diff, expected_dirty);
git_diff_free(diff);
- cl_git_pass(git_submodule_reload_all(g_repo));
+ git_submodule_free(sm);
+
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
@@ -332,6 +347,8 @@ void test_diff_submodules__invalid_cache(void)
p_unlink("submod2/sm_changed_head/new_around_here");
+ git_submodule_free(sm);
+
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_moved);
git_diff_free(diff);
@@ -347,6 +364,8 @@ void test_diff_submodules__diff_ignore_options(void)
git_config *cfg;
static const char *expected_normal[] = {
"<SKIP>", /* .gitmodules */
+ "<UNTRACKED>", /* not-submodule */
+ "<UNTRACKED>", /* 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 */
@@ -356,10 +375,14 @@ void test_diff_submodules__diff_ignore_options(void)
};
static const char *expected_ignore_all[] = {
"<SKIP>", /* .gitmodules */
+ "<UNTRACKED>", /* not-submodule */
+ "<UNTRACKED>", /* not */
"<END>"
};
static const char *expected_ignore_dirty[] = {
"<SKIP>", /* .gitmodules */
+ "<UNTRACKED>", /* not-submodule */
+ "<UNTRACKED>", /* 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>"
@@ -421,3 +444,52 @@ void test_diff_submodules__diff_ignore_options(void)
git_config_free(cfg);
}
+
+void test_diff_submodules__skips_empty_includes_used(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff *diff = NULL;
+ diff_expects exp;
+
+ /* A side effect of of Git's handling of untracked directories and
+ * auto-ignoring of ".git" entries is that a newly initialized Git
+ * repo inside another repo will be skipped by diff, but one that
+ * actually has a commit it in will show as an untracked directory.
+ * Let's make sure that works.
+ */
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &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(0, exp.files);
+ git_diff_free(diff);
+
+ {
+ git_repository *r2;
+ cl_git_pass(git_repository_init(&r2, "empty_standard_repo/subrepo", 0));
+ git_repository_free(r2);
+ }
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &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(1, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
+ git_diff_free(diff);
+
+ cl_git_mkfile("empty_standard_repo/subrepo/README.txt", "hello\n");
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &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(1, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
+ git_diff_free(diff);
+}