Skip to content

Commit 17670ef

Browse files
committed
tests: diff: add test to verify behaviour with empty dir ordering
It was reported that, given a file "abc.txt", a diff will be shown if an empty directory "abb/" is created, but not if "abd/" is created. Add a test to verify that we do the right thing here and do not depend on any ordering.
1 parent b0691db commit 17670ef

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/diff/workdir.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,3 +2160,46 @@ void test_diff_workdir__symlink_changed_on_non_symlink_platform(void)
21602160
git_tree_free(tree);
21612161
git_vector_free(&pathlist);
21622162
}
2163+
2164+
void test_diff_workdir__order(void)
2165+
{
2166+
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
2167+
git_buf patch = GIT_BUF_INIT;
2168+
git_oid tree_oid, blob_oid;
2169+
git_treebuilder *builder;
2170+
git_tree *tree;
2171+
git_diff *diff;
2172+
2173+
g_repo = cl_git_sandbox_init("empty_standard_repo");
2174+
2175+
/* Build tree with a single file "abc.txt" */
2176+
cl_git_pass(git_blob_create_from_buffer(&blob_oid, g_repo, "foo\n", 4));
2177+
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
2178+
cl_git_pass(git_treebuilder_insert(NULL, builder, "abc.txt", &blob_oid, GIT_FILEMODE_BLOB));
2179+
cl_git_pass(git_treebuilder_write(&tree_oid, builder));
2180+
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid));
2181+
2182+
/* Create a directory that sorts before and one that sorts after "abc.txt" */
2183+
cl_git_mkfile("empty_standard_repo/abc.txt", "bar\n");
2184+
cl_must_pass(p_mkdir("empty_standard_repo/abb", 0777));
2185+
cl_must_pass(p_mkdir("empty_standard_repo/abd", 0777));
2186+
2187+
opts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
2188+
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
2189+
2190+
cl_assert_equal_i(1, git_diff_num_deltas(diff));
2191+
cl_git_pass(git_diff_to_buf(&patch, diff, GIT_DIFF_FORMAT_PATCH));
2192+
cl_assert_equal_s(patch.ptr,
2193+
"diff --git a/abc.txt b/abc.txt\n"
2194+
"index 257cc56..5716ca5 100644\n"
2195+
"--- a/abc.txt\n"
2196+
"+++ b/abc.txt\n"
2197+
"@@ -1 +1 @@\n"
2198+
"-foo\n"
2199+
"+bar\n");
2200+
2201+
git_treebuilder_free(builder);
2202+
git_buf_dispose(&patch);
2203+
git_diff_free(diff);
2204+
git_tree_free(tree);
2205+
}

0 commit comments

Comments
 (0)