cl_git_pass(git_patch_to_buf(&actual, patch));
cl_assert_equal_s(expected0, actual.ptr);
- git_buf_free(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
cl_git_pass(git_patch_to_buf(&actual, patch));
cl_assert_equal_s(expected1, actual.ptr);
- git_buf_free(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
cl_git_pass(git_patch_to_buf(&actual, patch));
cl_assert_equal_s(expected0, actual.ptr);
- git_buf_free(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
cl_git_pass(git_patch_to_buf(&actual, patch));
cl_assert_equal_s(expected1, actual.ptr);
- git_buf_free(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_set_bool(cfg, "diff.kipling0.binary", 0));
- cl_git_pass(git_config_set_string(cfg, "diff.kipling0.xfuncname", "^H"));
+ cl_git_pass(git_config_set_string(cfg, "diff.kipling0.xfuncname", "^H.*$"));
git_config_free(cfg);
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_git_pass(git_patch_to_buf(&actual, patch));
cl_assert_equal_s(expected2, actual.ptr);
- git_buf_free(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
cl_assert_equal_s(expected, actual.ptr);
- git_buf_free(&actual);
+ git_buf_dispose(&actual);
git_patch_free(patch);
git_diff_free(diff);
}
void test_diff_drivers__builtins(void)
{
- git_index *idx;
git_diff *diff;
git_patch *patch;
+ git_str file = GIT_STR_INIT, expected = GIT_STR_INIT;
git_buf actual = GIT_BUF_INIT;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- const char *base =
- "<html>\n<body>\n"
- " <h1 id=\"first section\">\n <ol>\n <li>item 1.1</li>\n <li>item 1.2</li>\n <li>item 1.3</li>\n <li>item 1.4</li>\n <li>item 1.5</li>\n <li>item 1.6</li>\n <li>item 1.7</li>\n <li>item 1.8</li>\n <li>item 1.9</li>\n </ol>\n </h1>\n"
- " <h1 id=\"second section\">\n <ol>\n <li>item 2.1</li>\n <li>item 2.2</li>\n <li>item 2.3</li>\n <li>item 2.4</li>\n <li>item 2.5</li>\n <li>item 2.6</li>\n <li>item 2.7</li>\n <li>item 2.8</li>\n </ol>\n </h1>\n"
- " <h1 id=\"third section\">\n <ol>\n <li>item 3.1</li>\n <li>item 3.2</li>\n <li>item 3.3</li>\n <li>item 3.4</li>\n <li>item 3.5</li>\n <li>item 3.6</li>\n <li>item 3.7</li>\n <li>item 3.8</li>\n </ol>\n </h1>\n"
- "</body></html>\n";
- const char *modified =
- "<html>\n<body>\n"
- " <h1 id=\"first section\">\n <ol>\n <li>item 1.1</li>\n <li>item 1.2 changed</li>\n <li>item 1.3 changed</li>\n <li>item 1.4</li>\n <li>item 1.5</li>\n <li>item 1.6</li>\n <li>item 1.7</li>\n <li>item 1.8</li>\n <li>item 1.9</li>\n <li>item 1.10 added</li>\n </ol>\n </h1>\n"
- " <h1 id=\"second section\">\n <ol>\n <li>item 2.1</li>\n <li>item 2.2</li>\n <li>item 2.3</li>\n <li>item 2.4</li>\n <li>item 2.5</li>\n <li>item 2.6</li>\n <li>item 2.7 changed</li>\n <li>item 2.7.1 added</li>\n <li>item 2.8</li>\n </ol>\n </h1>\n"
- " <h1 id=\"third section\">\n <ol>\n <li>item 3.1</li>\n <li>item 3.2</li>\n <li>item 3.3</li>\n <li>item 3.4</li>\n <li>item 3.5</li>\n <li>item 3.6</li>\n </ol>\n </h1>\n"
- "</body></html>\n";
- const char *expected_nodriver =
- "diff --git a/file.html b/file.html\nindex 97b34db..c7dbed3 100644\n--- a/file.html\n+++ b/file.html\n@@ -5,4 +5,4 @@\n <li>item 1.1</li>\n- <li>item 1.2</li>\n- <li>item 1.3</li>\n+ <li>item 1.2 changed</li>\n+ <li>item 1.3 changed</li>\n <li>item 1.4</li>\n@@ -13,2 +13,3 @@\n <li>item 1.9</li>\n+ <li>item 1.10 added</li>\n </ol>\n@@ -23,3 +24,4 @@\n <li>item 2.6</li>\n- <li>item 2.7</li>\n+ <li>item 2.7 changed</li>\n+ <li>item 2.7.1 added</li>\n <li>item 2.8</li>\n@@ -35,4 +37,2 @@\n <li>item 3.6</li>\n- <li>item 3.7</li>\n- <li>item 3.8</li>\n </ol>\n";
- const char *expected_driver =
- "diff --git a/file.html b/file.html\nindex 97b34db..c7dbed3 100644\n--- a/file.html\n+++ b/file.html\n@@ -5,4 +5,4 @@ <h1 id=\"first section\">\n <li>item 1.1</li>\n- <li>item 1.2</li>\n- <li>item 1.3</li>\n+ <li>item 1.2 changed</li>\n+ <li>item 1.3 changed</li>\n <li>item 1.4</li>\n@@ -13,2 +13,3 @@ <h1 id=\"first section\">\n <li>item 1.9</li>\n+ <li>item 1.10 added</li>\n </ol>\n@@ -23,3 +24,4 @@ <h1 id=\"second section\">\n <li>item 2.6</li>\n- <li>item 2.7</li>\n+ <li>item 2.7 changed</li>\n+ <li>item 2.7.1 added</li>\n <li>item 2.8</li>\n@@ -35,4 +37,2 @@ <h1 id=\"third section\">\n <li>item 3.6</li>\n- <li>item 3.7</li>\n- <li>item 3.8</li>\n </ol>\n";
-
- g_repo = cl_git_sandbox_init("empty_standard_repo");
-
- cl_git_mkfile("empty_standard_repo/file.html", base);
- cl_git_pass(git_repository_index(&idx, g_repo));
- cl_git_pass(git_index_add_bypath(idx, "file.html"));
- cl_git_pass(git_index_write(idx));
- git_index_free(idx);
+ git_vector files = GIT_VECTOR_INIT;
+ size_t i;
+ char *path, *extension;
- cl_git_rewritefile("empty_standard_repo/file.html", modified);
+ g_repo = cl_git_sandbox_init("userdiff");
- /* do diff with no special driver */
+ cl_git_pass(git_fs_path_dirload(&files, "userdiff/files", 9, 0));
opts.interhunk_lines = 1;
opts.context_lines = 1;
+ opts.pathspec.count = 1;
- cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
- cl_assert_equal_sz(1, git_diff_num_deltas(diff));
- cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_patch_to_buf(&actual, patch));
+ git_vector_foreach(&files, i, path) {
+ if (git__prefixcmp(path, "files/file."))
+ continue;
+ extension = path + strlen("files/file.");
+ opts.pathspec.strings = &path;
- overwrite_filemode(expected_nodriver, &actual);
+ /* do diff with no special driver */
- cl_assert_equal_s(expected_nodriver, actual.ptr);
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_assert_equal_sz(1, git_diff_num_deltas(diff));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_buf(&actual, patch));
- git_buf_free(&actual);
- git_patch_free(patch);
- git_diff_free(diff);
+ git_str_sets(&expected, "userdiff/expected/nodriver/diff.");
+ git_str_puts(&expected, extension);
+ cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
- /* do diff with HTML driver */
+ overwrite_filemode(expected.ptr, &actual);
- cl_git_mkfile("empty_standard_repo/.gitattributes", "*.html diff=html\n");
+ cl_assert_equal_s(expected.ptr, actual.ptr);
- cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
- cl_assert_equal_sz(1, git_diff_num_deltas(diff));
- cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_patch_to_buf(&actual, patch));
+ git_buf_dispose(&actual);
+ git_patch_free(patch);
+ git_diff_free(diff);
+
+ /* do diff with driver */
+
+ {
+ FILE *fp = fopen("userdiff/.gitattributes", "w");
+ fprintf(fp, "*.%s diff=%s\n", extension, extension);
+ fclose(fp);
+ }
- overwrite_filemode(expected_driver, &actual);
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_assert_equal_sz(1, git_diff_num_deltas(diff));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_buf(&actual, patch));
- cl_assert_equal_s(expected_driver, actual.ptr);
+ git_str_sets(&expected, "userdiff/expected/driver/diff.");
+ git_str_puts(&expected, extension);
+ cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
+
+ overwrite_filemode(expected.ptr, &actual);
+
+ cl_assert_equal_s(expected.ptr, actual.ptr);
+
+ git_buf_dispose(&actual);
+ git_patch_free(patch);
+ git_diff_free(diff);
+
+ git__free(path);
+ }
+
+ git_buf_dispose(&actual);
+ git_str_dispose(&file);
+ git_str_dispose(&expected);
+ git_vector_free(&files);
+}
+
+void test_diff_drivers__invalid_pattern(void)
+{
+ git_config *cfg;
+ git_index *idx;
+ git_diff *diff;
+ git_patch *patch;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+
+ g_repo = cl_git_sandbox_init("userdiff");
+ cl_git_mkfile("userdiff/.gitattributes", "*.storyboard diff=storyboard\n");
+
+ cl_git_pass(git_repository_config__weakptr(&cfg, g_repo));
+ cl_git_pass(git_config_set_string(cfg, "diff.storyboard.xfuncname", "<!--(.*?)-->"));
+
+ cl_git_mkfile("userdiff/dummy.storyboard", "");
+ cl_git_pass(git_repository_index__weakptr(&idx, g_repo));
+ cl_git_pass(git_index_add_bypath(idx, "dummy.storyboard"));
+ cl_git_mkfile("userdiff/dummy.storyboard", "some content\n");
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
}