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:
authorBen Straub <bs@github.com>2013-10-28 22:04:58 +0400
committerBen Straub <bs@github.com>2013-10-28 22:04:58 +0400
commit42c8f8f807fe986534e0cbabbfabc32cb4eb9077 (patch)
treefa76cb66e6d49855be344026b1cbe31d03962916 /tests-clar
parenta7d28f40a2a01382b76c55ca0a0672c177adaf69 (diff)
parent5c50f22a93c78190fb7d81802199ff9defc8cf55 (diff)
Merge remote-tracking branch 'libgit2/development' into blame
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/checkout/conflict.c1124
-rw-r--r--tests-clar/checkout/index.c10
-rw-r--r--tests-clar/checkout/tree.c44
-rw-r--r--tests-clar/clar_libgit2.c6
-rw-r--r--tests-clar/clone/nonetwork.c27
-rw-r--r--tests-clar/core/dirent.c53
-rw-r--r--tests-clar/core/iconv.c60
-rw-r--r--tests-clar/core/mkdir.c20
-rw-r--r--tests-clar/core/path.c2
-rw-r--r--tests-clar/diff/blob.c234
-rw-r--r--tests-clar/diff/diff_helpers.c133
-rw-r--r--tests-clar/diff/diff_helpers.h18
-rw-r--r--tests-clar/diff/diffiter.c156
-rw-r--r--tests-clar/diff/drivers.c65
-rw-r--r--tests-clar/diff/index.c12
-rw-r--r--tests-clar/diff/notify.c16
-rw-r--r--tests-clar/diff/patch.c349
-rw-r--r--tests-clar/diff/pathspec.c8
-rw-r--r--tests-clar/diff/rename.c109
-rw-r--r--tests-clar/diff/submodules.c87
-rw-r--r--tests-clar/diff/tree.c71
-rw-r--r--tests-clar/diff/workdir.c232
-rw-r--r--tests-clar/index/addall.c5
-rw-r--r--tests-clar/index/filemodes.c28
-rw-r--r--tests-clar/index/names.c64
-rw-r--r--tests-clar/index/tests.c66
-rw-r--r--tests-clar/merge/merge_helpers.c2
-rw-r--r--tests-clar/object/tree/attributes.c3
-rw-r--r--tests-clar/online/clone.c6
-rw-r--r--tests-clar/online/push.c118
-rw-r--r--tests-clar/pack/indexer.c128
-rw-r--r--tests-clar/pack/packbuilder.c4
-rw-r--r--tests-clar/refs/lookup.c12
-rw-r--r--tests-clar/refs/reflog/drop.c13
-rw-r--r--tests-clar/refs/reflog/reflog.c103
-rw-r--r--tests-clar/refs/unicode.c34
-rw-r--r--tests-clar/repo/init.c81
-rw-r--r--tests-clar/resources/merge-resolve/.gitted/objects/1a/010b1c0f081b2e8901d55307a15c29ff30af0ebin0 -> 19 bytes
-rw-r--r--tests-clar/resources/merge-resolve/.gitted/objects/72/ea499e108df5ff0a4a913e7655bbeeb1fb69f2bin0 -> 26 bytes
-rw-r--r--tests-clar/resources/merge-resolve/.gitted/objects/8b/fb012a6d809e499bd8d3e194a3929bc8995b93bin0 -> 34 bytes
-rw-r--r--tests-clar/stash/drop.c4
-rw-r--r--tests-clar/status/renames.c14
-rw-r--r--tests-clar/status/worktree.c2
-rw-r--r--tests-clar/stress/diff.c6
-rw-r--r--tests-clar/submodule/lookup.c15
-rw-r--r--tests-clar/submodule/modify.c15
-rw-r--r--tests-clar/submodule/status.c3
-rw-r--r--tests-clar/submodule/submodule_helpers.c5
-rw-r--r--tests-clar/threads/basic.c13
49 files changed, 2572 insertions, 1008 deletions
diff --git a/tests-clar/checkout/conflict.c b/tests-clar/checkout/conflict.c
new file mode 100644
index 000000000..d261f3860
--- /dev/null
+++ b/tests-clar/checkout/conflict.c
@@ -0,0 +1,1124 @@
+#include "clar_libgit2.h"
+#include "git2/repository.h"
+#include "git2/sys/index.h"
+#include "fileops.h"
+
+static git_repository *g_repo;
+static git_index *g_index;
+
+#define TEST_REPO_PATH "merge-resolve"
+
+#define CONFLICTING_ANCESTOR_OID "d427e0b2e138501a3d15cc376077a3631e15bd46"
+#define CONFLICTING_OURS_OID "4e886e602529caa9ab11d71f86634bd1b6e0de10"
+#define CONFLICTING_THEIRS_OID "2bd0a343aeef7a2cf0d158478966a6e587ff3863"
+
+#define AUTOMERGEABLE_ANCESTOR_OID "6212c31dab5e482247d7977e4f0dd3601decf13b"
+#define AUTOMERGEABLE_OURS_OID "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"
+#define AUTOMERGEABLE_THEIRS_OID "058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe"
+
+#define LINK_ANCESTOR_OID "1a010b1c0f081b2e8901d55307a15c29ff30af0e"
+#define LINK_OURS_OID "72ea499e108df5ff0a4a913e7655bbeeb1fb69f2"
+#define LINK_THEIRS_OID "8bfb012a6d809e499bd8d3e194a3929bc8995b93"
+
+#define LINK_ANCESTOR_TARGET "file"
+#define LINK_OURS_TARGET "other-file"
+#define LINK_THEIRS_TARGET "still-another-file"
+
+#define CONFLICTING_OURS_FILE \
+ "this file is changed in master and branch\n"
+#define CONFLICTING_THEIRS_FILE \
+ "this file is changed in branch and master\n"
+#define CONFLICTING_DIFF3_FILE \
+ "<<<<<<< ours\n" \
+ "this file is changed in master and branch\n" \
+ "=======\n" \
+ "this file is changed in branch and master\n" \
+ ">>>>>>> theirs\n"
+
+#define AUTOMERGEABLE_MERGED_FILE \
+ "this file is changed in master\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is automergeable\n" \
+ "this file is changed in branch\n"
+
+struct checkout_index_entry {
+ uint16_t mode;
+ char oid_str[41];
+ int stage;
+ char path[128];
+};
+
+struct checkout_name_entry {
+ char ancestor[64];
+ char ours[64];
+ char theirs[64];
+};
+
+void test_checkout_conflict__initialize(void)
+{
+ g_repo = cl_git_sandbox_init(TEST_REPO_PATH);
+ git_repository_index(&g_index, g_repo);
+
+ cl_git_rewritefile(
+ TEST_REPO_PATH "/.gitattributes",
+ "* text eol=lf\n");
+}
+
+void test_checkout_conflict__cleanup(void)
+{
+ git_index_free(g_index);
+ cl_git_sandbox_cleanup();
+}
+
+static void create_index(struct checkout_index_entry *entries, size_t entries_len)
+{
+ git_buf path = GIT_BUF_INIT;
+ size_t i;
+
+ for (i = 0; i < entries_len; i++) {
+ git_buf_joinpath(&path, TEST_REPO_PATH, entries[i].path);
+
+ if (entries[i].stage == 3 && (i == 0 || strcmp(entries[i-1].path, entries[i].path) != 0 || entries[i-1].stage != 2))
+ p_unlink(git_buf_cstr(&path));
+
+ git_index_remove_bypath(g_index, entries[i].path);
+ }
+
+ for (i = 0; i < entries_len; i++) {
+ git_index_entry entry;
+
+ memset(&entry, 0x0, sizeof(git_index_entry));
+
+ entry.mode = entries[i].mode;
+ entry.flags = entries[i].stage << GIT_IDXENTRY_STAGESHIFT;
+ git_oid_fromstr(&entry.oid, entries[i].oid_str);
+ entry.path = entries[i].path;
+
+ cl_git_pass(git_index_add(g_index, &entry));
+ }
+
+ git_buf_free(&path);
+}
+
+static void create_index_names(struct checkout_name_entry *entries, size_t entries_len)
+{
+ size_t i;
+
+ for (i = 0; i < entries_len; i++) {
+ cl_git_pass(git_index_name_add(g_index,
+ strlen(entries[i].ancestor) == 0 ? NULL : entries[i].ancestor,
+ strlen(entries[i].ours) == 0 ? NULL : entries[i].ours,
+ strlen(entries[i].theirs) == 0 ? NULL : entries[i].theirs));
+ }
+}
+
+static void create_conflicting_index(void)
+{
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "conflicting.txt" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "conflicting.txt" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "conflicting.txt" },
+ };
+
+ create_index(checkout_index_entries, 3);
+ git_index_write(g_index);
+}
+
+static void ensure_workdir_contents(const char *path, const char *contents)
+{
+ git_buf fullpath = GIT_BUF_INIT, data_buf = GIT_BUF_INIT;
+
+ cl_git_pass(
+ git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+
+ cl_git_pass(git_futils_readbuffer(&data_buf, git_buf_cstr(&fullpath)));
+ cl_assert(strcmp(git_buf_cstr(&data_buf), contents) == 0);
+
+ git_buf_free(&fullpath);
+ git_buf_free(&data_buf);
+}
+
+static void ensure_workdir_oid(const char *path, const char *oid_str)
+{
+ git_oid expected, actual;
+
+ cl_git_pass(git_oid_fromstr(&expected, oid_str));
+ cl_git_pass(git_repository_hashfile(&actual, g_repo, path, GIT_OBJ_BLOB, NULL));
+ cl_assert(git_oid_cmp(&expected, &actual) == 0);
+}
+
+static void ensure_workdir_mode(const char *path, int mode)
+{
+#ifndef GIT_WIN32
+ git_buf fullpath = GIT_BUF_INIT;
+ struct stat st;
+
+ cl_git_pass(
+ git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+
+ cl_git_pass(p_stat(git_buf_cstr(&fullpath), &st));
+ cl_assert_equal_i(mode, st.st_mode);
+
+ git_buf_free(&fullpath);
+#endif
+}
+
+static void ensure_workdir(const char *path, int mode, const char *oid_str)
+{
+ ensure_workdir_mode(path, mode);
+ ensure_workdir_oid(path, oid_str);
+}
+
+static void ensure_workdir_link(const char *path, const char *target)
+{
+#ifdef GIT_WIN32
+ ensure_workdir_contents(path, target);
+#else
+ git_buf fullpath = GIT_BUF_INIT;
+ char actual[1024];
+ struct stat st;
+ int len;
+
+ cl_git_pass(
+ git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path));
+
+ cl_git_pass(p_lstat(git_buf_cstr(&fullpath), &st));
+ cl_assert(S_ISLNK(st.st_mode));
+
+ cl_assert((len = p_readlink(git_buf_cstr(&fullpath), actual, 1024)) > 0);
+ actual[len] = '\0';
+ cl_assert(strcmp(actual, target) == 0);
+
+ git_buf_free(&fullpath);
+#endif
+}
+
+void test_checkout_conflict__ignored(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SKIP_UNMERGED;
+
+ create_conflicting_index();
+ cl_git_pass(p_unlink(TEST_REPO_PATH "/conflicting.txt"));
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ cl_assert(!git_path_exists(TEST_REPO_PATH "/conflicting.txt"));
+}
+
+void test_checkout_conflict__ours(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy |= GIT_CHECKOUT_USE_OURS;
+
+ create_conflicting_index();
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir_contents("conflicting.txt", CONFLICTING_OURS_FILE);
+}
+
+void test_checkout_conflict__theirs(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy |= GIT_CHECKOUT_USE_THEIRS;
+
+ create_conflicting_index();
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir_contents("conflicting.txt", CONFLICTING_THEIRS_FILE);
+
+}
+
+void test_checkout_conflict__diff3(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ create_conflicting_index();
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir_contents("conflicting.txt", CONFLICTING_DIFF3_FILE);
+}
+
+void test_checkout_conflict__automerge(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, AUTOMERGEABLE_ANCESTOR_OID, 1, "automergeable.txt" },
+ { 0100644, AUTOMERGEABLE_OURS_OID, 2, "automergeable.txt" },
+ { 0100644, AUTOMERGEABLE_THEIRS_OID, 3, "automergeable.txt" },
+ };
+
+ create_index(checkout_index_entries, 3);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir_contents("automergeable.txt", AUTOMERGEABLE_MERGED_FILE);
+}
+
+void test_checkout_conflict__directory_file(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "df-1" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "df-1" },
+ { 0100644, CONFLICTING_THEIRS_OID, 0, "df-1/file" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "df-2" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "df-2" },
+ { 0100644, CONFLICTING_OURS_OID, 0, "df-2/file" },
+
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "df-3" },
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "df-3/file" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "df-3/file" },
+
+ { 0100644, CONFLICTING_OURS_OID, 2, "df-4" },
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "df-4/file" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "df-4/file" },
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+
+ create_index(checkout_index_entries, 12);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir_oid("df-1/file", CONFLICTING_THEIRS_OID);
+ ensure_workdir_oid("df-1~ours", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("df-2/file", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("df-2~theirs", CONFLICTING_THEIRS_OID);
+ ensure_workdir_oid("df-3/file", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("df-3~theirs", CONFLICTING_THEIRS_OID);
+ ensure_workdir_oid("df-4~ours", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("df-4/file", CONFLICTING_THEIRS_OID);
+}
+
+void test_checkout_conflict__directory_file_with_custom_labels(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "df-1" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "df-1" },
+ { 0100644, CONFLICTING_THEIRS_OID, 0, "df-1/file" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "df-2" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "df-2" },
+ { 0100644, CONFLICTING_OURS_OID, 0, "df-2/file" },
+
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "df-3" },
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "df-3/file" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "df-3/file" },
+
+ { 0100644, CONFLICTING_OURS_OID, 2, "df-4" },
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "df-4/file" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "df-4/file" },
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+ opts.our_label = "HEAD";
+ opts.their_label = "branch";
+
+ create_index(checkout_index_entries, 12);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir_oid("df-1/file", CONFLICTING_THEIRS_OID);
+ ensure_workdir_oid("df-1~HEAD", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("df-2/file", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("df-2~branch", CONFLICTING_THEIRS_OID);
+ ensure_workdir_oid("df-3/file", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("df-3~branch", CONFLICTING_THEIRS_OID);
+ ensure_workdir_oid("df-4~HEAD", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("df-4/file", CONFLICTING_THEIRS_OID);
+}
+
+void test_checkout_conflict__link_file(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "link-1" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "link-1" },
+ { 0120000, LINK_THEIRS_OID, 3, "link-1" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "link-2" },
+ { 0120000, LINK_OURS_OID, 2, "link-2" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "link-2" },
+
+ { 0120000, LINK_ANCESTOR_OID, 1, "link-3" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "link-3" },
+ { 0120000, LINK_THEIRS_OID, 3, "link-3" },
+
+ { 0120000, LINK_ANCESTOR_OID, 1, "link-4" },
+ { 0120000, LINK_OURS_OID, 2, "link-4" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "link-4" },
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+
+ create_index(checkout_index_entries, 12);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ /* Typechange conflicts always keep the file in the workdir */
+ ensure_workdir_oid("link-1", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("link-2", CONFLICTING_THEIRS_OID);
+ ensure_workdir_oid("link-3", CONFLICTING_OURS_OID);
+ ensure_workdir_oid("link-4", CONFLICTING_THEIRS_OID);
+}
+
+void test_checkout_conflict__links(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0120000, LINK_ANCESTOR_OID, 1, "link-1" },
+ { 0120000, LINK_OURS_OID, 2, "link-1" },
+ { 0120000, LINK_THEIRS_OID, 3, "link-1" },
+
+ { 0120000, LINK_OURS_OID, 2, "link-2" },
+ { 0120000, LINK_THEIRS_OID, 3, "link-2" },
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+
+ create_index(checkout_index_entries, 5);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ /* Conflicts with links always keep the ours side (even with -Xtheirs) */
+ ensure_workdir_link("link-1", LINK_OURS_TARGET);
+ ensure_workdir_link("link-2", LINK_OURS_TARGET);
+}
+
+void test_checkout_conflict__add_add(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, CONFLICTING_OURS_OID, 2, "conflicting.txt" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "conflicting.txt" },
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+
+ create_index(checkout_index_entries, 2);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ /* Add/add writes diff3 files */
+ ensure_workdir_contents("conflicting.txt", CONFLICTING_DIFF3_FILE);
+}
+
+void test_checkout_conflict__mode_change(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "executable-1" },
+ { 0100755, CONFLICTING_ANCESTOR_OID, 2, "executable-1" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "executable-1" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "executable-2" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "executable-2" },
+ { 0100755, CONFLICTING_ANCESTOR_OID, 3, "executable-2" },
+
+ { 0100755, CONFLICTING_ANCESTOR_OID, 1, "executable-3" },
+ { 0100644, CONFLICTING_ANCESTOR_OID, 2, "executable-3" },
+ { 0100755, CONFLICTING_THEIRS_OID, 3, "executable-3" },
+
+ { 0100755, CONFLICTING_ANCESTOR_OID, 1, "executable-4" },
+ { 0100755, CONFLICTING_OURS_OID, 2, "executable-4" },
+ { 0100644, CONFLICTING_ANCESTOR_OID, 3, "executable-4" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "executable-5" },
+ { 0100755, CONFLICTING_OURS_OID, 2, "executable-5" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "executable-5" },
+
+ { 0100755, CONFLICTING_ANCESTOR_OID, 1, "executable-6" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "executable-6" },
+ { 0100755, CONFLICTING_THEIRS_OID, 3, "executable-6" },
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+
+ create_index(checkout_index_entries, 18);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ /* Keep the modified mode */
+ ensure_workdir_oid("executable-1", CONFLICTING_THEIRS_OID);
+ ensure_workdir_mode("executable-1", 0100755);
+
+ ensure_workdir_oid("executable-2", CONFLICTING_OURS_OID);
+ ensure_workdir_mode("executable-2", 0100755);
+
+ ensure_workdir_oid("executable-3", CONFLICTING_THEIRS_OID);
+ ensure_workdir_mode("executable-3", 0100644);
+
+ ensure_workdir_oid("executable-4", CONFLICTING_OURS_OID);
+ ensure_workdir_mode("executable-4", 0100644);
+
+ ensure_workdir_contents("executable-5", CONFLICTING_DIFF3_FILE);
+ ensure_workdir_mode("executable-5", 0100755);
+
+ ensure_workdir_contents("executable-6", CONFLICTING_DIFF3_FILE);
+ ensure_workdir_mode("executable-6", 0100644);
+}
+
+void test_checkout_conflict__renames(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
+ { 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" },
+ { 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 1, "0b-rewritten-in-ours.txt" },
+ { 0100644, "e376fbdd06ebf021c92724da9f26f44212734e3e", 2, "0b-rewritten-in-ours.txt" },
+ { 0100644, "b2d399ae15224e1d58066e3c8df70ce37de7a656", 3, "0b-rewritten-in-ours.txt" },
+ { 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-duplicated-in-theirs.txt" },
+ { 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 1, "0c-rewritten-in-theirs.txt" },
+ { 0100644, "efc9121fdedaf08ba180b53ebfbcf71bd488ed09", 2, "0c-rewritten-in-theirs.txt" },
+ { 0100644, "712ebba6669ea847d9829e4f1059d6c830c8b531", 3, "0c-rewritten-in-theirs.txt" },
+ { 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638", 0, "1a-newname-in-ours-edited-in-theirs.txt" },
+ { 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-newname-in-ours.txt" },
+ { 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a", 0, "1b-newname-in-theirs-edited-in-ours.txt" },
+ { 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-newname-in-theirs.txt" },
+ { 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" },
+ { 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 2, "3a-newname-in-ours-deleted-in-theirs.txt" },
+ { 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 1, "3a-renamed-in-ours-deleted-in-theirs.txt" },
+ { 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 3, "3b-newname-in-theirs-deleted-in-ours.txt" },
+ { 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 1, "3b-renamed-in-theirs-deleted-in-ours.txt" },
+ { 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 2, "4a-newname-in-ours-added-in-theirs.txt" },
+ { 0100644, "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a", 3, "4a-newname-in-ours-added-in-theirs.txt" },
+ { 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 1, "4a-renamed-in-ours-added-in-theirs.txt" },
+ { 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9", 2, "4b-newname-in-theirs-added-in-ours.txt" },
+ { 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 3, "4b-newname-in-theirs-added-in-ours.txt" },
+ { 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 1, "4b-renamed-in-theirs-added-in-ours.txt" },
+ { 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 2, "5a-newname-in-ours-added-in-theirs.txt" },
+ { 0100644, "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714", 3, "5a-newname-in-ours-added-in-theirs.txt" },
+ { 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 1, "5a-renamed-in-ours-added-in-theirs.txt" },
+ { 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 3, "5a-renamed-in-ours-added-in-theirs.txt" },
+ { 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced", 2, "5b-newname-in-theirs-added-in-ours.txt" },
+ { 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 3, "5b-newname-in-theirs-added-in-ours.txt" },
+ { 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 1, "5b-renamed-in-theirs-added-in-ours.txt" },
+ { 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 2, "5b-renamed-in-theirs-added-in-ours.txt" },
+ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 2, "6-both-renamed-1-to-2-ours.txt" },
+ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 3, "6-both-renamed-1-to-2-theirs.txt" },
+ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 1, "6-both-renamed-1-to-2.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 1, "7-both-renamed-side-1.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 3, "7-both-renamed-side-1.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 1, "7-both-renamed-side-2.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 2, "7-both-renamed-side-2.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 2, "7-both-renamed.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "7-both-renamed.txt" }
+ };
+
+ struct checkout_name_entry checkout_name_entries[] = {
+ {
+ "3a-renamed-in-ours-deleted-in-theirs.txt",
+ "3a-newname-in-ours-deleted-in-theirs.txt",
+ ""
+ },
+
+ {
+ "3b-renamed-in-theirs-deleted-in-ours.txt",
+ "",
+ "3b-newname-in-theirs-deleted-in-ours.txt"
+ },
+
+ {
+ "4a-renamed-in-ours-added-in-theirs.txt",
+ "4a-newname-in-ours-added-in-theirs.txt",
+ ""
+ },
+
+ {
+ "4b-renamed-in-theirs-added-in-ours.txt",
+ "",
+ "4b-newname-in-theirs-added-in-ours.txt"
+ },
+
+ {
+ "5a-renamed-in-ours-added-in-theirs.txt",
+ "5a-newname-in-ours-added-in-theirs.txt",
+ "5a-renamed-in-ours-added-in-theirs.txt"
+ },
+
+ {
+ "5b-renamed-in-theirs-added-in-ours.txt",
+ "5b-renamed-in-theirs-added-in-ours.txt",
+ "5b-newname-in-theirs-added-in-ours.txt"
+ },
+
+ {
+ "6-both-renamed-1-to-2.txt",
+ "6-both-renamed-1-to-2-ours.txt",
+ "6-both-renamed-1-to-2-theirs.txt"
+ },
+
+ {
+ "7-both-renamed-side-1.txt",
+ "7-both-renamed.txt",
+ "7-both-renamed-side-1.txt"
+ },
+
+ {
+ "7-both-renamed-side-2.txt",
+ "7-both-renamed-side-2.txt",
+ "7-both-renamed.txt"
+ }
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+
+ create_index(checkout_index_entries, 41);
+ create_index_names(checkout_name_entries, 9);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir("0a-no-change.txt",
+ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e");
+
+ ensure_workdir("0b-duplicated-in-ours.txt",
+ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6");
+
+ ensure_workdir("0b-rewritten-in-ours.txt",
+ 0100644, "4c7e515d6d52d820496858f2f059ece69e99e2e3");
+
+ ensure_workdir("0c-duplicated-in-theirs.txt",
+ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31");
+
+ ensure_workdir("0c-rewritten-in-theirs.txt",
+ 0100644, "4648d658682d1155c2a3db5b0c53305e26884ea5");
+
+ ensure_workdir("1a-newname-in-ours-edited-in-theirs.txt",
+ 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638");
+
+ ensure_workdir("1a-newname-in-ours.txt",
+ 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb");
+
+ ensure_workdir("1b-newname-in-theirs-edited-in-ours.txt",
+ 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a");
+
+ ensure_workdir("1b-newname-in-theirs.txt",
+ 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136");
+
+ ensure_workdir("2-newname-in-both.txt",
+ 0100644, "178940b450f238a56c0d75b7955cb57b38191982");
+
+ ensure_workdir("3a-newname-in-ours-deleted-in-theirs.txt",
+ 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9");
+
+ ensure_workdir("3b-newname-in-theirs-deleted-in-ours.txt",
+ 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495");
+
+ ensure_workdir("4a-newname-in-ours-added-in-theirs.txt~ours",
+ 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c");
+
+ ensure_workdir("4a-newname-in-ours-added-in-theirs.txt~theirs",
+ 0100644, "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a");
+
+ ensure_workdir("4b-newname-in-theirs-added-in-ours.txt~ours",
+ 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9");
+
+ ensure_workdir("4b-newname-in-theirs-added-in-ours.txt~theirs",
+ 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db");
+
+ ensure_workdir("5a-newname-in-ours-added-in-theirs.txt~ours",
+ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436");
+
+ ensure_workdir("5a-newname-in-ours-added-in-theirs.txt~theirs",
+ 0100644, "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714");
+
+ ensure_workdir("5b-newname-in-theirs-added-in-ours.txt~ours",
+ 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced");
+
+ ensure_workdir("5b-newname-in-theirs-added-in-ours.txt~theirs",
+ 0100644, "63247125386de9ec90a27ad36169307bf8a11a38");
+
+ ensure_workdir("6-both-renamed-1-to-2-ours.txt",
+ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450");
+
+ ensure_workdir("6-both-renamed-1-to-2-theirs.txt",
+ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450");
+
+ ensure_workdir("7-both-renamed.txt~ours",
+ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11");
+
+ ensure_workdir("7-both-renamed.txt~theirs",
+ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07");
+}
+
+void test_checkout_conflict__rename_keep_ours(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
+ { 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" },
+ { 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 1, "0b-rewritten-in-ours.txt" },
+ { 0100644, "e376fbdd06ebf021c92724da9f26f44212734e3e", 2, "0b-rewritten-in-ours.txt" },
+ { 0100644, "b2d399ae15224e1d58066e3c8df70ce37de7a656", 3, "0b-rewritten-in-ours.txt" },
+ { 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-duplicated-in-theirs.txt" },
+ { 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 1, "0c-rewritten-in-theirs.txt" },
+ { 0100644, "efc9121fdedaf08ba180b53ebfbcf71bd488ed09", 2, "0c-rewritten-in-theirs.txt" },
+ { 0100644, "712ebba6669ea847d9829e4f1059d6c830c8b531", 3, "0c-rewritten-in-theirs.txt" },
+ { 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638", 0, "1a-newname-in-ours-edited-in-theirs.txt" },
+ { 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-newname-in-ours.txt" },
+ { 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a", 0, "1b-newname-in-theirs-edited-in-ours.txt" },
+ { 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-newname-in-theirs.txt" },
+ { 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" },
+ { 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 2, "3a-newname-in-ours-deleted-in-theirs.txt" },
+ { 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 1, "3a-renamed-in-ours-deleted-in-theirs.txt" },
+ { 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 3, "3b-newname-in-theirs-deleted-in-ours.txt" },
+ { 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 1, "3b-renamed-in-theirs-deleted-in-ours.txt" },
+ { 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 2, "4a-newname-in-ours-added-in-theirs.txt" },
+ { 0100644, "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a", 3, "4a-newname-in-ours-added-in-theirs.txt" },
+ { 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 1, "4a-renamed-in-ours-added-in-theirs.txt" },
+ { 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9", 2, "4b-newname-in-theirs-added-in-ours.txt" },
+ { 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 3, "4b-newname-in-theirs-added-in-ours.txt" },
+ { 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 1, "4b-renamed-in-theirs-added-in-ours.txt" },
+ { 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 2, "5a-newname-in-ours-added-in-theirs.txt" },
+ { 0100644, "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714", 3, "5a-newname-in-ours-added-in-theirs.txt" },
+ { 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 1, "5a-renamed-in-ours-added-in-theirs.txt" },
+ { 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 3, "5a-renamed-in-ours-added-in-theirs.txt" },
+ { 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced", 2, "5b-newname-in-theirs-added-in-ours.txt" },
+ { 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 3, "5b-newname-in-theirs-added-in-ours.txt" },
+ { 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 1, "5b-renamed-in-theirs-added-in-ours.txt" },
+ { 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 2, "5b-renamed-in-theirs-added-in-ours.txt" },
+ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 2, "6-both-renamed-1-to-2-ours.txt" },
+ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 3, "6-both-renamed-1-to-2-theirs.txt" },
+ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 1, "6-both-renamed-1-to-2.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 1, "7-both-renamed-side-1.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 3, "7-both-renamed-side-1.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 1, "7-both-renamed-side-2.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 2, "7-both-renamed-side-2.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 2, "7-both-renamed.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "7-both-renamed.txt" }
+ };
+
+ struct checkout_name_entry checkout_name_entries[] = {
+ {
+ "3a-renamed-in-ours-deleted-in-theirs.txt",
+ "3a-newname-in-ours-deleted-in-theirs.txt",
+ ""
+ },
+
+ {
+ "3b-renamed-in-theirs-deleted-in-ours.txt",
+ "",
+ "3b-newname-in-theirs-deleted-in-ours.txt"
+ },
+
+ {
+ "4a-renamed-in-ours-added-in-theirs.txt",
+ "4a-newname-in-ours-added-in-theirs.txt",
+ ""
+ },
+
+ {
+ "4b-renamed-in-theirs-added-in-ours.txt",
+ "",
+ "4b-newname-in-theirs-added-in-ours.txt"
+ },
+
+ {
+ "5a-renamed-in-ours-added-in-theirs.txt",
+ "5a-newname-in-ours-added-in-theirs.txt",
+ "5a-renamed-in-ours-added-in-theirs.txt"
+ },
+
+ {
+ "5b-renamed-in-theirs-added-in-ours.txt",
+ "5b-renamed-in-theirs-added-in-ours.txt",
+ "5b-newname-in-theirs-added-in-ours.txt"
+ },
+
+ {
+ "6-both-renamed-1-to-2.txt",
+ "6-both-renamed-1-to-2-ours.txt",
+ "6-both-renamed-1-to-2-theirs.txt"
+ },
+
+ {
+ "7-both-renamed-side-1.txt",
+ "7-both-renamed.txt",
+ "7-both-renamed-side-1.txt"
+ },
+
+ {
+ "7-both-renamed-side-2.txt",
+ "7-both-renamed-side-2.txt",
+ "7-both-renamed.txt"
+ }
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS;
+
+ create_index(checkout_index_entries, 41);
+ create_index_names(checkout_name_entries, 9);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir("0a-no-change.txt",
+ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e");
+
+ ensure_workdir("0b-duplicated-in-ours.txt",
+ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6");
+
+ ensure_workdir("0b-rewritten-in-ours.txt",
+ 0100644, "e376fbdd06ebf021c92724da9f26f44212734e3e");
+
+ ensure_workdir("0c-duplicated-in-theirs.txt",
+ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31");
+
+ ensure_workdir("0c-rewritten-in-theirs.txt",
+ 0100644, "efc9121fdedaf08ba180b53ebfbcf71bd488ed09");
+
+ ensure_workdir("1a-newname-in-ours-edited-in-theirs.txt",
+ 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638");
+
+ ensure_workdir("1a-newname-in-ours.txt",
+ 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb");
+
+ ensure_workdir("1b-newname-in-theirs-edited-in-ours.txt",
+ 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a");
+
+ ensure_workdir("1b-newname-in-theirs.txt",
+ 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136");
+
+ ensure_workdir("2-newname-in-both.txt",
+ 0100644, "178940b450f238a56c0d75b7955cb57b38191982");
+
+ ensure_workdir("3a-newname-in-ours-deleted-in-theirs.txt",
+ 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9");
+
+ ensure_workdir("3b-newname-in-theirs-deleted-in-ours.txt",
+ 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495");
+
+ ensure_workdir("4a-newname-in-ours-added-in-theirs.txt",
+ 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c");
+
+ ensure_workdir("4b-newname-in-theirs-added-in-ours.txt",
+ 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9");
+
+ ensure_workdir("5a-newname-in-ours-added-in-theirs.txt",
+ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436");
+
+ ensure_workdir("5b-newname-in-theirs-added-in-ours.txt",
+ 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced");
+
+ ensure_workdir("6-both-renamed-1-to-2-ours.txt",
+ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450");
+
+ ensure_workdir("7-both-renamed.txt",
+ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11");
+}
+
+void test_checkout_conflict__name_mangled_file_exists_in_workdir(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 1, "test-one-side-one.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 3, "test-one-side-one.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 1, "test-one-side-two.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 2, "test-one-side-two.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 2, "test-one.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "test-one.txt" },
+
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 1, "test-two-side-one.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 3, "test-two-side-one.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 1, "test-two-side-two.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 2, "test-two-side-two.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 2, "test-two.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "test-two.txt" },
+
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 1, "test-three-side-one.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 3, "test-three-side-one.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 1, "test-three-side-two.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 2, "test-three-side-two.txt" },
+ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 2, "test-three.txt" },
+ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "test-three.txt" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "directory_file-one" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "directory_file-one" },
+ { 0100644, CONFLICTING_THEIRS_OID, 0, "directory_file-one/file" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "directory_file-two" },
+ { 0100644, CONFLICTING_OURS_OID, 0, "directory_file-two/file" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "directory_file-two" },
+ };
+
+ struct checkout_name_entry checkout_name_entries[] = {
+ {
+ "test-one-side-one.txt",
+ "test-one.txt",
+ "test-one-side-one.txt"
+ },
+ {
+ "test-one-side-two.txt",
+ "test-one-side-two.txt",
+ "test-one.txt"
+ },
+
+ {
+ "test-two-side-one.txt",
+ "test-two.txt",
+ "test-two-side-one.txt"
+ },
+ {
+ "test-two-side-two.txt",
+ "test-two-side-two.txt",
+ "test-two.txt"
+ },
+
+ {
+ "test-three-side-one.txt",
+ "test-three.txt",
+ "test-three-side-one.txt"
+ },
+ {
+ "test-three-side-two.txt",
+ "test-three-side-two.txt",
+ "test-three.txt"
+ }
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_SAFE;
+
+ create_index(checkout_index_entries, 24);
+ create_index_names(checkout_name_entries, 6);
+ git_index_write(g_index);
+
+ /* Add some files on disk that conflict with the names that would be chosen
+ * for the files written for each side. */
+
+ cl_git_rewritefile("merge-resolve/test-one.txt~ours",
+ "Expect index contents to be written to ~ours_0");
+ cl_git_rewritefile("merge-resolve/test-one.txt~theirs",
+ "Expect index contents to be written to ~theirs_0");
+
+ cl_git_rewritefile("merge-resolve/test-two.txt~ours",
+ "Expect index contents to be written to ~ours_3");
+ cl_git_rewritefile("merge-resolve/test-two.txt~theirs",
+ "Expect index contents to be written to ~theirs_3");
+ cl_git_rewritefile("merge-resolve/test-two.txt~ours_0",
+ "Expect index contents to be written to ~ours_3");
+ cl_git_rewritefile("merge-resolve/test-two.txt~theirs_0",
+ "Expect index contents to be written to ~theirs_3");
+ cl_git_rewritefile("merge-resolve/test-two.txt~ours_1",
+ "Expect index contents to be written to ~ours_3");
+ cl_git_rewritefile("merge-resolve/test-two.txt~theirs_1",
+ "Expect index contents to be written to ~theirs_3");
+ cl_git_rewritefile("merge-resolve/test-two.txt~ours_2",
+ "Expect index contents to be written to ~ours_3");
+ cl_git_rewritefile("merge-resolve/test-two.txt~theirs_2",
+ "Expect index contents to be written to ~theirs_3");
+
+ cl_git_rewritefile("merge-resolve/test-three.txt~Ours",
+ "Expect case insensitive filesystems to create ~ours_0");
+ cl_git_rewritefile("merge-resolve/test-three.txt~THEIRS",
+ "Expect case insensitive filesystems to create ~theirs_0");
+
+ cl_git_rewritefile("merge-resolve/directory_file-one~ours",
+ "Index contents written to ~ours_0 in this D/F conflict");
+ cl_git_rewritefile("merge-resolve/directory_file-two~theirs",
+ "Index contents written to ~theirs_0 in this D/F conflict");
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir("test-one.txt~ours_0",
+ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11");
+ ensure_workdir("test-one.txt~theirs_0",
+ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07");
+
+ ensure_workdir("test-two.txt~ours_3",
+ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11");
+ ensure_workdir("test-two.txt~theirs_3",
+ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07");
+
+ /* Name is mangled on case insensitive only */
+#if defined(GIT_WIN32) || defined(__APPLE__)
+ ensure_workdir("test-three.txt~ours_0",
+ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11");
+ ensure_workdir("test-three.txt~theirs_0",
+ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07");
+#else
+ ensure_workdir("test-three.txt~ours",
+ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11");
+ ensure_workdir("test-three.txt~theirs",
+ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07");
+#endif
+
+ ensure_workdir("directory_file-one~ours_0", 0100644, CONFLICTING_OURS_OID);
+ ensure_workdir("directory_file-two~theirs_0", 0100644, CONFLICTING_THEIRS_OID);
+}
+
+void test_checkout_conflict__update_only(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, AUTOMERGEABLE_ANCESTOR_OID, 1, "automergeable.txt" },
+ { 0100644, AUTOMERGEABLE_OURS_OID, 2, "automergeable.txt" },
+ { 0100644, AUTOMERGEABLE_THEIRS_OID, 3, "automergeable.txt" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "modify-delete" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "modify-delete" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "directory_file-one" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "directory_file-one" },
+ { 0100644, CONFLICTING_THEIRS_OID, 0, "directory_file-one/file" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "directory_file-two" },
+ { 0100644, CONFLICTING_OURS_OID, 0, "directory_file-two/file" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "directory_file-two" },
+ };
+
+ opts.checkout_strategy |= GIT_CHECKOUT_UPDATE_ONLY;
+
+ create_index(checkout_index_entries, 3);
+ git_index_write(g_index);
+
+ cl_git_pass(p_mkdir("merge-resolve/directory_file-two", 0777));
+ cl_git_rewritefile("merge-resolve/directory_file-two/file", CONFLICTING_OURS_FILE);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir_contents("automergeable.txt", AUTOMERGEABLE_MERGED_FILE);
+ ensure_workdir("directory_file-two/file", 0100644, CONFLICTING_OURS_OID);
+
+ cl_assert(!git_path_exists("merge-resolve/modify-delete"));
+ cl_assert(!git_path_exists("merge-resolve/test-one.txt"));
+ cl_assert(!git_path_exists("merge-resolve/test-one-side-one.txt"));
+ cl_assert(!git_path_exists("merge-resolve/test-one-side-two.txt"));
+ cl_assert(!git_path_exists("merge-resolve/test-one.txt~ours"));
+ cl_assert(!git_path_exists("merge-resolve/test-one.txt~theirs"));
+ cl_assert(!git_path_exists("merge-resolve/directory_file-one/file"));
+ cl_assert(!git_path_exists("merge-resolve/directory_file-one~ours"));
+ cl_assert(!git_path_exists("merge-resolve/directory_file-two~theirs"));
+}
+
+void test_checkout_conflict__path_filters(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ char *paths[] = { "conflicting-1.txt", "conflicting-3.txt" };
+ git_strarray patharray = {0};
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "conflicting-1.txt" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "conflicting-1.txt" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "conflicting-1.txt" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "conflicting-2.txt" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "conflicting-2.txt" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "conflicting-2.txt" },
+
+ { 0100644, AUTOMERGEABLE_ANCESTOR_OID, 1, "conflicting-3.txt" },
+ { 0100644, AUTOMERGEABLE_OURS_OID, 2, "conflicting-3.txt" },
+ { 0100644, AUTOMERGEABLE_THEIRS_OID, 3, "conflicting-3.txt" },
+
+ { 0100644, AUTOMERGEABLE_ANCESTOR_OID, 1, "conflicting-4.txt" },
+ { 0100644, AUTOMERGEABLE_OURS_OID, 2, "conflicting-4.txt" },
+ { 0100644, AUTOMERGEABLE_THEIRS_OID, 3, "conflicting-4.txt" },
+ };
+
+ patharray.count = 2;
+ patharray.strings = paths;
+
+ opts.paths = patharray;
+
+ create_index(checkout_index_entries, 12);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ ensure_workdir_contents("conflicting-1.txt", CONFLICTING_DIFF3_FILE);
+ cl_assert(!git_path_exists("merge-resolve/conflicting-2.txt"));
+ ensure_workdir_contents("conflicting-3.txt", AUTOMERGEABLE_MERGED_FILE);
+ cl_assert(!git_path_exists("merge-resolve/conflicting-4.txt"));
+}
+
+static void collect_progress(
+ const char *path,
+ size_t completed_steps,
+ size_t total_steps,
+ void *payload)
+{
+ git_vector *paths = payload;
+
+ if (path == NULL)
+ return;
+
+ git_vector_insert(paths, strdup(path));
+}
+
+void test_checkout_conflict__report_progress(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_vector paths = GIT_VECTOR_INIT;
+ char *path;
+ size_t i;
+
+ struct checkout_index_entry checkout_index_entries[] = {
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "conflicting-1.txt" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "conflicting-1.txt" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "conflicting-1.txt" },
+
+ { 0100644, CONFLICTING_ANCESTOR_OID, 1, "conflicting-2.txt" },
+ { 0100644, CONFLICTING_OURS_OID, 2, "conflicting-2.txt" },
+ { 0100644, CONFLICTING_THEIRS_OID, 3, "conflicting-2.txt" },
+
+ { 0100644, AUTOMERGEABLE_ANCESTOR_OID, 1, "conflicting-3.txt" },
+ { 0100644, AUTOMERGEABLE_OURS_OID, 2, "conflicting-3.txt" },
+ { 0100644, AUTOMERGEABLE_THEIRS_OID, 3, "conflicting-3.txt" },
+
+ { 0100644, AUTOMERGEABLE_ANCESTOR_OID, 1, "conflicting-4.txt" },
+ { 0100644, AUTOMERGEABLE_OURS_OID, 2, "conflicting-4.txt" },
+ { 0100644, AUTOMERGEABLE_THEIRS_OID, 3, "conflicting-4.txt" },
+ };
+
+ opts.progress_cb = collect_progress;
+ opts.progress_payload = &paths;
+
+
+ create_index(checkout_index_entries, 12);
+ git_index_write(g_index);
+
+ cl_git_pass(git_checkout_index(g_repo, g_index, &opts));
+
+ cl_assert_equal_i(4, git_vector_length(&paths));
+ cl_assert_equal_s("conflicting-1.txt", git_vector_get(&paths, 0));
+ cl_assert_equal_s("conflicting-2.txt", git_vector_get(&paths, 1));
+ cl_assert_equal_s("conflicting-3.txt", git_vector_get(&paths, 2));
+ cl_assert_equal_s("conflicting-4.txt", git_vector_get(&paths, 3));
+
+ git_vector_foreach(&paths, i, path)
+ git__free(path);
+
+ git_vector_free(&paths);
+}
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index 73050d08e..48d6d79f9 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -224,13 +224,15 @@ void test_checkout_index__options_disable_filters(void)
void test_checkout_index__options_dir_modes(void)
{
-#ifndef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
git_oid oid;
git_commit *commit;
mode_t um;
+ if (!cl_is_chmod_supported())
+ return;
+
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
@@ -252,15 +254,16 @@ void test_checkout_index__options_dir_modes(void)
cl_assert_equal_i_fmt(st.st_mode, GIT_FILEMODE_BLOB_EXECUTABLE, "%07o");
git_commit_free(commit);
-#endif
}
void test_checkout_index__options_override_file_modes(void)
{
-#ifndef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
+ if (!cl_is_chmod_supported())
+ return;
+
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
opts.file_mode = 0700;
@@ -268,7 +271,6 @@ void test_checkout_index__options_override_file_modes(void)
cl_git_pass(p_stat("./testrepo/new.txt", &st));
cl_assert_equal_i_fmt(st.st_mode & GIT_MODE_PERMS_MASK, 0700, "%07o");
-#endif
}
void test_checkout_index__options_open_flags(void)
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
index fff530cdd..66b01bc7f 100644
--- a/tests-clar/checkout/tree.c
+++ b/tests-clar/checkout/tree.c
@@ -696,3 +696,47 @@ void test_checkout_tree__extremely_long_file_name(void)
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_assert(!git_path_exists(path));
}
+
+static void create_conflict(void)
+{
+ git_index *index;
+ git_index_entry entry;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ memset(&entry, 0x0, sizeof(git_index_entry));
+ entry.mode = 0100644;
+ entry.flags = 1 << GIT_IDXENTRY_STAGESHIFT;
+ git_oid_fromstr(&entry.oid, "d427e0b2e138501a3d15cc376077a3631e15bd46");
+ entry.path = "conflicts.txt";
+ cl_git_pass(git_index_add(index, &entry));
+
+ entry.flags = 2 << GIT_IDXENTRY_STAGESHIFT;
+ git_oid_fromstr(&entry.oid, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
+ cl_git_pass(git_index_add(index, &entry));
+
+ entry.flags = 3 << GIT_IDXENTRY_STAGESHIFT;
+ git_oid_fromstr(&entry.oid, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
+ cl_git_pass(git_index_add(index, &entry));
+
+ git_index_write(index);
+ git_index_free(index);
+}
+
+void test_checkout_tree__fails_when_conflicts_exist_in_index(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_oid oid;
+ git_object *obj = NULL;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ cl_git_pass(git_reference_name_to_id(&oid, g_repo, "HEAD"));
+ cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
+
+ create_conflict();
+
+ cl_git_fail(git_checkout_tree(g_repo, obj, &opts));
+
+ git_object_free(obj);
+}
diff --git a/tests-clar/clar_libgit2.c b/tests-clar/clar_libgit2.c
index 6063bf91c..50762cdb8 100644
--- a/tests-clar/clar_libgit2.c
+++ b/tests-clar/clar_libgit2.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "posix.h"
#include "path.h"
+#include "git2/sys/repository.h"
void cl_git_report_failure(
int error, const char *file, int line, const char *fncall)
@@ -190,6 +191,9 @@ git_repository *cl_git_sandbox_init(const char *sandbox)
/* Now open the sandbox repository and make it available for tests */
cl_git_pass(git_repository_open(&_cl_repo, sandbox));
+ /* Adjust configs after copying to new filesystem */
+ cl_git_pass(git_repository_reinit_filesystem(_cl_repo, 0));
+
return _cl_repo;
}
@@ -301,7 +305,7 @@ static int remove_placeholders_recurs(void *_data, git_buf *path)
size_t pathlen;
if (git_path_isdir(path->ptr) == true)
- return git_path_direach(path, remove_placeholders_recurs, data);
+ return git_path_direach(path, 0, remove_placeholders_recurs, data);
pathlen = path->size;
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index 4bcb5be1e..071e3d09f 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -56,41 +56,18 @@ void test_clone_nonetwork__bad_url(void)
cl_assert(!git_path_exists("./foo"));
}
-static int dont_call_me(void *state, git_buf *path)
-{
- GIT_UNUSED(state);
- GIT_UNUSED(path);
- return GIT_ERROR;
-}
-
void test_clone_nonetwork__do_not_clean_existing_directory(void)
{
- git_buf path_buf = GIT_BUF_INIT;
-
- git_buf_put(&path_buf, "./foo", 5);
-
/* Clone should not remove the directory if it already exists, but
* Should clean up entries it creates. */
p_mkdir("./foo", GIT_DIR_MODE);
cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
- cl_assert(git_path_exists("./foo"));
-
- /* Make sure the directory is empty. */
- cl_git_pass(git_path_direach(&path_buf,
- dont_call_me,
- NULL));
+ cl_assert(git_path_is_empty_dir("./foo"));
/* Try again with a bare repository. */
g_options.bare = true;
cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options));
- cl_assert(git_path_exists("./foo"));
-
- /* Make sure the directory is empty. */
- cl_git_pass(git_path_direach(&path_buf,
- dont_call_me,
- NULL));
-
- git_buf_free(&path_buf);
+ cl_assert(git_path_is_empty_dir("./foo"));
}
void test_clone_nonetwork__local(void)
diff --git a/tests-clar/core/dirent.c b/tests-clar/core/dirent.c
index 5a7859d1b..f17260362 100644
--- a/tests-clar/core/dirent.c
+++ b/tests-clar/core/dirent.c
@@ -88,14 +88,6 @@ static int one_entry(void *state, git_buf *path)
return GIT_ERROR;
}
-static int dont_call_me(void *state, git_buf *path)
-{
- GIT_UNUSED(state);
- GIT_UNUSED(path);
- return GIT_ERROR;
-}
-
-
static name_data dot_names[] = {
{ 0, "./a" },
@@ -115,9 +107,7 @@ void test_core_dirent__dont_traverse_dot(void)
cl_set_cleanup(&dirent_cleanup__cb, &dot);
setup(&dot);
- cl_git_pass(git_path_direach(&dot.path,
- one_entry,
- &dot));
+ cl_git_pass(git_path_direach(&dot.path, 0, one_entry, &dot));
check_counts(&dot);
}
@@ -141,9 +131,7 @@ void test_core_dirent__traverse_subfolder(void)
cl_set_cleanup(&dirent_cleanup__cb, &sub);
setup(&sub);
- cl_git_pass(git_path_direach(&sub.path,
- one_entry,
- &sub));
+ cl_git_pass(git_path_direach(&sub.path, 0, one_entry, &sub));
check_counts(&sub);
}
@@ -161,9 +149,7 @@ void test_core_dirent__traverse_slash_terminated_folder(void)
cl_set_cleanup(&dirent_cleanup__cb, &sub_slash);
setup(&sub_slash);
- cl_git_pass(git_path_direach(&sub_slash.path,
- one_entry,
- &sub_slash));
+ cl_git_pass(git_path_direach(&sub_slash.path, 0, one_entry, &sub_slash));
check_counts(&sub_slash);
}
@@ -184,16 +170,12 @@ void test_core_dirent__dont_traverse_empty_folders(void)
cl_set_cleanup(&dirent_cleanup__cb, &empty);
setup(&empty);
- cl_git_pass(git_path_direach(&empty.path,
- one_entry,
- &empty));
+ cl_git_pass(git_path_direach(&empty.path, 0, one_entry, &empty));
check_counts(&empty);
/* make sure callback not called */
- cl_git_pass(git_path_direach(&empty.path,
- dont_call_me,
- &empty));
+ cl_assert(git_path_is_empty_dir(empty.path.ptr));
}
static name_data odd_names[] = {
@@ -216,9 +198,7 @@ void test_core_dirent__traverse_weird_filenames(void)
cl_set_cleanup(&dirent_cleanup__cb, &odd);
setup(&odd);
- cl_git_pass(git_path_direach(&odd.path,
- one_entry,
- &odd));
+ cl_git_pass(git_path_direach(&odd.path, 0, one_entry, &odd));
check_counts(&odd);
}
@@ -231,5 +211,26 @@ void test_core_dirent__length_limits(void)
big_filename[FILENAME_MAX] = 0;
cl_must_fail(p_creat(big_filename, 0666));
+
git__free(big_filename);
}
+
+void test_core_dirent__empty_dir(void)
+{
+ cl_must_pass(p_mkdir("empty_dir", 0777));
+ cl_assert(git_path_is_empty_dir("empty_dir"));
+
+ cl_git_mkfile("empty_dir/content", "whatever\n");
+ cl_assert(!git_path_is_empty_dir("empty_dir"));
+ cl_assert(!git_path_is_empty_dir("empty_dir/content"));
+
+ cl_must_pass(p_unlink("empty_dir/content"));
+
+ cl_must_pass(p_mkdir("empty_dir/content", 0777));
+ cl_assert(!git_path_is_empty_dir("empty_dir"));
+ cl_assert(git_path_is_empty_dir("empty_dir/content"));
+
+ cl_must_pass(p_rmdir("empty_dir/content"));
+
+ cl_must_pass(p_rmdir("empty_dir"));
+}
diff --git a/tests-clar/core/iconv.c b/tests-clar/core/iconv.c
new file mode 100644
index 000000000..73bc99a23
--- /dev/null
+++ b/tests-clar/core/iconv.c
@@ -0,0 +1,60 @@
+#include "clar_libgit2.h"
+#include "path.h"
+
+static git_path_iconv_t ic;
+static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
+static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
+
+void test_core_iconv__initialize(void)
+{
+ cl_git_pass(git_path_iconv_init_precompose(&ic));
+}
+
+void test_core_iconv__cleanup(void)
+{
+ git_path_iconv_clear(&ic);
+}
+
+void test_core_iconv__unchanged(void)
+{
+ char *data = "Ascii data", *original = data;
+ size_t datalen = strlen(data);
+
+ cl_git_pass(git_path_iconv(&ic, &data, &datalen));
+ GIT_UNUSED(datalen);
+
+ /* There are no high bits set, so this should leave data untouched */
+ cl_assert(data == original);
+}
+
+void test_core_iconv__decomposed_to_precomposed(void)
+{
+ char *data = nfd;
+ size_t datalen = strlen(nfd);
+
+ cl_git_pass(git_path_iconv(&ic, &data, &datalen));
+ GIT_UNUSED(datalen);
+
+ /* The decomposed nfd string should be transformed to the nfc form
+ * (on platforms where iconv is enabled, of course).
+ */
+#ifdef GIT_USE_ICONV
+ cl_assert_equal_s(nfc, data);
+#else
+ cl_assert_equal_s(nfd, data);
+#endif
+}
+
+void test_core_iconv__precomposed_is_unmodified(void)
+{
+ char *data = nfc;
+ size_t datalen = strlen(nfc);
+
+ cl_git_pass(git_path_iconv(&ic, &data, &datalen));
+ GIT_UNUSED(datalen);
+
+ /* data is already in precomposed form, so even though some bytes have
+ * the high-bit set, the iconv transform should result in no change.
+ */
+ cl_assert_equal_s(nfc, data);
+}
diff --git a/tests-clar/core/mkdir.c b/tests-clar/core/mkdir.c
index a969e4de2..a8c5b10ae 100644
--- a/tests-clar/core/mkdir.c
+++ b/tests-clar/core/mkdir.c
@@ -111,14 +111,20 @@ static void cleanup_chmod_root(void *ref)
git_futils_rmdir_r("r", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
}
-static void check_mode(mode_t expected, mode_t actual)
+#define check_mode(X,A) check_mode_at_line((X), (A), __FILE__, __LINE__)
+
+static void check_mode_at_line(
+ mode_t expected, mode_t actual, const char *file, int line)
{
-#ifdef GIT_WIN32
- /* chmod on Win32 doesn't support exec bit, not group/world bits */
- cl_assert_equal_i_fmt((expected & 0600), (actual & 0777), "%07o");
-#else
- cl_assert_equal_i_fmt(expected, (actual & 0777), "%07o");
-#endif
+ /* FAT filesystems don't support exec bit, nor group/world bits */
+ if (!cl_is_chmod_supported()) {
+ expected &= 0600;
+ actual &= 0600;
+ }
+
+ clar__assert_equal(
+ file, line, "expected_mode != actual_mode", 1,
+ "%07o", (int)expected, (int)(actual & 0777));
}
void test_core_mkdir__chmods(void)
diff --git a/tests-clar/core/path.c b/tests-clar/core/path.c
index e584d6115..cf2d5e944 100644
--- a/tests-clar/core/path.c
+++ b/tests-clar/core/path.c
@@ -1,5 +1,5 @@
#include "clar_libgit2.h"
-#include <fileops.h>
+#include "fileops.h"
static void
check_dirname(const char *A, const char *B)
diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c
index 42b9fcd5f..b51bc0f38 100644
--- a/tests-clar/diff/blob.c
+++ b/tests-clar/diff/blob.c
@@ -142,7 +142,7 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
{
git_blob *a, *b, *c;
git_oid a_oid, b_oid, c_oid;
- git_diff_patch *p;
+ git_patch *p;
const git_diff_delta *delta;
size_t tc, ta, td;
@@ -161,11 +161,11 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
/* Doing the equivalent of a `git diff -U1` on these files */
/* diff on tests/resources/attr/root_test1 */
- cl_git_pass(git_diff_patch_from_blobs(&p, a, NULL, b, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, a, NULL, b, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
@@ -173,22 +173,22 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(b), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(b), delta->new_file.size);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(6, git_diff_patch_num_lines_in_hunk(p, 0));
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(6, git_patch_num_lines_in_hunk(p, 0));
- cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
+ cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(1, (int)tc);
cl_assert_equal_i(5, (int)ta);
cl_assert_equal_i(0, (int)td);
- git_diff_patch_free(p);
+ git_patch_free(p);
/* diff on tests/resources/attr/root_test2 */
- cl_git_pass(git_diff_patch_from_blobs(&p, b, NULL, c, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, b, NULL, c, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
cl_assert(git_oid_equal(git_blob_id(b), &delta->old_file.oid));
@@ -196,22 +196,22 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(15, git_diff_patch_num_lines_in_hunk(p, 0));
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(15, git_patch_num_lines_in_hunk(p, 0));
- cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
+ cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(3, (int)tc);
cl_assert_equal_i(9, (int)ta);
cl_assert_equal_i(3, (int)td);
- git_diff_patch_free(p);
+ git_patch_free(p);
/* diff on tests/resources/attr/root_test3 */
- cl_git_pass(git_diff_patch_from_blobs(&p, a, NULL, c, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, a, NULL, c, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
cl_assert(git_oid_equal(git_blob_id(a), &delta->old_file.oid));
@@ -219,19 +219,19 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(c), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(c), delta->new_file.size);
- cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
+ cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(0, (int)tc);
cl_assert_equal_i(12, (int)ta);
cl_assert_equal_i(1, (int)td);
- git_diff_patch_free(p);
+ git_patch_free(p);
/* one more */
- cl_git_pass(git_diff_patch_from_blobs(&p, c, NULL, d, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, c, NULL, d, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, delta->status);
cl_assert(git_oid_equal(git_blob_id(c), &delta->old_file.oid));
@@ -239,16 +239,16 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
- cl_assert_equal_i(2, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(5, git_diff_patch_num_lines_in_hunk(p, 0));
- cl_assert_equal_i(9, git_diff_patch_num_lines_in_hunk(p, 1));
+ cl_assert_equal_i(2, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(5, git_patch_num_lines_in_hunk(p, 0));
+ cl_assert_equal_i(9, git_patch_num_lines_in_hunk(p, 1));
- cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
+ cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(4, (int)tc);
cl_assert_equal_i(6, (int)ta);
cl_assert_equal_i(4, (int)td);
- git_diff_patch_free(p);
+ git_patch_free(p);
git_blob_free(a);
git_blob_free(b);
@@ -317,16 +317,16 @@ void test_diff_blob__can_compare_against_null_blobs(void)
void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
{
git_blob *e = NULL;
- git_diff_patch *p;
+ git_patch *p;
const git_diff_delta *delta;
- int line;
- char origin;
+ const git_diff_line *line;
+ int l, max_l;
- cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
cl_assert(git_oid_equal(git_blob_id(d), &delta->old_file.oid));
@@ -334,24 +334,24 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
cl_assert(git_oid_iszero(&delta->new_file.oid));
cl_assert_equal_sz(0, delta->new_file.size);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(14, git_diff_patch_num_lines_in_hunk(p, 0));
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(14, git_patch_num_lines_in_hunk(p, 0));
- for (line = 0; line < git_diff_patch_num_lines_in_hunk(p, 0); ++line) {
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, NULL, NULL, NULL, NULL, p, 0, line));
- cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
+ max_l = git_patch_num_lines_in_hunk(p, 0);
+ for (l = 0; l < max_l; ++l) {
+ cl_git_pass(git_patch_get_line_in_hunk(&line, p, 0, l));
+ cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
}
- git_diff_patch_free(p);
+ git_patch_free(p);
opts.flags |= GIT_DIFF_REVERSE;
- cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, d, NULL, e, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
cl_assert(git_oid_iszero(&delta->old_file.oid));
@@ -359,44 +359,44 @@ void test_diff_blob__can_compare_against_null_blobs_with_patch(void)
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
cl_assert_equal_sz(git_blob_rawsize(d), delta->new_file.size);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(14, git_diff_patch_num_lines_in_hunk(p, 0));
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(14, git_patch_num_lines_in_hunk(p, 0));
- for (line = 0; line < git_diff_patch_num_lines_in_hunk(p, 0); ++line) {
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, NULL, NULL, NULL, NULL, p, 0, line));
- cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
+ max_l = git_patch_num_lines_in_hunk(p, 0);
+ for (l = 0; l < max_l; ++l) {
+ cl_git_pass(git_patch_get_line_in_hunk(&line, p, 0, l));
+ cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
}
- git_diff_patch_free(p);
+ git_patch_free(p);
opts.flags ^= GIT_DIFF_REVERSE;
- cl_git_pass(git_diff_patch_from_blobs(&p, alien, NULL, NULL, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, alien, NULL, NULL, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
- cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
+ cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
- git_diff_patch_free(p);
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blobs(&p, NULL, NULL, alien, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, NULL, NULL, alien, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_ADDED, delta->status);
cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
- cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
+ cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
- git_diff_patch_free(p);
+ git_patch_free(p);
}
static void assert_identical_blobs_comparison(diff_expects *expected)
@@ -437,13 +437,13 @@ void test_diff_blob__can_compare_identical_blobs(void)
void test_diff_blob__can_compare_identical_blobs_with_patch(void)
{
- git_diff_patch *p;
+ git_patch *p;
const git_diff_delta *delta;
- cl_git_pass(git_diff_patch_from_blobs(&p, d, NULL, d, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, d, NULL, d, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
cl_assert_equal_sz(delta->old_file.size, git_blob_rawsize(d));
@@ -451,13 +451,13 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
cl_assert_equal_sz(delta->new_file.size, git_blob_rawsize(d));
cl_assert(git_oid_equal(git_blob_id(d), &delta->new_file.oid));
- cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
- git_diff_patch_free(p);
+ cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blobs(&p, NULL, NULL, NULL, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, NULL, NULL, NULL, NULL, &opts));
cl_assert(p != NULL);
- delta = git_diff_patch_delta(p);
+ delta = git_patch_get_delta(p);
cl_assert(delta != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, delta->status);
cl_assert_equal_sz(0, delta->old_file.size);
@@ -465,14 +465,14 @@ void test_diff_blob__can_compare_identical_blobs_with_patch(void)
cl_assert_equal_sz(0, delta->new_file.size);
cl_assert(git_oid_iszero(&delta->new_file.oid));
- cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
- git_diff_patch_free(p);
+ cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blobs(&p, alien, NULL, alien, NULL, &opts));
+ cl_git_pass(git_patch_from_blobs(&p, alien, NULL, alien, NULL, &opts));
cl_assert(p != NULL);
- cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_diff_patch_delta(p)->status);
- cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
- git_diff_patch_free(p);
+ cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_patch_get_delta(p)->status);
+ cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
+ git_patch_free(p);
}
static void assert_binary_blobs_comparison(diff_expects *expected)
@@ -693,7 +693,7 @@ void test_diff_blob__can_compare_blob_to_buffer(void)
void test_diff_blob__can_compare_blob_to_buffer_with_patch(void)
{
- git_diff_patch *p;
+ git_patch *p;
git_blob *a;
git_oid a_oid;
const char *a_content = "Hello from the root\n";
@@ -705,58 +705,58 @@ void test_diff_blob__can_compare_blob_to_buffer_with_patch(void)
cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4));
/* diff from blob a to content of b */
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, a, NULL, b_content, strlen(b_content), NULL, &opts));
cl_assert(p != NULL);
- cl_assert_equal_i(GIT_DELTA_MODIFIED, git_diff_patch_delta(p)->status);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(6, git_diff_patch_num_lines_in_hunk(p, 0));
+ cl_assert_equal_i(GIT_DELTA_MODIFIED, git_patch_get_delta(p)->status);
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(6, git_patch_num_lines_in_hunk(p, 0));
- cl_git_pass(git_diff_patch_line_stats(&tc, &ta, &td, p));
+ cl_git_pass(git_patch_line_stats(&tc, &ta, &td, p));
cl_assert_equal_i(1, (int)tc);
cl_assert_equal_i(5, (int)ta);
cl_assert_equal_i(0, (int)td);
- git_diff_patch_free(p);
+ git_patch_free(p);
/* diff from blob a to content of a */
opts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED;
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, a, NULL, a_content, strlen(a_content), NULL, &opts));
cl_assert(p != NULL);
- cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_diff_patch_delta(p)->status);
- cl_assert_equal_i(0, (int)git_diff_patch_num_hunks(p));
- git_diff_patch_free(p);
+ cl_assert_equal_i(GIT_DELTA_UNMODIFIED, git_patch_get_delta(p)->status);
+ cl_assert_equal_i(0, (int)git_patch_num_hunks(p));
+ git_patch_free(p);
/* diff from NULL blob to content of a */
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, NULL, NULL, a_content, strlen(a_content), NULL, &opts));
cl_assert(p != NULL);
- cl_assert_equal_i(GIT_DELTA_ADDED, git_diff_patch_delta(p)->status);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
- git_diff_patch_free(p);
+ cl_assert_equal_i(GIT_DELTA_ADDED, git_patch_get_delta(p)->status);
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
+ git_patch_free(p);
/* diff from blob a to NULL buffer */
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, a, NULL, NULL, 0, NULL, &opts));
cl_assert(p != NULL);
- cl_assert_equal_i(GIT_DELTA_DELETED, git_diff_patch_delta(p)->status);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
- git_diff_patch_free(p);
+ cl_assert_equal_i(GIT_DELTA_DELETED, git_patch_get_delta(p)->status);
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
+ git_patch_free(p);
/* diff with reverse */
opts.flags ^= GIT_DIFF_REVERSE;
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, a, NULL, NULL, 0, NULL, &opts));
cl_assert(p != NULL);
- cl_assert_equal_i(GIT_DELTA_ADDED, git_diff_patch_delta(p)->status);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(p));
- cl_assert_equal_i(1, git_diff_patch_num_lines_in_hunk(p, 0));
- git_diff_patch_free(p);
+ cl_assert_equal_i(GIT_DELTA_ADDED, git_patch_get_delta(p)->status);
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(p));
+ cl_assert_equal_i(1, git_patch_num_lines_in_hunk(p, 0));
+ git_patch_free(p);
git_blob_free(a);
}
@@ -853,7 +853,7 @@ void test_diff_blob__using_path_and_attributes(void)
"0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n";
size_t bin_len = 33;
const char *changed;
- git_diff_patch *p;
+ git_patch *p;
char *pout;
/* set up custom diff drivers and 'diff' attribute mappings for them */
@@ -950,9 +950,9 @@ void test_diff_blob__using_path_and_attributes(void)
cl_assert_equal_i(3, expected.line_adds);
cl_assert_equal_i(0, expected.line_dels);
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.normal", changed, strlen(changed), NULL, &opts));
- cl_git_pass(git_diff_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.normal b/zzz.normal\n"
"index 45141a7..75b0dbb 100644\n"
@@ -963,21 +963,21 @@ void test_diff_blob__using_path_and_attributes(void)
"+And more\n"
"+Go here\n", pout);
git__free(pout);
- git_diff_patch_free(p);
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.binary", changed, strlen(changed), NULL, &opts));
- cl_git_pass(git_diff_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.binary b/zzz.binary\n"
"index 45141a7..75b0dbb 100644\n"
"Binary files a/zzz.binary and b/zzz.binary differ\n", pout);
git__free(pout);
- git_diff_patch_free(p);
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.alphary", changed, strlen(changed), NULL, &opts));
- cl_git_pass(git_diff_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.alphary b/zzz.alphary\n"
"index 45141a7..75b0dbb 100644\n"
@@ -988,11 +988,11 @@ void test_diff_blob__using_path_and_attributes(void)
"+And more\n"
"+Go here\n", pout);
git__free(pout);
- git_diff_patch_free(p);
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, nonbin, "zzz.numary", changed, strlen(changed), NULL, &opts));
- cl_git_pass(git_diff_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.numary b/zzz.numary\n"
"index 45141a7..75b0dbb 100644\n"
@@ -1003,7 +1003,7 @@ void test_diff_blob__using_path_and_attributes(void)
"+And more\n"
"+Go here\n", pout);
git__free(pout);
- git_diff_patch_free(p);
+ git_patch_free(p);
/* "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\n0123456789\n"
* 33 bytes
@@ -1011,19 +1011,19 @@ void test_diff_blob__using_path_and_attributes(void)
changed = "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\x00\nreplace a line\n";
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.normal", changed, 37, NULL, &opts));
- cl_git_pass(git_diff_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.normal b/zzz.normal\n"
"index b435cd5..1604519 100644\n"
"Binary files a/zzz.normal and b/zzz.normal differ\n", pout);
git__free(pout);
- git_diff_patch_free(p);
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textary", changed, 37, NULL, &opts));
- cl_git_pass(git_diff_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.textary b/zzz.textary\n"
"index b435cd5..1604519 100644\n"
@@ -1033,11 +1033,11 @@ void test_diff_blob__using_path_and_attributes(void)
"-0123456789\n"
"+replace a line\n", pout);
git__free(pout);
- git_diff_patch_free(p);
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textalphary", changed, 37, NULL, &opts));
- cl_git_pass(git_diff_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.textalphary b/zzz.textalphary\n"
"index b435cd5..1604519 100644\n"
@@ -1047,11 +1047,11 @@ void test_diff_blob__using_path_and_attributes(void)
"-0123456789\n"
"+replace a line\n", pout);
git__free(pout);
- git_diff_patch_free(p);
+ git_patch_free(p);
- cl_git_pass(git_diff_patch_from_blob_and_buffer(
+ cl_git_pass(git_patch_from_blob_and_buffer(
&p, bin, "zzz.textnumary", changed, 37, NULL, &opts));
- cl_git_pass(git_diff_patch_to_str(&pout, p));
+ cl_git_pass(git_patch_to_str(&pout, p));
cl_assert_equal_s(
"diff --git a/zzz.textnumary b/zzz.textnumary\n"
"index b435cd5..1604519 100644\n"
@@ -1061,7 +1061,7 @@ void test_diff_blob__using_path_and_attributes(void)
"-0123456789\n"
"+replace a line\n", pout);
git__free(pout);
- git_diff_patch_free(p);
+ git_patch_free(p);
git_blob_free(nonbin);
git_blob_free(bin);
diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c
index a5c322b4d..466d0ef54 100644
--- a/tests-clar/diff/diff_helpers.c
+++ b/tests-clar/diff/diff_helpers.c
@@ -21,6 +21,35 @@ git_tree *resolve_commit_oid_to_tree(
return tree;
}
+static char diff_pick_suffix(int mode)
+{
+ if (S_ISDIR(mode))
+ return '/';
+ else if (GIT_PERMS_IS_EXEC(mode))
+ return '*';
+ else
+ return ' ';
+}
+
+static void fprintf_delta(FILE *fp, const git_diff_delta *delta, float progress)
+{
+ char code = git_diff_status_char(delta->status);
+ char old_suffix = diff_pick_suffix(delta->old_file.mode);
+ char new_suffix = diff_pick_suffix(delta->new_file.mode);
+
+ fprintf(fp, "%c\t%s", code, delta->old_file.path);
+
+ if ((delta->old_file.path != delta->new_file.path &&
+ strcmp(delta->old_file.path, delta->new_file.path) != 0) ||
+ (delta->old_file.mode != delta->new_file.mode &&
+ delta->old_file.mode != 0 && delta->new_file.mode != 0))
+ fprintf(fp, "%c %s%c", old_suffix, delta->new_file.path, new_suffix);
+ else if (old_suffix != ' ')
+ fprintf(fp, "%c", old_suffix);
+
+ fprintf(fp, "\t[%.2f]\n", progress);
+}
+
int diff_file_cb(
const git_diff_delta *delta,
float progress,
@@ -29,9 +58,7 @@ int diff_file_cb(
diff_expects *e = payload;
if (e->debug)
- fprintf(stderr, "%c %s (%.3f)\n",
- git_diff_status_char(delta->status),
- delta->old_file.path, progress);
+ fprintf_delta(stderr, delta, progress);
if (e->names)
cl_assert_equal_s(e->names[e->files], delta->old_file.path);
@@ -55,48 +82,50 @@ int diff_print_file_cb(
float progress,
void *payload)
{
- fprintf(stderr, "%c %s\n",
- git_diff_status_char(delta->status), delta->old_file.path);
+ if (!payload) {
+ fprintf_delta(stderr, delta, progress);
+ return 0;
+ }
+
+ if (!((diff_expects *)payload)->debug)
+ fprintf_delta(stderr, delta, progress);
+
return diff_file_cb(delta, progress, payload);
}
int diff_hunk_cb(
const git_diff_delta *delta,
- const git_diff_range *range,
- const char *header,
- size_t header_len,
+ const git_diff_hunk *hunk,
void *payload)
{
diff_expects *e = payload;
+ const char *scan = hunk->header, *scan_end = scan + hunk->header_len;
GIT_UNUSED(delta);
/* confirm no NUL bytes in header text */
- while (header_len--) cl_assert('\0' != *header++);
+ while (scan < scan_end)
+ cl_assert('\0' != *scan++);
e->hunks++;
- e->hunk_old_lines += range->old_lines;
- e->hunk_new_lines += range->new_lines;
+ e->hunk_old_lines += hunk->old_lines;
+ e->hunk_new_lines += hunk->new_lines;
return 0;
}
int diff_line_cb(
const git_diff_delta *delta,
- const git_diff_range *range,
- char line_origin,
- const char *content,
- size_t content_len,
+ const git_diff_hunk *hunk,
+ const git_diff_line *line,
void *payload)
{
diff_expects *e = payload;
GIT_UNUSED(delta);
- GIT_UNUSED(range);
- GIT_UNUSED(content);
- GIT_UNUSED(content_len);
+ GIT_UNUSED(hunk);
e->lines++;
- switch (line_origin) {
+ switch (line->origin) {
case GIT_DIFF_LINE_CONTEXT:
case GIT_DIFF_LINE_CONTEXT_EOFNL: /* techically not a line */
e->line_ctxt++;
@@ -116,25 +145,25 @@ int diff_line_cb(
}
int diff_foreach_via_iterator(
- git_diff_list *diff,
+ git_diff *diff,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
- git_diff_data_cb line_cb,
+ git_diff_line_cb line_cb,
void *data)
{
size_t d, num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
- git_diff_patch *patch;
+ git_patch *patch;
const git_diff_delta *delta;
size_t h, num_h;
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
- cl_assert(delta);
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
+ cl_assert((delta = git_patch_get_delta(patch)) != NULL);
/* call file_cb for this file */
if (file_cb != NULL && file_cb(delta, (float)d / num_d, data) != 0) {
- git_diff_patch_free(patch);
+ git_patch_free(patch);
goto abort;
}
@@ -146,44 +175,37 @@ int diff_foreach_via_iterator(
}
if (!hunk_cb && !line_cb) {
- git_diff_patch_free(patch);
+ git_patch_free(patch);
continue;
}
- num_h = git_diff_patch_num_hunks(patch);
+ num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
- const git_diff_range *range;
- const char *hdr;
- size_t hdr_len, l, num_l;
+ const git_diff_hunk *hunk;
+ size_t l, num_l;
- cl_git_pass(git_diff_patch_get_hunk(
- &range, &hdr, &hdr_len, &num_l, patch, h));
+ cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h));
- if (hunk_cb && hunk_cb(delta, range, hdr, hdr_len, data) != 0) {
- git_diff_patch_free(patch);
+ if (hunk_cb && hunk_cb(delta, hunk, data) != 0) {
+ git_patch_free(patch);
goto abort;
}
for (l = 0; l < num_l; ++l) {
- char origin;
- const char *line;
- size_t line_len;
- int old_lineno, new_lineno;
+ const git_diff_line *line;
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &line, &line_len, &old_lineno, &new_lineno,
- patch, h, l));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l));
if (line_cb &&
- line_cb(delta, range, origin, line, line_len, data) != 0) {
- git_diff_patch_free(patch);
+ line_cb(delta, hunk, line, data) != 0) {
+ git_patch_free(patch);
goto abort;
}
}
}
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
return 0;
@@ -195,27 +217,26 @@ abort:
static int diff_print_cb(
const git_diff_delta *delta,
- const git_diff_range *range,
- char line_origin, /**< GIT_DIFF_LINE_... value from above */
- const char *content,
- size_t content_len,
+ const git_diff_hunk *hunk,
+ const git_diff_line *line,
void *payload)
{
GIT_UNUSED(payload);
GIT_UNUSED(delta);
- GIT_UNUSED(range);
- GIT_UNUSED(line_origin);
- GIT_UNUSED(content_len);
- fputs(content, (FILE *)payload);
+ GIT_UNUSED(hunk);
+ fprintf((FILE *)payload, "%c%.*s",
+ line->origin, (int)line->content_len, line->content);
return 0;
}
-void diff_print(FILE *fp, git_diff_list *diff)
+void diff_print(FILE *fp, git_diff *diff)
{
- cl_git_pass(git_diff_print_patch(diff, diff_print_cb, fp ? fp : stderr));
+ cl_git_pass(git_diff_print(
+ diff, GIT_DIFF_FORMAT_PATCH, diff_print_cb, fp ? fp : stderr));
}
-void diff_print_raw(FILE *fp, git_diff_list *diff)
+void diff_print_raw(FILE *fp, git_diff *diff)
{
- cl_git_pass(git_diff_print_raw(diff, diff_print_cb, fp ? fp : stderr));
+ cl_git_pass(git_diff_print(
+ diff, GIT_DIFF_FORMAT_RAW, diff_print_cb, fp ? fp : stderr));
}
diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h
index bb76d0076..bf21f4b1f 100644
--- a/tests-clar/diff/diff_helpers.h
+++ b/tests-clar/diff/diff_helpers.h
@@ -44,25 +44,21 @@ extern int diff_print_file_cb(
extern int diff_hunk_cb(
const git_diff_delta *delta,
- const git_diff_range *range,
- const char *header,
- size_t header_len,
+ const git_diff_hunk *hunk,
void *cb_data);
extern int diff_line_cb(
const git_diff_delta *delta,
- const git_diff_range *range,
- char line_origin,
- const char *content,
- size_t content_len,
+ const git_diff_hunk *hunk,
+ const git_diff_line *line,
void *cb_data);
extern int diff_foreach_via_iterator(
- git_diff_list *diff,
+ git_diff *diff,
git_diff_file_cb file_cb,
git_diff_hunk_cb hunk_cb,
- git_diff_data_cb line_cb,
+ git_diff_line_cb line_cb,
void *data);
-extern void diff_print(FILE *fp, git_diff_list *diff);
-extern void diff_print_raw(FILE *fp, git_diff_list *diff);
+extern void diff_print(FILE *fp, git_diff *diff);
+extern void diff_print_raw(FILE *fp, git_diff *diff);
diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c
index 932d720f2..f886e1baa 100644
--- a/tests-clar/diff/diffiter.c
+++ b/tests-clar/diff/diffiter.c
@@ -13,47 +13,48 @@ void test_diff_diffiter__cleanup(void)
void test_diff_diffiter__create(void)
{
git_repository *repo = cl_git_sandbox_init("attr");
- git_diff_list *diff;
+ git_diff *diff;
size_t d, num_d;
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
- const git_diff_delta *delta;
- cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
+ const git_diff_delta *delta = git_diff_get_delta(diff, d);
+ cl_assert(delta != NULL);
}
- git_diff_list_free(diff);
+ cl_assert(!git_diff_get_delta(diff, num_d));
+
+ git_diff_free(diff);
}
-void test_diff_diffiter__iterate_files(void)
+void test_diff_diffiter__iterate_files_1(void)
{
git_repository *repo = cl_git_sandbox_init("attr");
- git_diff_list *diff;
+ git_diff *diff;
size_t d, num_d;
- int count = 0;
+ diff_expects exp = { 0 };
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
num_d = git_diff_num_deltas(diff);
- cl_assert_equal_i(6, (int)num_d);
for (d = 0; d < num_d; ++d) {
- const git_diff_delta *delta;
- cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
+ const git_diff_delta *delta = git_diff_get_delta(diff, d);
cl_assert(delta != NULL);
- count++;
+
+ diff_file_cb(delta, (float)d / (float)num_d, &exp);
}
- cl_assert_equal_i(6, count);
+ cl_assert_equal_sz(6, exp.files);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_diffiter__iterate_files_2(void)
{
git_repository *repo = cl_git_sandbox_init("status");
- git_diff_list *diff;
+ git_diff *diff;
size_t d, num_d;
int count = 0;
@@ -63,21 +64,20 @@ void test_diff_diffiter__iterate_files_2(void)
cl_assert_equal_i(8, (int)num_d);
for (d = 0; d < num_d; ++d) {
- const git_diff_delta *delta;
- cl_git_pass(git_diff_get_patch(NULL, &delta, diff, d));
+ const git_diff_delta *delta = git_diff_get_delta(diff, d);
cl_assert(delta != NULL);
count++;
}
cl_assert_equal_i(8, count);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_diffiter__iterate_files_and_hunks(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
size_t d, num_d;
int file_count = 0, hunk_count = 0;
@@ -90,47 +90,39 @@ void test_diff_diffiter__iterate_files_and_hunks(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
- git_diff_patch *patch;
- const git_diff_delta *delta;
+ git_patch *patch;
size_t h, num_h;
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
-
- cl_assert(delta);
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
cl_assert(patch);
file_count++;
- num_h = git_diff_patch_num_hunks(patch);
+ num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
- const git_diff_range *range;
- const char *header;
- size_t header_len, num_l;
+ const git_diff_hunk *hunk;
- cl_git_pass(git_diff_patch_get_hunk(
- &range, &header, &header_len, &num_l, patch, h));
-
- cl_assert(range);
- cl_assert(header);
+ cl_git_pass(git_patch_get_hunk(&hunk, NULL, patch, h));
+ cl_assert(hunk);
hunk_count++;
}
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
cl_assert_equal_i(13, file_count);
cl_assert_equal_i(8, hunk_count);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_diffiter__max_size_threshold(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
int file_count = 0, binary_count = 0, hunk_count = 0;
size_t d, num_d;
@@ -142,27 +134,28 @@ void test_diff_diffiter__max_size_threshold(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
- git_diff_patch *patch;
+ git_patch *patch;
const git_diff_delta *delta;
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
- cl_assert(delta);
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
cl_assert(patch);
+ delta = git_patch_get_delta(patch);
+ cl_assert(delta);
file_count++;
- hunk_count += (int)git_diff_patch_num_hunks(patch);
+ hunk_count += (int)git_patch_num_hunks(patch);
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
cl_assert_equal_i(13, file_count);
cl_assert_equal_i(0, binary_count);
cl_assert_equal_i(8, hunk_count);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* try again with low file size threshold */
@@ -177,18 +170,19 @@ void test_diff_diffiter__max_size_threshold(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
- git_diff_patch *patch;
+ git_patch *patch;
const git_diff_delta *delta;
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
+ delta = git_patch_get_delta(patch);
file_count++;
- hunk_count += (int)git_diff_patch_num_hunks(patch);
+ hunk_count += (int)git_patch_num_hunks(patch);
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
cl_assert_equal_i(13, file_count);
@@ -200,7 +194,7 @@ void test_diff_diffiter__max_size_threshold(void)
cl_assert_equal_i(3, binary_count);
cl_assert_equal_i(5, hunk_count);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
@@ -208,7 +202,7 @@ void test_diff_diffiter__iterate_all(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp = {0};
size_t d, num_d;
@@ -220,57 +214,51 @@ void test_diff_diffiter__iterate_all(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
- git_diff_patch *patch;
- const git_diff_delta *delta;
+ git_patch *patch;
size_t h, num_h;
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
- cl_assert(patch && delta);
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
+ cl_assert(patch);
exp.files++;
- num_h = git_diff_patch_num_hunks(patch);
+ num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
- const git_diff_range *range;
- const char *header;
- size_t header_len, l, num_l;
+ const git_diff_hunk *range;
+ size_t l, num_l;
- cl_git_pass(git_diff_patch_get_hunk(
- &range, &header, &header_len, &num_l, patch, h));
- cl_assert(range && header);
+ cl_git_pass(git_patch_get_hunk(&range, &num_l, patch, h));
+ cl_assert(range);
exp.hunks++;
for (l = 0; l < num_l; ++l) {
- char origin;
- const char *content;
- size_t content_len;
+ const git_diff_line *line;
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &content, &content_len, NULL, NULL, patch, h, l));
- cl_assert(content);
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l));
+ cl_assert(line && line->content);
exp.lines++;
}
}
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
cl_assert_equal_i(13, exp.files);
cl_assert_equal_i(8, exp.hunks);
cl_assert_equal_i(14, exp.lines);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
-static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp)
+static void iterate_over_patch(git_patch *patch, diff_expects *exp)
{
- size_t h, num_h = git_diff_patch_num_hunks(patch), num_l;
+ size_t h, num_h = git_patch_num_hunks(patch), num_l;
exp->files++;
exp->hunks += (int)num_h;
/* let's iterate in reverse, just because we can! */
for (h = 1, num_l = 0; h <= num_h; ++h)
- num_l += git_diff_patch_num_lines_in_hunk(patch, num_h - h);
+ num_l += git_patch_num_lines_in_hunk(patch, num_h - h);
exp->lines += (int)num_l;
}
@@ -281,9 +269,9 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp = {0};
- git_diff_patch *patches[PATCH_CACHE];
+ git_patch *patches[PATCH_CACHE];
size_t p, d, num_d;
memset(patches, 0, sizeof(patches));
@@ -308,32 +296,32 @@ void test_diff_diffiter__iterate_randomly_while_saving_state(void)
for (d = 0; d < num_d; ++d) {
/* take old patch */
- git_diff_patch *patch = patches[p];
+ git_patch *patch = patches[p];
patches[p] = NULL;
/* cache new patch */
- cl_git_pass(git_diff_get_patch(&patches[p], NULL, diff, d));
+ cl_git_pass(git_patch_from_diff(&patches[p], diff, d));
cl_assert(patches[p] != NULL);
/* process old patch if non-NULL */
if (patch != NULL) {
iterate_over_patch(patch, &exp);
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
p = rand() % PATCH_CACHE;
}
/* free diff list now - refcounts should keep things safe */
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* process remaining unprocessed patches */
for (p = 0; p < PATCH_CACHE; p++) {
- git_diff_patch *patch = patches[p];
+ git_patch *patch = patches[p];
if (patch != NULL) {
iterate_over_patch(patch, &exp);
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
}
@@ -416,7 +404,7 @@ static const char *expected_patch_text[8] = {
void test_diff_diffiter__iterate_and_generate_patch_text(void)
{
git_repository *repo = cl_git_sandbox_init("status");
- git_diff_list *diff;
+ git_diff *diff;
size_t d, num_d;
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, NULL));
@@ -425,28 +413,28 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void)
cl_assert_equal_i(8, (int)num_d);
for (d = 0; d < num_d; ++d) {
- git_diff_patch *patch;
+ git_patch *patch;
char *text;
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d));
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
cl_assert(patch != NULL);
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected_patch_text[d], text);
git__free(text);
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_diffiter__checks_options_version(void)
{
git_repository *repo = cl_git_sandbox_init("status");
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
const git_error *err;
opts.version = 0;
diff --git a/tests-clar/diff/drivers.c b/tests-clar/diff/drivers.c
index e02dd5c68..fbd1dff81 100644
--- a/tests-clar/diff/drivers.c
+++ b/tests-clar/diff/drivers.c
@@ -20,8 +20,8 @@ void test_diff_drivers__patterns(void)
git_config *cfg;
const char *one_sha = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
git_tree *one;
- git_diff_list *diff;
- git_diff_patch *patch;
+ git_diff *diff;
+ git_patch *patch;
char *text;
const char *expected0 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\n--- a/untimely.txt\n+++ b/untimely.txt\n@@ -22,3 +22,5 @@ Comes through the blood of the vanguards who\n dreamed--too soon--it had sounded.\r\n \r\n -- Rudyard Kipling\r\n+\r\n+Some new stuff\r\n";
const char *expected1 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\nBinary files a/untimely.txt and b/untimely.txt differ\n";
@@ -35,7 +35,7 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(0, (int)git_diff_num_deltas(diff));
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* default diff */
@@ -44,13 +44,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected0, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
/* attribute diff set to false */
@@ -59,13 +59,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected1, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
/* attribute diff set to unconfigured value (should use default) */
@@ -74,13 +74,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected0, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
/* let's define that driver */
@@ -91,13 +91,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected1, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
/* let's use a real driver with some regular expressions */
@@ -112,13 +112,13 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected2, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
git_tree_free(one);
}
@@ -127,8 +127,8 @@ void test_diff_drivers__long_lines(void)
{
const char *base = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non nisi ligula. Ut viverra enim sed lobortis suscipit.\nPhasellus eget erat odio. Praesent at est iaculis, ultricies augue vel, dignissim risus. Suspendisse at nisi quis turpis fringilla rutrum id sit amet nulla.\nNam eget dolor fermentum, aliquet nisl at, convallis tellus. Pellentesque rhoncus erat enim, id porttitor elit euismod quis.\nMauris sollicitudin magna odio, non egestas libero vehicula ut. Etiam et quam velit. Fusce eget libero rhoncus, ultricies felis sit amet, egestas purus.\nAliquam in semper tellus. Pellentesque adipiscing rutrum velit, quis malesuada lacus consequat eget.\n";
git_index *idx;
- git_diff_list *diff;
- git_diff_patch *patch;
+ git_diff *diff;
+ git_patch *patch;
char *actual;
const char *expected = "diff --git a/longlines.txt b/longlines.txt\nindex c1ce6ef..0134431 100644\n--- a/longlines.txt\n+++ b/longlines.txt\n@@ -3,3 +3,5 @@ Phasellus eget erat odio. Praesent at est iaculis, ultricies augue vel, dignissi\n Nam eget dolor fermentum, aliquet nisl at, convallis tellus. Pellentesque rhoncus erat enim, id porttitor elit euismod quis.\n Mauris sollicitudin magna odio, non egestas libero vehicula ut. Etiam et quam velit. Fusce eget libero rhoncus, ultricies felis sit amet, egestas purus.\n Aliquam in semper tellus. Pellentesque adipiscing rutrum velit, quis malesuada lacus consequat eget.\n+newline\n+newline\n";
@@ -144,13 +144,20 @@ void test_diff_drivers__long_lines(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
cl_assert_equal_sz(1, git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&actual, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&actual, patch));
+
+ /* if chmod not supported, overwrite mode bits since anything is possible */
+ if (!cl_is_chmod_supported()) {
+ size_t actual_len = strlen(actual);
+ if (actual_len > 72 && memcmp(&actual[66], "100644", 6) != 0)
+ memcpy(&actual[66], "100644", 6);
+ }
cl_assert_equal_s(expected, actual);
free(actual);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
}
diff --git a/tests-clar/diff/index.c b/tests-clar/diff/index.c
index e1c617dae..8f4567137 100644
--- a/tests-clar/diff/index.c
+++ b/tests-clar/diff/index.c
@@ -21,7 +21,7 @@ void test_diff_index__0(void)
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
cl_assert(a);
@@ -56,7 +56,7 @@ void test_diff_index__0(void)
cl_assert_equal_i(6, exp.line_adds);
cl_assert_equal_i(2, exp.line_dels);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
memset(&exp, 0, sizeof(exp));
@@ -84,7 +84,7 @@ void test_diff_index__0(void)
cl_assert_equal_i(11, exp.line_adds);
cl_assert_equal_i(2, exp.line_dels);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
git_tree_free(a);
@@ -114,7 +114,7 @@ void test_diff_index__1(void)
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
cl_assert(a);
@@ -134,7 +134,7 @@ void test_diff_index__1(void)
cl_assert_equal_i(2, exp.files);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
git_tree_free(a);
@@ -146,7 +146,7 @@ void test_diff_index__checks_options_version(void)
const char *a_commit = "26a125ee1bf";
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
const git_error *err;
opts.version = 0;
diff --git a/tests-clar/diff/notify.c b/tests-clar/diff/notify.c
index 433b4a9c1..cc33cb71c 100644
--- a/tests-clar/diff/notify.c
+++ b/tests-clar/diff/notify.c
@@ -13,7 +13,7 @@ void test_diff_notify__cleanup(void)
}
static int assert_called_notifications(
- const git_diff_list *diff_so_far,
+ const git_diff *diff_so_far,
const git_diff_delta *delta_to_add,
const char *matched_pathspec,
void *payload)
@@ -45,7 +45,7 @@ static void test_notify(
int expected_diffed_files_count)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
g_repo = cl_git_sandbox_init("status");
@@ -63,7 +63,7 @@ static void test_notify(
cl_assert_equal_i(expected_diffed_files_count, exp.files);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_notify__notify_single_pathspec(void)
@@ -155,7 +155,7 @@ void test_diff_notify__notify_catchall(void)
}
static int abort_diff(
- const git_diff_list *diff_so_far,
+ const git_diff *diff_so_far,
const git_diff_delta *delta_to_add,
const char *matched_pathspec,
void *payload)
@@ -171,7 +171,7 @@ static int abort_diff(
void test_diff_notify__notify_cb_can_abort_diff(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
char *pathspec = NULL;
g_repo = cl_git_sandbox_init("status");
@@ -189,7 +189,7 @@ void test_diff_notify__notify_cb_can_abort_diff(void)
}
static int filter_all(
- const git_diff_list *diff_so_far,
+ const git_diff *diff_so_far,
const git_diff_delta *delta_to_add,
const char *matched_pathspec,
void *payload)
@@ -205,7 +205,7 @@ static int filter_all(
void test_diff_notify__notify_cb_can_be_used_as_filtering_function(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
char *pathspec = NULL;
diff_expects exp;
@@ -224,5 +224,5 @@ void test_diff_notify__notify_cb_can_be_used_as_filtering_function(void)
cl_assert_equal_i(0, exp.files);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c
index 6a33fa990..366e5da58 100644
--- a/tests-clar/diff/patch.c
+++ b/tests-clar/diff/patch.c
@@ -26,40 +26,37 @@ void test_diff_patch__cleanup(void)
static int check_removal_cb(
const git_diff_delta *delta,
- const git_diff_range *range,
- char line_origin,
- const char *formatted_output,
- size_t output_len,
+ const git_diff_hunk *hunk,
+ const git_diff_line *line,
void *payload)
{
GIT_UNUSED(payload);
- GIT_UNUSED(output_len);
- switch (line_origin) {
+ switch (line->origin) {
case GIT_DIFF_LINE_FILE_HDR:
- cl_assert_equal_s(EXPECTED_HEADER, formatted_output);
- cl_assert(range == NULL);
+ cl_assert_equal_s(EXPECTED_HEADER, line->content);
+ cl_assert(hunk == NULL);
goto check_delta;
case GIT_DIFF_LINE_HUNK_HDR:
- cl_assert_equal_s(EXPECTED_HUNK, formatted_output);
+ cl_assert_equal_s(EXPECTED_HUNK, line->content);
/* Fall through */
case GIT_DIFF_LINE_CONTEXT:
case GIT_DIFF_LINE_DELETION:
- goto check_range;
+ goto check_hunk;
default:
/* unexpected code path */
return -1;
}
-check_range:
- cl_assert(range != NULL);
- cl_assert_equal_i(1, range->old_start);
- cl_assert_equal_i(2, range->old_lines);
- cl_assert_equal_i(0, range->new_start);
- cl_assert_equal_i(0, range->new_lines);
+check_hunk:
+ cl_assert(hunk != NULL);
+ cl_assert_equal_i(1, hunk->old_start);
+ cl_assert_equal_i(2, hunk->old_lines);
+ cl_assert_equal_i(0, hunk->new_start);
+ cl_assert_equal_i(0, hunk->new_lines);
check_delta:
cl_assert_equal_s("subdir.txt", delta->old_file.path);
@@ -86,7 +83,7 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
const char *one_sha = "26a125e";
const char *another_sha = "735b6a2";
git_tree *one, *another;
- git_diff_list *diff;
+ git_diff *diff;
g_repo = cl_git_sandbox_init("status");
@@ -95,9 +92,10 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, one, another, NULL));
- cl_git_pass(git_diff_print_patch(diff, check_removal_cb, NULL));
+ cl_git_pass(git_diff_print(
+ diff, GIT_DIFF_FORMAT_PATCH, check_removal_cb, NULL));
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(another);
git_tree_free(one);
@@ -108,8 +106,8 @@ void test_diff_patch__to_string(void)
const char *one_sha = "26a125e";
const char *another_sha = "735b6a2";
git_tree *one, *another;
- git_diff_list *diff;
- git_diff_patch *patch;
+ git_diff *diff;
+ git_patch *patch;
char *text;
const char *expected = "diff --git a/subdir.txt b/subdir.txt\ndeleted file mode 100644\nindex e8ee89e..0000000\n--- a/subdir.txt\n+++ /dev/null\n@@ -1,2 +0,0 @@\n-Is it a bird?\n-Is it a plane?\n";
@@ -122,20 +120,20 @@ void test_diff_patch__to_string(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected, text);
- cl_assert_equal_sz(31, git_diff_patch_size(patch, 0, 0, 0));
- cl_assert_equal_sz(31, git_diff_patch_size(patch, 1, 0, 0));
- cl_assert_equal_sz(31 + 16, git_diff_patch_size(patch, 1, 1, 0));
- cl_assert_equal_sz(strlen(expected), git_diff_patch_size(patch, 1, 1, 1));
+ cl_assert_equal_sz(31, git_patch_size(patch, 0, 0, 0));
+ cl_assert_equal_sz(31, git_patch_size(patch, 1, 0, 0));
+ cl_assert_equal_sz(31 + 16, git_patch_size(patch, 1, 1, 0));
+ cl_assert_equal_sz(strlen(expected), git_patch_size(patch, 1, 1, 1));
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
git_tree_free(another);
git_tree_free(one);
}
@@ -145,8 +143,8 @@ void test_diff_patch__config_options(void)
const char *one_sha = "26a125e"; /* current HEAD */
git_tree *one;
git_config *cfg;
- git_diff_list *diff;
- git_diff_patch *patch;
+ git_diff *diff;
+ git_patch *patch;
char *text;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
char *onefile = "staged_changes_modified_file";
@@ -167,24 +165,24 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, one, NULL, &opts));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected1, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected2, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
cl_git_pass(git_config_set_string(cfg, "diff.noprefix", "true"));
@@ -192,13 +190,13 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected3, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
cl_git_pass(git_config_set_int32(cfg, "core.abbrev", 12));
@@ -206,13 +204,13 @@ void test_diff_patch__config_options(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, one, NULL, &opts));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0));
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected4, text);
git__free(text);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
git_tree_free(one);
git_config_free(cfg);
@@ -223,14 +221,12 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
git_config *cfg;
git_tree *head;
git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff;
- git_diff_patch *patch;
+ git_diff *diff;
+ git_patch *patch;
const git_diff_delta *delta;
- const git_diff_range *range;
- const char *hdr, *text;
- size_t hdrlen, hunklen, textlen;
- char origin;
- int oldno, newno;
+ const git_diff_hunk *hunk;
+ const git_diff_line *line;
+ size_t hunklen;
git_buf old_content = GIT_BUF_INIT, actual = GIT_BUF_INIT;
const char *new_content = "The Song of Seven Cities\n------------------------\n\nI WAS Lord of Cities very sumptuously builded.\nSeven roaring Cities paid me tribute from afar.\nIvory their outposts were--the guardrooms of them gilded,\nAnd garrisoned with Amazons invincible in war.\n\nThis is some new text;\nNot as good as the old text;\nBut here it is.\n\nSo they warred and trafficked only yesterday, my Cities.\nTo-day there is no mark or mound of where my Cities stood.\nFor the River rose at midnight and it washed away my Cities.\nThey are evened with Atlantis and the towns before the Flood.\n\nRain on rain-gorged channels raised the water-levels round them,\nFreshet backed on freshet swelled and swept their world from sight,\nTill the emboldened floods linked arms and, flashing forward, drowned them--\nDrowned my Seven Cities and their peoples in one night!\n\nLow among the alders lie their derelict foundations,\nThe beams wherein they trusted and the plinths whereon they built--\nMy rulers and their treasure and their unborn populations,\nDead, destroyed, aborted, and defiled with mud and silt!\n\nAnother replacement;\nBreaking up the poem;\nGenerating some hunks.\n\nTo the sound of trumpets shall their seed restore my Cities\nWealthy and well-weaponed, that once more may I behold\nAll the world go softly when it walks before my Cities,\nAnd the horses and the chariots fleeing from them as of old!\n\n -- Rudyard Kipling\n";
@@ -238,6 +234,9 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_git_pass(git_config_new(&cfg));
git_repository_set_config(g_repo, cfg);
+ git_config_free(cfg);
+
+ git_repository_reinit_filesystem(g_repo, false);
cl_git_pass(
git_futils_readbuffer(&old_content, "renames/songof7cities.txt"));
@@ -250,89 +249,83 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_assert((delta = git_patch_get_delta(patch)) != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
- cl_assert_equal_i(2, (int)git_diff_patch_num_hunks(patch));
+ cl_assert_equal_i(2, (int)git_patch_num_hunks(patch));
/* check hunk 0 */
cl_git_pass(
- git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
+ git_patch_get_hunk(&hunk, &hunklen, patch, 0));
cl_assert_equal_i(18, (int)hunklen);
- cl_assert_equal_i(6, (int)range->old_start);
- cl_assert_equal_i(15, (int)range->old_lines);
- cl_assert_equal_i(6, (int)range->new_start);
- cl_assert_equal_i(9, (int)range->new_lines);
+ cl_assert_equal_i(6, (int)hunk->old_start);
+ cl_assert_equal_i(15, (int)hunk->old_lines);
+ cl_assert_equal_i(6, (int)hunk->new_start);
+ cl_assert_equal_i(9, (int)hunk->new_lines);
- cl_assert_equal_i(18, (int)git_diff_patch_num_lines_in_hunk(patch, 0));
+ cl_assert_equal_i(18, (int)git_patch_num_lines_in_hunk(patch, 0));
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 0, 0));
- cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 0));
+ cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("Ivory their outposts were--the guardrooms of them gilded,\n", actual.ptr);
- cl_assert_equal_i(6, oldno);
- cl_assert_equal_i(6, newno);
+ cl_assert_equal_i(6, line->old_lineno);
+ cl_assert_equal_i(6, line->new_lineno);
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 0, 3));
- cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 3));
+ cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("All the world went softly when it walked before my Cities--\n", actual.ptr);
- cl_assert_equal_i(9, oldno);
- cl_assert_equal_i(-1, newno);
+ cl_assert_equal_i(9, line->old_lineno);
+ cl_assert_equal_i(-1, line->new_lineno);
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 0, 12));
- cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 12));
+ cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("This is some new text;\n", actual.ptr);
- cl_assert_equal_i(-1, oldno);
- cl_assert_equal_i(9, newno);
+ cl_assert_equal_i(-1, line->old_lineno);
+ cl_assert_equal_i(9, line->new_lineno);
/* check hunk 1 */
- cl_git_pass(
- git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 1));
+ cl_git_pass(git_patch_get_hunk(&hunk, &hunklen, patch, 1));
cl_assert_equal_i(18, (int)hunklen);
- cl_assert_equal_i(31, (int)range->old_start);
- cl_assert_equal_i(15, (int)range->old_lines);
- cl_assert_equal_i(25, (int)range->new_start);
- cl_assert_equal_i(9, (int)range->new_lines);
+ cl_assert_equal_i(31, (int)hunk->old_start);
+ cl_assert_equal_i(15, (int)hunk->old_lines);
+ cl_assert_equal_i(25, (int)hunk->new_start);
+ cl_assert_equal_i(9, (int)hunk->new_lines);
- cl_assert_equal_i(18, (int)git_diff_patch_num_lines_in_hunk(patch, 1));
+ cl_assert_equal_i(18, (int)git_patch_num_lines_in_hunk(patch, 1));
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 1, 0));
- cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 0));
+ cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("My rulers and their treasure and their unborn populations,\n", actual.ptr);
- cl_assert_equal_i(31, oldno);
- cl_assert_equal_i(25, newno);
+ cl_assert_equal_i(31, line->old_lineno);
+ cl_assert_equal_i(25, line->new_lineno);
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 1, 3));
- cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 3));
+ cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("The Daughters of the Palace whom they cherished in my Cities,\n", actual.ptr);
- cl_assert_equal_i(34, oldno);
- cl_assert_equal_i(-1, newno);
+ cl_assert_equal_i(34, line->old_lineno);
+ cl_assert_equal_i(-1, line->new_lineno);
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 1, 12));
- cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 1, 12));
+ cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("Another replacement;\n", actual.ptr);
- cl_assert_equal_i(-1, oldno);
- cl_assert_equal_i(28, newno);
+ cl_assert_equal_i(-1, line->old_lineno);
+ cl_assert_equal_i(28, line->new_lineno);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
/* Let's check line numbers when there is no newline */
@@ -343,72 +336,66 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_assert((delta = git_patch_get_delta(patch)) != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
- cl_assert_equal_i(1, (int)git_diff_patch_num_hunks(patch));
+ cl_assert_equal_i(1, (int)git_patch_num_hunks(patch));
/* check hunk 0 */
- cl_git_pass(
- git_diff_patch_get_hunk(&range, &hdr, &hdrlen, &hunklen, patch, 0));
+ cl_git_pass(git_patch_get_hunk(&hunk, &hunklen, patch, 0));
cl_assert_equal_i(6, (int)hunklen);
- cl_assert_equal_i(46, (int)range->old_start);
- cl_assert_equal_i(4, (int)range->old_lines);
- cl_assert_equal_i(46, (int)range->new_start);
- cl_assert_equal_i(4, (int)range->new_lines);
+ cl_assert_equal_i(46, (int)hunk->old_start);
+ cl_assert_equal_i(4, (int)hunk->old_lines);
+ cl_assert_equal_i(46, (int)hunk->new_start);
+ cl_assert_equal_i(4, (int)hunk->new_lines);
- cl_assert_equal_i(6, (int)git_diff_patch_num_lines_in_hunk(patch, 0));
+ cl_assert_equal_i(6, (int)git_patch_num_lines_in_hunk(patch, 0));
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 0, 1));
- cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 1));
+ cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("And the horses and the chariots fleeing from them as of old!\n", actual.ptr);
- cl_assert_equal_i(47, oldno);
- cl_assert_equal_i(47, newno);
+ cl_assert_equal_i(47, line->old_lineno);
+ cl_assert_equal_i(47, line->new_lineno);
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 0, 2));
- cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 2));
+ cl_assert_equal_i(GIT_DIFF_LINE_CONTEXT, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("\n", actual.ptr);
- cl_assert_equal_i(48, oldno);
- cl_assert_equal_i(48, newno);
+ cl_assert_equal_i(48, line->old_lineno);
+ cl_assert_equal_i(48, line->new_lineno);
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 0, 3));
- cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 3));
+ cl_assert_equal_i(GIT_DIFF_LINE_DELETION, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s(" -- Rudyard Kipling\n", actual.ptr);
- cl_assert_equal_i(49, oldno);
- cl_assert_equal_i(-1, newno);
+ cl_assert_equal_i(49, line->old_lineno);
+ cl_assert_equal_i(-1, line->new_lineno);
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 0, 4));
- cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 4));
+ cl_assert_equal_i(GIT_DIFF_LINE_ADDITION, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s(" -- Rudyard Kipling", actual.ptr);
- cl_assert_equal_i(-1, oldno);
- cl_assert_equal_i(49, newno);
+ cl_assert_equal_i(-1, line->old_lineno);
+ cl_assert_equal_i(49, line->new_lineno);
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &text, &textlen, &oldno, &newno, patch, 0, 5));
- cl_assert_equal_i(GIT_DIFF_LINE_DEL_EOFNL, (int)origin);
- cl_git_pass(git_buf_set(&actual, text, textlen));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, 0, 5));
+ cl_assert_equal_i(GIT_DIFF_LINE_DEL_EOFNL, (int)line->origin);
+ cl_git_pass(git_buf_set(&actual, line->content, line->content_len));
cl_assert_equal_s("\n\\ No newline at end of file\n", actual.ptr);
- cl_assert_equal_i(-1, oldno);
- cl_assert_equal_i(49, newno);
+ cl_assert_equal_i(-1, line->old_lineno);
+ cl_assert_equal_i(49, line->new_lineno);
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
git_buf_free(&actual);
git_buf_free(&old_content);
git_tree_free(head);
- git_config_free(cfg);
}
static void check_single_patch_stats(
@@ -416,8 +403,8 @@ static void check_single_patch_stats(
size_t adds, size_t dels, size_t ctxt, size_t *sizes,
const char *expected)
{
- git_diff_list *diff;
- git_diff_patch *patch;
+ git_diff *diff;
+ git_patch *patch;
const git_diff_delta *delta;
size_t actual_ctxt, actual_adds, actual_dels;
@@ -425,12 +412,13 @@ static void check_single_patch_stats(
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_assert((delta = git_patch_get_delta(patch)) != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
- cl_assert_equal_i((int)hunks, (int)git_diff_patch_num_hunks(patch));
+ cl_assert_equal_i((int)hunks, (int)git_patch_num_hunks(patch));
- cl_git_pass( git_diff_patch_line_stats(
+ cl_git_pass( git_patch_line_stats(
&actual_ctxt, &actual_adds, &actual_dels, patch) );
cl_assert_equal_sz(ctxt, actual_ctxt);
@@ -439,57 +427,60 @@ static void check_single_patch_stats(
if (expected != NULL) {
char *text;
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected, text);
git__free(text);
cl_assert_equal_sz(
- strlen(expected), git_diff_patch_size(patch, 1, 1, 1));
+ strlen(expected), git_patch_size(patch, 1, 1, 1));
}
if (sizes) {
if (sizes[0])
- cl_assert_equal_sz(sizes[0], git_diff_patch_size(patch, 0, 0, 0));
+ cl_assert_equal_sz(sizes[0], git_patch_size(patch, 0, 0, 0));
if (sizes[1])
- cl_assert_equal_sz(sizes[1], git_diff_patch_size(patch, 1, 0, 0));
+ cl_assert_equal_sz(sizes[1], git_patch_size(patch, 1, 0, 0));
if (sizes[2])
- cl_assert_equal_sz(sizes[2], git_diff_patch_size(patch, 1, 1, 0));
+ cl_assert_equal_sz(sizes[2], git_patch_size(patch, 1, 1, 0));
}
/* walk lines in hunk with basic sanity checks */
for (; hunks > 0; --hunks) {
size_t i, max_i;
- int lastoldno = -1, oldno, lastnewno = -1, newno;
- char origin;
+ const git_diff_line *line;
+ int last_new_lineno = -1, last_old_lineno = -1;
- max_i = git_diff_patch_num_lines_in_hunk(patch, hunks - 1);
+ max_i = git_patch_num_lines_in_hunk(patch, hunks - 1);
for (i = 0; i < max_i; ++i) {
int expected = 1;
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, NULL, NULL, &oldno, &newno, patch, hunks - 1, i));
+ cl_git_pass(
+ git_patch_get_line_in_hunk(&line, patch, hunks - 1, i));
- if (origin == GIT_DIFF_LINE_ADD_EOFNL ||
- origin == GIT_DIFF_LINE_DEL_EOFNL ||
- origin == GIT_DIFF_LINE_CONTEXT_EOFNL)
+ if (line->origin == GIT_DIFF_LINE_ADD_EOFNL ||
+ line->origin == GIT_DIFF_LINE_DEL_EOFNL ||
+ line->origin == GIT_DIFF_LINE_CONTEXT_EOFNL)
expected = 0;
- if (oldno >= 0) {
- if (lastoldno >= 0)
- cl_assert_equal_i(expected, oldno - lastoldno);
- lastoldno = oldno;
+ if (line->old_lineno >= 0) {
+ if (last_old_lineno >= 0)
+ cl_assert_equal_i(
+ expected, line->old_lineno - last_old_lineno);
+ last_old_lineno = line->old_lineno;
}
- if (newno >= 0) {
- if (lastnewno >= 0)
- cl_assert_equal_i(expected, newno - lastnewno);
- lastnewno = newno;
+
+ if (line->new_lineno >= 0) {
+ if (last_new_lineno >= 0)
+ cl_assert_equal_i(
+ expected, line->new_lineno - last_new_lineno);
+ last_new_lineno = line->new_lineno;
}
}
}
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ git_patch_free(patch);
+ git_diff_free(diff);
}
void test_diff_patch__line_counts_with_eofnl(void)
@@ -520,6 +511,9 @@ void test_diff_patch__line_counts_with_eofnl(void)
cl_git_pass(git_config_new(&cfg));
git_repository_set_config(g_repo, cfg);
+ git_config_free(cfg);
+
+ git_repository_reinit_filesystem(g_repo, false);
cl_git_pass(git_futils_readbuffer(&content, "renames/songof7cities.txt"));
@@ -574,5 +568,4 @@ void test_diff_patch__line_counts_with_eofnl(void)
g_repo, 1, 1, 1, 6, expected_sizes, expected);
git_buf_free(&content);
- git_config_free(cfg);
}
diff --git a/tests-clar/diff/pathspec.c b/tests-clar/diff/pathspec.c
index 7b15ea04c..5761d2d2b 100644
--- a/tests-clar/diff/pathspec.c
+++ b/tests-clar/diff/pathspec.c
@@ -20,7 +20,7 @@ void test_diff_pathspec__0(void)
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
git_strarray paths = { NULL, 1 };
char *path;
git_pathspec *ps;
@@ -52,7 +52,7 @@ void test_diff_pathspec__0(void)
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
git_pathspec_match_list_free(matches);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
@@ -68,7 +68,7 @@ void test_diff_pathspec__0(void)
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
git_pathspec_match_list_free(matches);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
@@ -84,7 +84,7 @@ void test_diff_pathspec__0(void)
(int)git_pathspec_match_list_diff_entry(matches,0)->status);
git_pathspec_match_list_free(matches);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
git_tree_free(a);
diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
index 9864c5896..42bb65aa8 100644
--- a/tests-clar/diff/rename.c
+++ b/tests-clar/diff/rename.c
@@ -43,7 +43,7 @@ void test_diff_rename__match_oid(void)
const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
git_tree *old_tree, *new_tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
@@ -88,7 +88,7 @@ void test_diff_rename__match_oid(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_git_pass(git_diff_tree_to_tree(
&diff, g_repo, old_tree, new_tree, &diffopts));
@@ -109,7 +109,7 @@ void test_diff_rename__match_oid(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(old_tree);
git_tree_free(new_tree);
@@ -120,7 +120,7 @@ void test_diff_rename__checks_options_version(void)
const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2";
const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
git_tree *old_tree, *new_tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
const git_error *err;
@@ -142,7 +142,7 @@ void test_diff_rename__checks_options_version(void)
err = giterr_last();
cl_assert_equal_i(GITERR_INVALID, err->klass);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(old_tree);
git_tree_free(new_tree);
}
@@ -153,7 +153,7 @@ void test_diff_rename__not_exact_match(void)
const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
const char *sha2 = "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13";
git_tree *old_tree, *new_tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
@@ -207,7 +207,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* git diff -M -C \
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
@@ -228,7 +228,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* git diff -M -C --find-copies-harder --break-rewrites \
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
@@ -253,7 +253,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* == Changes =====================================================
* songofseven.txt -> untimely.txt (rename, convert to crlf)
@@ -281,7 +281,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* git diff -M -C \
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
@@ -301,7 +301,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* git diff -M -C --find-copies-harder --break-rewrites \
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
@@ -330,7 +330,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* git diff -M -C --find-copies-harder --break-rewrites \
* 1c068dee5790ef1580cfc4cd670915b48d790084 \
@@ -353,7 +353,7 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(old_tree);
git_tree_free(new_tree);
@@ -364,7 +364,7 @@ void test_diff_rename__handles_small_files(void)
const char *tree_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
git_index *index;
git_tree *tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
@@ -388,7 +388,7 @@ void test_diff_rename__handles_small_files(void)
GIT_DIFF_FIND_AND_BREAK_REWRITES;
cl_git_pass(git_diff_find_similar(diff, &opts));
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
}
@@ -400,7 +400,7 @@ void test_diff_rename__working_directory_changes(void)
git_oid id;
git_tree *tree;
git_blob *blob;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
@@ -451,7 +451,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* rewrite files in the working directory with / without CRLF changes */
@@ -477,7 +477,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* try a different whitespace option */
@@ -496,7 +496,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* try a different matching option */
@@ -514,7 +514,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_UNTRACKED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* again with exact match blob */
@@ -545,7 +545,7 @@ void test_diff_rename__working_directory_changes(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_buf_free(&content);
@@ -557,10 +557,10 @@ void test_diff_rename__patch(void)
const char *sha0 = "2bc7f351d20b53f1c72c16c4b036e491c478c49a";
const char *sha1 = "1c068dee5790ef1580cfc4cd670915b48d790084";
git_tree *old_tree, *new_tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
- git_diff_patch *patch;
+ git_patch *patch;
const git_diff_delta *delta;
char *text;
const char *expected = "diff --git a/sixserving.txt b/ikeepsix.txt\nindex ad0a8e5..36020db 100644\n--- a/sixserving.txt\n+++ b/ikeepsix.txt\n@@ -1,3 +1,6 @@\n+I Keep Six Honest Serving-Men\n+=============================\n+\n I KEEP six honest serving-men\n (They taught me all I knew);\n Their names are What and Why and When\n@@ -21,4 +24,4 @@ She sends'em abroad on her own affairs,\n One million Hows, two million Wheres,\n And seven million Whys!\n \n- -- Rudyard Kipling\n+ -- Rudyard Kipling\n";
@@ -584,25 +584,26 @@ void test_diff_rename__patch(void)
cl_assert_equal_i(4, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, 0));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_assert((delta = git_patch_get_delta(patch)) != NULL);
cl_assert_equal_i(GIT_DELTA_COPIED, (int)delta->status);
- cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_git_pass(git_patch_to_str(&text, patch));
cl_assert_equal_s(expected, text);
git__free(text);
- git_diff_patch_free(patch);
+ git_patch_free(patch);
- cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 1));
+ cl_assert((delta = git_diff_get_delta(diff, 1)) != NULL);
cl_assert_equal_i(GIT_DELTA_UNMODIFIED, (int)delta->status);
- cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 2));
+ cl_assert((delta = git_diff_get_delta(diff, 2)) != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
- cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 3));
+ cl_assert((delta = git_diff_get_delta(diff, 3)) != NULL);
cl_assert_equal_i(GIT_DELTA_MODIFIED, (int)delta->status);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(old_tree);
git_tree_free(new_tree);
}
@@ -612,7 +613,7 @@ void test_diff_rename__file_exchange(void)
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
@@ -647,7 +648,7 @@ void test_diff_rename__file_exchange(void)
cl_assert_equal_i(2, exp.files);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
@@ -660,7 +661,7 @@ void test_diff_rename__file_exchange_three(void)
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT, c3 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
@@ -699,7 +700,7 @@ void test_diff_rename__file_exchange_three(void)
cl_assert_equal_i(3, exp.files);
cl_assert_equal_i(3, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
@@ -713,7 +714,7 @@ void test_diff_rename__file_partial_exchange(void)
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
@@ -752,7 +753,7 @@ void test_diff_rename__file_partial_exchange(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
@@ -765,7 +766,7 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
git_buf c1 = GIT_BUF_INIT, c2 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
@@ -809,7 +810,7 @@ void test_diff_rename__rename_and_copy_from_same_source(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_COPIED]);
cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNMODIFIED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
@@ -822,7 +823,7 @@ void test_diff_rename__from_deleted_to_split(void)
git_buf c1 = GIT_BUF_INIT;
git_index *index;
git_tree *tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
diff_expects exp;
@@ -863,7 +864,7 @@ void test_diff_rename__from_deleted_to_split(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNMODIFIED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
@@ -907,7 +908,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
git_index *index;
git_tree *tree;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
git_buf one = GIT_BUF_INIT, two = GIT_BUF_INIT;
@@ -961,7 +962,7 @@ void test_diff_rename__rejected_match_can_match_others(void)
cl_git_pass(
git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
git_reference_free(head);
@@ -993,7 +994,7 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
git_index *index;
git_tree *tree;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
unsigned int status[] = { GIT_DELTA_RENAMED, GIT_DELTA_RENAMED };
@@ -1035,7 +1036,7 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
cl_assert(expect.idx > 0);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
git_reference_free(head);
@@ -1048,7 +1049,7 @@ void test_diff_rename__rejected_match_can_match_others_three(void)
git_index *index;
git_tree *tree;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
@@ -1091,7 +1092,7 @@ void test_diff_rename__rejected_match_can_match_others_three(void)
cl_assert(expect.idx == expect.len);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
git_reference_free(head);
@@ -1102,7 +1103,7 @@ void test_diff_rename__can_rename_from_rewrite(void)
{
git_index *index;
git_tree *tree;
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
@@ -1140,7 +1141,7 @@ void test_diff_rename__can_rename_from_rewrite(void)
cl_assert(expect.idx == expect.len);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
}
@@ -1149,7 +1150,7 @@ void test_diff_rename__case_changes_are_split(void)
{
git_index *index;
git_tree *tree;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
@@ -1182,7 +1183,7 @@ void test_diff_rename__case_changes_are_split(void)
cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_index_free(index);
git_tree_free(tree);
}
@@ -1191,7 +1192,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
{
git_index *index;
git_tree *tree;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
@@ -1230,7 +1231,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
cl_assert_equal_i(1, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_index_free(index);
git_tree_free(tree);
}
@@ -1238,7 +1239,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
void test_diff_rename__rewrite_on_single_file(void)
{
git_index *index;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
@@ -1280,6 +1281,6 @@ void test_diff_rename__rewrite_on_single_file(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_index_free(index);
}
diff --git a/tests-clar/diff/submodules.c b/tests-clar/diff/submodules.c
index 036ff09aa..24545b2c7 100644
--- a/tests-clar/diff/submodules.c
+++ b/tests-clar/diff/submodules.c
@@ -14,15 +14,16 @@ void test_diff_submodules__cleanup(void)
}
static void check_diff_patches_at_line(
- git_diff_list *diff, const char **expected, const char *file, int line)
+ git_diff *diff, const char **expected, const char *file, int line)
{
const git_diff_delta *delta;
- git_diff_patch *patch = NULL;
+ git_patch *patch = NULL;
size_t d, num_d = git_diff_num_deltas(diff);
char *patch_text;
- for (d = 0; d < num_d; ++d, git_diff_patch_free(patch)) {
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
+ for (d = 0; d < num_d; ++d, git_patch_free(patch)) {
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
+ cl_assert((delta = git_patch_get_delta(patch)) != NULL);
if (delta->status == GIT_DELTA_UNMODIFIED) {
cl_assert_at_line(expected[d] == NULL, file, line);
@@ -32,11 +33,11 @@ static void check_diff_patches_at_line(
if (expected[d] && !strcmp(expected[d], "<SKIP>"))
continue;
if (expected[d] && !strcmp(expected[d], "<END>")) {
- cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
+ cl_git_pass(git_patch_to_str(&patch_text, patch));
cl_assert_at_line(!strcmp(expected[d], "<END>"), file, line);
}
- cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
+ cl_git_pass(git_patch_to_str(&patch_text, patch));
clar__assert_equal(
file, line, "expected diff did not match actual diff", 1,
@@ -53,7 +54,7 @@ static void check_diff_patches_at_line(
void test_diff_submodules__unmodified_submodule(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
NULL, /* added */
@@ -74,13 +75,13 @@ void test_diff_submodules__unmodified_submodule(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_submodules__dirty_submodule(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
NULL, /* added */
@@ -104,13 +105,13 @@ void test_diff_submodules__dirty_submodule(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_submodules__dirty_submodule_2(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL, *diff2 = NULL;
+ git_diff *diff = NULL, *diff2 = NULL;
char *smpath = "testrepo";
static const char *expected_none[] = { "<END>" };
static const char *expected_dirty[] = {
@@ -123,7 +124,7 @@ void test_diff_submodules__dirty_submodule_2(void)
cl_git_pass(git_submodule_reload_all(g_repo));
opts.flags = GIT_DIFF_INCLUDE_UNTRACKED |
- GIT_DIFF_INCLUDE_UNTRACKED_CONTENT |
+ GIT_DIFF_SHOW_UNTRACKED_CONTENT |
GIT_DIFF_RECURSE_UNTRACKED_DIRS |
GIT_DIFF_DISABLE_PATHSPEC_MATCH;
opts.old_prefix = "a"; opts.new_prefix = "b";
@@ -132,7 +133,7 @@ void test_diff_submodules__dirty_submodule_2(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_none);
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
cl_git_mkfile("submodules/testrepo/all_new.txt", "never seen before");
@@ -146,25 +147,25 @@ void test_diff_submodules__dirty_submodule_2(void)
cl_git_pass(git_repository_head_tree(&head, g_repo));
cl_git_pass(git_diff_tree_to_index(&diff2, g_repo, head, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
- git_diff_list_free(diff2);
+ git_diff_free(diff2);
git_tree_free(head);
check_diff_patches(diff, expected_dirty);
}
- git_diff_list_free(diff);
+ 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_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_submodules__submod2_index_to_wd(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
"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 */
@@ -182,14 +183,14 @@ void test_diff_submodules__submod2_index_to_wd(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_submodules__submod2_head_to_index(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_tree *head;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
static const char *expected[] = {
"<SKIP>", /* .gitmodules */
"diff --git a/sm_added_and_uncommited b/sm_added_and_uncommited\nnew file mode 160000\nindex 0000000..4800958\n--- /dev/null\n+++ b/sm_added_and_uncommited\n@@ -0,0 +1 @@\n+Subproject commit 480095882d281ed676fe5b863569520e54a7d5c0\n", /* sm_added_and_uncommited */
@@ -205,7 +206,7 @@ void test_diff_submodules__submod2_head_to_index(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, head, NULL, &opts));
check_diff_patches(diff, expected);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(head);
}
@@ -213,7 +214,7 @@ void test_diff_submodules__submod2_head_to_index(void)
void test_diff_submodules__invalid_cache(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
git_submodule *sm;
char *smpath = "sm_changed_head";
git_repository *smrepo;
@@ -246,7 +247,7 @@ void test_diff_submodules__invalid_cache(void)
/* baseline */
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_baseline);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* update index with new HEAD */
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
@@ -254,7 +255,7 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* create untracked file in submodule working directory */
cl_git_mkfile("submod2/sm_changed_head/new_around_here", "hello");
@@ -262,13 +263,13 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_UNTRACKED);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* modify tracked file in submodule working directory */
cl_git_append2file(
@@ -276,20 +277,20 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_git_pass(git_submodule_reload_all(g_repo));
cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* add file to index in submodule */
cl_git_pass(git_submodule_open(&smrepo, sm));
@@ -300,13 +301,13 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_dirty);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* commit changed index of submodule */
cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Move it");
@@ -315,25 +316,25 @@ void test_diff_submodules__invalid_cache(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_moved);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_ALL);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_unchanged);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_NONE);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_moved_dirty);
- git_diff_list_free(diff);
+ git_diff_free(diff);
p_unlink("submod2/sm_changed_head/new_around_here");
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_moved);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_index_free(smindex);
git_repository_free(smrepo);
@@ -342,7 +343,7 @@ void test_diff_submodules__invalid_cache(void)
void test_diff_submodules__diff_ignore_options(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
git_config *cfg;
static const char *expected_normal[] = {
"<SKIP>", /* .gitmodules */
@@ -371,26 +372,26 @@ void test_diff_submodules__diff_ignore_options(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_normal);
- git_diff_list_free(diff);
+ git_diff_free(diff);
opts.flags |= GIT_DIFF_IGNORE_SUBMODULES;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_all);
- git_diff_list_free(diff);
+ git_diff_free(diff);
opts.flags &= ~GIT_DIFF_IGNORE_SUBMODULES;
opts.ignore_submodules = GIT_SUBMODULE_IGNORE_ALL;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_all);
- git_diff_list_free(diff);
+ git_diff_free(diff);
opts.ignore_submodules = GIT_SUBMODULE_IGNORE_DIRTY;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_dirty);
- git_diff_list_free(diff);
+ git_diff_free(diff);
opts.ignore_submodules = 0;
cl_git_pass(git_repository_config(&cfg, g_repo));
@@ -398,25 +399,25 @@ void test_diff_submodules__diff_ignore_options(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_normal);
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_git_pass(git_config_set_bool(cfg, "diff.ignoreSubmodules", true));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_all);
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_git_pass(git_config_set_string(cfg, "diff.ignoreSubmodules", "none"));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_normal);
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_git_pass(git_config_set_string(cfg, "diff.ignoreSubmodules", "dirty"));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
check_diff_patches(diff, expected_ignore_dirty);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_config_free(cfg);
}
diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c
index f05c7869e..ca2daf5fb 100644
--- a/tests-clar/diff/tree.c
+++ b/tests-clar/diff/tree.c
@@ -3,7 +3,7 @@
static git_repository *g_repo = NULL;
static git_diff_options opts;
-static git_diff_list *diff;
+static git_diff *diff;
static git_tree *a, *b;
static diff_expects expect;
@@ -22,7 +22,7 @@ void test_diff_tree__initialize(void)
void test_diff_tree__cleanup(void)
{
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(a);
git_tree_free(b);
@@ -65,7 +65,7 @@ void test_diff_tree__0(void)
cl_assert_equal_i(24 + 1 + 5 + 5, expect.line_adds);
cl_assert_equal_i(7 + 1, expect.line_dels);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
memset(&expect, 0, sizeof(expect));
@@ -90,6 +90,9 @@ void test_diff_tree__0(void)
git_tree_free(c);
}
+#define DIFF_OPTS(FLAGS, CTXT) \
+ {GIT_DIFF_OPTIONS_VERSION, (FLAGS), 0, {NULL,0}, NULL, NULL, (CTXT), 1}
+
void test_diff_tree__options(void)
{
/* grabbed a couple of commit oids from the history of the attr repo */
@@ -102,16 +105,16 @@ void test_diff_tree__options(void)
int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 };
git_diff_options test_options[] = {
/* a vs b tests */
- { 1, GIT_DIFF_NORMAL, 1, 1, NULL, NULL, {0} },
- { 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
- { 1, GIT_DIFF_REVERSE, 2, 1, NULL, NULL, {0} },
- { 1, GIT_DIFF_FORCE_TEXT, 2, 1, NULL, NULL, {0} },
+ DIFF_OPTS(GIT_DIFF_NORMAL, 1),
+ DIFF_OPTS(GIT_DIFF_NORMAL, 3),
+ DIFF_OPTS(GIT_DIFF_REVERSE, 2),
+ DIFF_OPTS(GIT_DIFF_FORCE_TEXT, 2),
/* c vs d tests */
- { 1, GIT_DIFF_NORMAL, 3, 1, NULL, NULL, {0} },
- { 1, GIT_DIFF_IGNORE_WHITESPACE, 3, 1, NULL, NULL, {0} },
- { 1, GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3, 1, NULL, NULL, {0} },
- { 1, GIT_DIFF_IGNORE_WHITESPACE_EOL, 3, 1, NULL, NULL, {0} },
- { 1, GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1, 1, NULL, NULL, {0} },
+ DIFF_OPTS(GIT_DIFF_NORMAL, 3),
+ DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE, 3),
+ DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE_CHANGE, 3),
+ DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE_EOL, 3),
+ DIFF_OPTS(GIT_DIFF_IGNORE_WHITESPACE | GIT_DIFF_REVERSE, 1),
};
/* to generate these values:
@@ -168,7 +171,7 @@ void test_diff_tree__options(void)
cl_assert_equal_i(actual.line_adds, expected->line_adds);
cl_assert_equal_i(actual.line_dels, expected->line_dels);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
}
@@ -214,7 +217,7 @@ void test_diff_tree__merge(void)
const char *b_commit = "370fe9ec22";
const char *c_commit = "f5b0af1fb4f5c";
git_tree *c;
- git_diff_list *diff1 = NULL, *diff2 = NULL;
+ git_diff *diff1 = NULL, *diff2 = NULL;
g_repo = cl_git_sandbox_init("attr");
@@ -230,7 +233,7 @@ void test_diff_tree__merge(void)
cl_git_pass(git_diff_merge(diff1, diff2));
- git_diff_list_free(diff2);
+ git_diff_free(diff2);
cl_git_pass(git_diff_foreach(
diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect));
@@ -247,19 +250,17 @@ void test_diff_tree__merge(void)
cl_assert_equal_i(36, expect.line_adds);
cl_assert_equal_i(22, expect.line_dels);
- git_diff_list_free(diff1);
+ git_diff_free(diff1);
}
void test_diff_tree__larger_hunks(void)
{
const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69";
const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
- size_t d, num_d, h, num_h, l, num_l, header_len, line_len;
- const git_diff_delta *delta;
- git_diff_patch *patch;
- const git_diff_range *range;
- const char *header, *line;
- char origin;
+ size_t d, num_d, h, num_h, l, num_l;
+ git_patch *patch;
+ const git_diff_hunk *hunk;
+ const git_diff_line *line;
g_repo = cl_git_sandbox_init("diff");
@@ -273,31 +274,27 @@ void test_diff_tree__larger_hunks(void)
num_d = git_diff_num_deltas(diff);
for (d = 0; d < num_d; ++d) {
- cl_git_pass(git_diff_get_patch(&patch, &delta, diff, d));
- cl_assert(patch && delta);
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
+ cl_assert(patch);
- num_h = git_diff_patch_num_hunks(patch);
+ num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
- cl_git_pass(git_diff_patch_get_hunk(
- &range, &header, &header_len, &num_l, patch, h));
+ cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h));
for (l = 0; l < num_l; ++l) {
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &line, &line_len, NULL, NULL, patch, h, l));
+ cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l));
cl_assert(line);
}
- cl_git_fail(git_diff_patch_get_line_in_hunk(
- &origin, &line, &line_len, NULL, NULL, patch, h, num_l));
+ cl_git_fail(git_patch_get_line_in_hunk(&line, patch, h, num_l));
}
- cl_git_fail(git_diff_patch_get_hunk(
- &range, &header, &header_len, &num_l, patch, num_h));
+ cl_git_fail(git_patch_get_hunk(&hunk, &num_l, patch, num_h));
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
- cl_git_fail(git_diff_get_patch(&patch, &delta, diff, num_d));
+ cl_git_fail(git_patch_from_diff(&patch, diff, num_d));
cl_assert_equal_i(2, (int)num_d);
}
@@ -487,7 +484,7 @@ void test_diff_tree__diff_configs(void)
cl_assert_equal_i(7, expect.line_adds);
cl_assert_equal_i(15, expect.line_dels);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
set_config_int(g_repo, "diff.context", 1);
@@ -507,7 +504,7 @@ void test_diff_tree__diff_configs(void)
cl_assert_equal_i(7, expect.line_adds);
cl_assert_equal_i(15, expect.line_dels);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
set_config_int(g_repo, "diff.context", 0);
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index 6c17b41c6..e72acdb03 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -16,7 +16,7 @@ void test_diff_workdir__cleanup(void)
void test_diff_workdir__to_index(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
int use_iterator;
@@ -60,7 +60,7 @@ void test_diff_workdir__to_index(void)
cl_assert_equal_i(5, exp.line_dels);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_workdir__to_tree(void)
@@ -70,8 +70,8 @@ void test_diff_workdir__to_tree(void)
const char *b_commit = "0017bd4ab1ec3"; /* the start */
git_tree *a, *b;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
- git_diff_list *diff2 = NULL;
+ git_diff *diff = NULL;
+ git_diff *diff2 = NULL;
diff_expects exp;
int use_iterator;
@@ -119,7 +119,7 @@ void test_diff_workdir__to_tree(void)
* do more apples-to-apples test comparison below.
*/
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
memset(&exp, 0, sizeof(exp));
@@ -130,7 +130,7 @@ void test_diff_workdir__to_tree(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
- git_diff_list_free(diff2);
+ git_diff_free(diff2);
for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp));
@@ -157,7 +157,7 @@ void test_diff_workdir__to_tree(void)
cl_assert_equal_i(5, exp.line_dels);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
memset(&exp, 0, sizeof(exp));
@@ -167,7 +167,7 @@ void test_diff_workdir__to_tree(void)
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, b, NULL, &opts));
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
- git_diff_list_free(diff2);
+ git_diff_free(diff2);
for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
memset(&exp, 0, sizeof(exp));
@@ -194,7 +194,7 @@ void test_diff_workdir__to_tree(void)
cl_assert_equal_i(4, exp.line_dels);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(a);
git_tree_free(b);
@@ -203,7 +203,7 @@ void test_diff_workdir__to_tree(void)
void test_diff_workdir__to_index_with_pathspec(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
char *pathspec = NULL;
int use_iterator;
@@ -235,7 +235,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
cl_assert_equal_i(4, exp.file_status[GIT_DELTA_UNTRACKED]);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
pathspec = "modified_file";
@@ -258,7 +258,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
pathspec = "subdir";
@@ -281,7 +281,7 @@ void test_diff_workdir__to_index_with_pathspec(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
pathspec = "*_deleted";
@@ -304,12 +304,12 @@ void test_diff_workdir__to_index_with_pathspec(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_workdir__filemode_changes(void)
{
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
int use_iterator;
@@ -339,7 +339,7 @@ void test_diff_workdir__filemode_changes(void)
cl_assert_equal_i(0, exp.hunks);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* chmod file and test again */
@@ -362,14 +362,14 @@ void test_diff_workdir__filemode_changes(void)
cl_assert_equal_i(0, exp.hunks);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
}
void test_diff_workdir__filemode_changes_with_filemode_false(void)
{
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
if (!cl_is_chmod_supported())
@@ -391,7 +391,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(0, exp.hunks);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* chmod file and test again */
@@ -407,7 +407,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(0, exp.hunks);
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
}
@@ -415,7 +415,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
void test_diff_workdir__head_index_and_workdir_all_differ(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff_i2t = NULL, *diff_w2i = NULL;
+ git_diff *diff_i2t = NULL, *diff_w2i = NULL;
diff_expects exp;
char *pathspec = "staged_changes_modified_file";
git_tree *tree;
@@ -504,8 +504,8 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
cl_assert_equal_i(0, exp.line_dels);
}
- git_diff_list_free(diff_i2t);
- git_diff_list_free(diff_w2i);
+ git_diff_free(diff_i2t);
+ git_diff_free(diff_w2i);
git_tree_free(tree);
}
@@ -513,7 +513,7 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void)
void test_diff_workdir__eof_newline_changes(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
char *pathspec = "current_file";
int use_iterator;
@@ -546,7 +546,7 @@ void test_diff_workdir__eof_newline_changes(void)
cl_assert_equal_i(0, exp.line_dels);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_git_append2file("status/current_file", "\n");
@@ -573,7 +573,7 @@ void test_diff_workdir__eof_newline_changes(void)
cl_assert_equal_i(0, exp.line_dels);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_git_rewritefile("status/current_file", "current_file");
@@ -600,7 +600,7 @@ void test_diff_workdir__eof_newline_changes(void)
cl_assert_equal_i(2, exp.line_dels);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
/* PREPARATION OF TEST DATA
@@ -673,7 +673,7 @@ void test_diff_workdir__larger_hunks(void)
const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
git_tree *a, *b;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- size_t i, d, num_d, h, num_h, l, num_l, header_len, line_len;
+ size_t i, d, num_d, h, num_h, l, num_l;
g_repo = cl_git_sandbox_init("diff");
@@ -684,11 +684,10 @@ void test_diff_workdir__larger_hunks(void)
opts.interhunk_lines = 0;
for (i = 0; i <= 2; ++i) {
- git_diff_list *diff = NULL;
- git_diff_patch *patch;
- const git_diff_range *range;
- const char *header, *line;
- char origin;
+ git_diff *diff = NULL;
+ git_patch *patch;
+ const git_diff_hunk *hunk;
+ const git_diff_line *line;
/* okay, this is a bit silly, but oh well */
switch (i) {
@@ -707,33 +706,31 @@ void test_diff_workdir__larger_hunks(void)
cl_assert_equal_i(2, (int)num_d);
for (d = 0; d < num_d; ++d) {
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, d));
+ cl_git_pass(git_patch_from_diff(&patch, diff, d));
cl_assert(patch);
- num_h = git_diff_patch_num_hunks(patch);
+ num_h = git_patch_num_hunks(patch);
for (h = 0; h < num_h; h++) {
- cl_git_pass(git_diff_patch_get_hunk(
- &range, &header, &header_len, &num_l, patch, h));
+ cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h));
for (l = 0; l < num_l; ++l) {
- cl_git_pass(git_diff_patch_get_line_in_hunk(
- &origin, &line, &line_len, NULL, NULL, patch, h, l));
+ cl_git_pass(
+ git_patch_get_line_in_hunk(&line, patch, h, l));
cl_assert(line);
}
/* confirm fail after the last item */
- cl_git_fail(git_diff_patch_get_line_in_hunk(
- &origin, &line, &line_len, NULL, NULL, patch, h, num_l));
+ cl_git_fail(
+ git_patch_get_line_in_hunk(&line, patch, h, num_l));
}
/* confirm fail after the last item */
- cl_git_fail(git_diff_patch_get_hunk(
- &range, &header, &header_len, &num_l, patch, num_h));
+ cl_git_fail(git_patch_get_hunk(&hunk, &num_l, patch, num_h));
- git_diff_patch_free(patch);
+ git_patch_free(patch);
}
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
git_tree_free(a);
@@ -758,19 +755,10 @@ void test_diff_workdir__submodules(void)
const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698";
git_tree *a;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
- g_repo = cl_git_sandbox_init("submod2");
-
- cl_fixture_sandbox("submod2_target");
- p_rename("submod2_target/.gitted", "submod2_target/.git");
-
- rewrite_gitmodules(git_repository_workdir(g_repo));
- p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
- p_rename("submod2/not/.gitted", "submod2/not/.git");
-
- cl_fixture_cleanup("submod2_target");
+ g_repo = setup_fixture_submod2();
a = resolve_commit_oid_to_tree(g_repo, a_commit);
@@ -778,7 +766,7 @@ void test_diff_workdir__submodules(void)
GIT_DIFF_INCLUDE_UNTRACKED |
GIT_DIFF_INCLUDE_IGNORED |
GIT_DIFF_RECURSE_UNTRACKED_DIRS |
- GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
+ GIT_DIFF_SHOW_UNTRACKED_CONTENT;
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
@@ -828,14 +816,14 @@ void test_diff_workdir__submodules(void)
cl_assert_equal_i(30, exp.line_adds);
cl_assert_equal_i(1, exp.line_dels);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(a);
}
void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
git_tree *tree;
g_repo = cl_git_sandbox_init("testrepo.git");
@@ -853,7 +841,7 @@ void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
void test_diff_workdir__to_null_tree(void)
{
- git_diff_list *diff;
+ git_diff *diff;
diff_expects exp;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
@@ -871,12 +859,12 @@ void test_diff_workdir__to_null_tree(void)
cl_assert_equal_i(exp.files, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_workdir__checks_options_version(void)
{
- git_diff_list *diff;
+ git_diff *diff;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
const git_error *err;
@@ -896,11 +884,11 @@ void test_diff_workdir__checks_options_version(void)
void test_diff_workdir__can_diff_empty_file(void)
{
- git_diff_list *diff;
+ git_diff *diff;
git_tree *tree;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
struct stat st;
- git_diff_patch *patch;
+ git_patch *patch;
g_repo = cl_git_sandbox_init("attr_index");
@@ -910,7 +898,7 @@ void test_diff_workdir__can_diff_empty_file(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
cl_assert_equal_i(2, (int)git_diff_num_deltas(diff));
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* empty contents of file */
@@ -921,9 +909,9 @@ void test_diff_workdir__can_diff_empty_file(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
/* diffs are: .gitattributes, README.txt, sub/sub/.gitattributes */
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ cl_git_pass(git_patch_from_diff(&patch, diff, 1));
+ git_patch_free(patch);
+ git_diff_free(diff);
/* remove a file altogether */
@@ -932,9 +920,9 @@ void test_diff_workdir__can_diff_empty_file(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 1));
- git_diff_patch_free(patch);
- git_diff_list_free(diff);
+ cl_git_pass(git_patch_from_diff(&patch, diff, 1));
+ git_patch_free(patch);
+ git_diff_free(diff);
git_tree_free(tree);
}
@@ -942,7 +930,7 @@ void test_diff_workdir__can_diff_empty_file(void)
void test_diff_workdir__to_index_issue_1397(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
g_repo = cl_git_sandbox_init("issue_1397");
@@ -962,7 +950,7 @@ void test_diff_workdir__to_index_issue_1397(void)
cl_assert_equal_i(0, exp.hunks);
cl_assert_equal_i(0, exp.lines);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
cl_git_rewritefile("issue_1397/crlf_file.txt",
@@ -984,7 +972,7 @@ void test_diff_workdir__to_index_issue_1397(void)
cl_assert_equal_i(1, exp.line_adds);
cl_assert_equal_i(1, exp.line_dels);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_workdir__to_tree_issue_1397(void)
@@ -992,8 +980,8 @@ void test_diff_workdir__to_tree_issue_1397(void)
const char *a_commit = "7f483a738"; /* the current HEAD */
git_tree *a;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
- git_diff_list *diff2 = NULL;
+ git_diff *diff = NULL;
+ git_diff *diff2 = NULL;
diff_expects exp;
g_repo = cl_git_sandbox_init("issue_1397");
@@ -1015,13 +1003,13 @@ void test_diff_workdir__to_tree_issue_1397(void)
cl_assert_equal_i(0, exp.hunks);
cl_assert_equal_i(0, exp.lines);
- git_diff_list_free(diff);
+ git_diff_free(diff);
diff = NULL;
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
- git_diff_list_free(diff2);
+ git_diff_free(diff2);
memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach(
@@ -1031,14 +1019,14 @@ void test_diff_workdir__to_tree_issue_1397(void)
cl_assert_equal_i(0, exp.hunks);
cl_assert_equal_i(0, exp.lines);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(a);
}
void test_diff_workdir__untracked_directory_scenarios(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
char *pathspec = NULL;
static const char *files0[] = {
@@ -1088,7 +1076,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* empty directory */
@@ -1108,7 +1096,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* empty directory in empty directory */
@@ -1128,7 +1116,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* directory with only ignored files */
@@ -1152,7 +1140,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* directory with ignored directory (contents irrelevant) */
@@ -1175,11 +1163,11 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* quick version avoids directory scan */
- opts.flags = opts.flags | GIT_DIFF_FAST_UNTRACKED_DIRS;
+ opts.flags = opts.flags | GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS;
memset(&exp, 0, sizeof(exp));
exp.names = files1;
@@ -1195,11 +1183,11 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* directory with nested non-ignored content */
- opts.flags = opts.flags & ~GIT_DIFF_FAST_UNTRACKED_DIRS;
+ opts.flags = opts.flags & ~GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS;
cl_git_mkfile("status/subdir/directory/more/notignored",
"not ignored deep under untracked\n");
@@ -1218,7 +1206,7 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
/* use RECURSE_UNTRACKED_DIRS to get actual untracked files (no ignores) */
@@ -1239,14 +1227,14 @@ void test_diff_workdir__untracked_directory_scenarios(void)
cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_UNTRACKED]);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_workdir__untracked_directory_comes_last(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
g_repo = cl_git_sandbox_init("renames");
@@ -1264,13 +1252,13 @@ void test_diff_workdir__untracked_directory_comes_last(void)
cl_assert(diff != NULL);
- git_diff_list_free(diff);
+ git_diff_free(diff);
}
void test_diff_workdir__untracked_with_bom(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
const git_diff_delta *delta;
g_repo = cl_git_sandbox_init("empty_standard_repo");
@@ -1280,14 +1268,64 @@ void test_diff_workdir__untracked_with_bom(void)
"\xFF\xFE\x31\x00\x32\x00\x33\x00\x34\x00", 10, O_WRONLY|O_CREAT, 0664);
opts.flags =
- GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
+ GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_SHOW_UNTRACKED_CONTENT;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_i(1, git_diff_num_deltas(diff));
- cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 0));
+ cl_assert((delta = git_diff_get_delta(diff, 0)) != NULL);
cl_assert_equal_i(GIT_DELTA_UNTRACKED, delta->status);
- cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
- git_diff_list_free(diff);
+ /* not known at this point
+ * cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
+ */
+
+ git_diff_free(diff);
+}
+
+void test_diff_workdir__patience_diff(void)
+{
+ git_index *index;
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff *diff = NULL;
+ git_patch *patch = NULL;
+ char *as_str = NULL;
+ const char *expected_normal = "diff --git a/test.txt b/test.txt\nindex 34a5acc..d52725f 100644\n--- a/test.txt\n+++ b/test.txt\n@@ -1,10 +1,7 @@\n When I wrote this\n I did not know\n-how to create\n-a patience diff\n I did not know\n how to create\n+a patience diff\n another problem\n-I did not know\n-how to create\n a minimal diff\n";
+ const char *expected_patience = "diff --git a/test.txt b/test.txt\nindex 34a5acc..d52725f 100644\n--- a/test.txt\n+++ b/test.txt\n@@ -1,10 +1,7 @@\n When I wrote this\n I did not know\n+I did not know\n how to create\n a patience diff\n-I did not know\n-how to create\n another problem\n-I did not know\n-how to create\n a minimal diff\n";
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ cl_git_mkfile(
+ "empty_standard_repo/test.txt",
+ "When I wrote this\nI did not know\nhow to create\na patience diff\nI did not know\nhow to create\nanother problem\nI did not know\nhow to create\na minimal diff\n");
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 1372350000, "Base");
+
+ cl_git_rewritefile(
+ "empty_standard_repo/test.txt",
+ "When I wrote this\nI did not know\nI did not know\nhow to create\na patience diff\nanother problem\na minimal diff\n");
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_assert_equal_i(1, git_diff_num_deltas(diff));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&as_str, patch));
+
+ cl_assert_equal_s(expected_normal, as_str);
+ git__free(as_str);
+ git_patch_free(patch);
+ git_diff_free(diff);
+
+ opts.flags |= GIT_DIFF_PATIENCE;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_assert_equal_i(1, git_diff_num_deltas(diff));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_str(&as_str, patch));
+
+ cl_assert_equal_s(expected_patience, as_str);
+ git__free(as_str);
+ git_patch_free(patch);
+ git_diff_free(diff);
}
diff --git a/tests-clar/index/addall.c b/tests-clar/index/addall.c
index f46a1e16c..3b5f5f22d 100644
--- a/tests-clar/index/addall.c
+++ b/tests-clar/index/addall.c
@@ -111,8 +111,9 @@ static void check_stat_data(git_index *index, const char *path, bool match)
cl_assert(st.st_gid == entry->gid);
cl_assert_equal_i_fmt(
GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o");
- cl_assert_equal_b(
- GIT_PERMS_IS_EXEC(st.st_mode), GIT_PERMS_IS_EXEC(entry->mode));
+ if (cl_is_chmod_supported())
+ cl_assert_equal_b(
+ GIT_PERMS_IS_EXEC(st.st_mode), GIT_PERMS_IS_EXEC(entry->mode));
} else {
/* most things will still match */
cl_assert(st.st_size != entry->file_size);
diff --git a/tests-clar/index/filemodes.c b/tests-clar/index/filemodes.c
index 02f83efba..013932696 100644
--- a/tests-clar/index/filemodes.c
+++ b/tests-clar/index/filemodes.c
@@ -51,24 +51,29 @@ static void replace_file_with_mode(
git_buf_free(&content);
}
-static void add_and_check_mode(
- git_index *index, const char *filename, unsigned int expect_mode)
+#define add_and_check_mode(I,F,X) add_and_check_mode_(I,F,X,__FILE__,__LINE__)
+
+static void add_and_check_mode_(
+ git_index *index, const char *filename, unsigned int expect_mode,
+ const char *file, int line)
{
size_t pos;
const git_index_entry *entry;
cl_git_pass(git_index_add_bypath(index, filename));
- cl_assert(!git_index_find(&pos, index, filename));
+ clar__assert(!git_index_find(&pos, index, filename),
+ file, line, "Cannot find index entry", NULL, 1);
entry = git_index_get_byindex(index, pos);
- cl_assert(entry->mode == expect_mode);
+
+ clar__assert_equal(file, line, "Expected mode does not match index",
+ 1, "%07o", (unsigned int)entry->mode, (unsigned int)expect_mode);
}
void test_index_filemodes__untrusted(void)
{
git_index *index;
- bool can_filemode = cl_is_chmod_supported();
cl_repo_set_bool(g_repo, "core.filemode", false);
@@ -96,15 +101,10 @@ void test_index_filemodes__untrusted(void)
O_WRONLY | O_CREAT | O_TRUNC, 0644);
add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
- /* this test won't give predictable results on a platform
- * that doesn't support filemodes correctly, so skip it.
- */
- if (can_filemode) {
- /* 6 - add 0755 -> expect 0755 */
- cl_git_write2file("filemodes/new_on", "blah", 0,
- O_WRONLY | O_CREAT | O_TRUNC, 0755);
- add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
- }
+ /* 6 - add new 0755 -> expect 0644 if core.filemode == false */
+ cl_git_write2file("filemodes/new_on", "blah", 0,
+ O_WRONLY | O_CREAT | O_TRUNC, 0755);
+ add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB);
git_index_free(index);
}
diff --git a/tests-clar/index/names.c b/tests-clar/index/names.c
index 95a560ee4..87453ecbf 100644
--- a/tests-clar/index/names.c
+++ b/tests-clar/index/names.c
@@ -80,5 +80,69 @@ void test_index_names__roundtrip(void)
cl_assert(strcmp(conflict_name->ancestor, "ancestor3") == 0);
cl_assert(conflict_name->ours == NULL);
cl_assert(strcmp(conflict_name->theirs, "theirs3") == 0);
+}
+
+void test_index_names__cleaned_on_reset_hard(void)
+{
+ git_object *target;
+
+ retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
+
+ test_index_names__add();
+ cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
+ cl_assert(git_index_name_entrycount(repo_index) == 0);
+
+ git_object_free(target);
+}
+
+void test_index_names__cleaned_on_reset_mixed(void)
+{
+ git_object *target;
+
+ retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
+
+ test_index_names__add();
+ cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED));
+ cl_assert(git_index_name_entrycount(repo_index) == 0);
+
+ git_object_free(target);
+}
+
+void test_index_names__cleaned_on_checkout_tree(void)
+{
+ git_oid oid;
+ git_object *obj;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+
+ test_index_names__add();
+ git_reference_name_to_id(&oid, repo, "refs/heads/master");
+ git_object_lookup(&obj, repo, &oid, GIT_OBJ_ANY);
+ git_checkout_tree(repo, obj, &opts);
+ cl_assert(git_index_name_entrycount(repo_index) == 0);
+
+ git_object_free(obj);
+}
+
+void test_index_names__cleaned_on_checkout_head(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+
+ test_index_names__add();
+ git_checkout_head(repo, &opts);
+ cl_assert(git_index_name_entrycount(repo_index) == 0);
+}
+
+void test_index_names__retained_on_checkout_index(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
+ test_index_names__add();
+ git_checkout_index(repo, repo_index, &opts);
+ cl_assert(git_index_name_entrycount(repo_index) > 0);
}
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 9090d4d8a..009d393d7 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -99,11 +99,11 @@ void test_index_tests__default_test_index(void)
entries = (git_index_entry **)index->entries.contents;
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
- git_index_entry *e = entries[test_entries[i].index];
+ git_index_entry *e = entries[test_entries[i].index];
- cl_assert_equal_s(e->path, test_entries[i].path);
- cl_assert(e->mtime.seconds == test_entries[i].mtime);
- cl_assert(e->file_size == test_entries[i].file_size);
+ cl_assert_equal_s(e->path, test_entries[i].path);
+ cl_assert(e->mtime.seconds == test_entries[i].mtime);
+ cl_assert(e->file_size == test_entries[i].file_size);
}
git_index_free(index);
@@ -131,10 +131,10 @@ void test_index_tests__find_in_existing(void)
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
- size_t idx;
+ size_t idx;
- cl_assert(!git_index_find(&idx, index, test_entries[i].path));
- cl_assert(idx == test_entries[i].index);
+ cl_assert(!git_index_find(&idx, index, test_entries[i].path));
+ cl_assert(idx == test_entries[i].index);
}
git_index_free(index);
@@ -148,7 +148,7 @@ void test_index_tests__find_in_empty(void)
cl_git_pass(git_index_open(&index, "fake-index"));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
- cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path));
+ cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path));
}
git_index_free(index);
@@ -484,3 +484,53 @@ void test_index_tests__elocked(void)
git_index_free(index);
git_repository_free(repo);
}
+
+void test_index_tests__reload_from_disk(void)
+{
+ git_repository *repo;
+ git_index *read_index;
+ git_index *write_index;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ cl_git_pass(git_futils_mkdir("./myrepo", NULL, 0777, GIT_MKDIR_PATH));
+ cl_git_mkfile("./myrepo/a.txt", "a\n");
+ cl_git_mkfile("./myrepo/b.txt", "b\n");
+
+ cl_git_pass(git_repository_init(&repo, "./myrepo", 0));
+ cl_git_pass(git_repository_index(&write_index, repo));
+ cl_assert_equal_i(false, write_index->on_disk);
+
+ cl_git_pass(git_index_open(&read_index, write_index->index_file_path));
+ cl_assert_equal_i(false, read_index->on_disk);
+
+ /* Stage two new files agaisnt the write_index */
+ cl_git_pass(git_index_add_bypath(write_index, "a.txt"));
+ cl_git_pass(git_index_add_bypath(write_index, "b.txt"));
+
+ cl_assert_equal_sz(2, git_index_entrycount(write_index));
+
+ /* Persist the index changes to disk */
+ cl_git_pass(git_index_write(write_index));
+ cl_assert_equal_i(true, write_index->on_disk);
+
+ /* Sync the changes back into the read_index */
+ cl_assert_equal_sz(0, git_index_entrycount(read_index));
+
+ cl_git_pass(git_index_read(read_index));
+ cl_assert_equal_i(true, read_index->on_disk);
+
+ cl_assert_equal_sz(2, git_index_entrycount(read_index));
+
+ /* Remove the index file from the filesystem */
+ cl_git_pass(p_unlink(write_index->index_file_path));
+
+ /* Sync the changes back into the read_index */
+ cl_git_pass(git_index_read(read_index));
+ cl_assert_equal_i(false, read_index->on_disk);
+ cl_assert_equal_sz(0, git_index_entrycount(read_index));
+
+ git_index_free(read_index);
+ git_index_free(write_index);
+ git_repository_free(repo);
+}
diff --git a/tests-clar/merge/merge_helpers.c b/tests-clar/merge/merge_helpers.c
index e4092787c..ddcb93ff6 100644
--- a/tests-clar/merge/merge_helpers.c
+++ b/tests-clar/merge/merge_helpers.c
@@ -291,7 +291,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe
git_buf wd = GIT_BUF_INIT;
git_buf_puts(&wd, repo->workdir);
- git_path_direach(&wd, dircount, &actual_len);
+ git_path_direach(&wd, 0, dircount, &actual_len);
if (actual_len != expected_len)
return 0;
diff --git a/tests-clar/object/tree/attributes.c b/tests-clar/object/tree/attributes.c
index cc93b45d2..85216cd1b 100644
--- a/tests-clar/object/tree/attributes.c
+++ b/tests-clar/object/tree/attributes.c
@@ -107,7 +107,8 @@ void test_object_tree_attributes__normalize_600(void)
cl_git_pass(git_tree_lookup(&tree, repo, &id));
entry = git_tree_entry_byname(tree, "ListaTeste.xml");
- cl_assert_equal_i(entry->attr, GIT_FILEMODE_BLOB);
+ cl_assert_equal_i(git_tree_entry_filemode(entry), GIT_FILEMODE_BLOB);
+ cl_assert_equal_i(git_tree_entry_filemode_raw(entry), 0100600);
git_tree_free(tree);
cl_git_sandbox_cleanup();
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c
index 4a6ade52d..aa3d6b26a 100644
--- a/tests-clar/online/clone.c
+++ b/tests-clar/online/clone.c
@@ -11,6 +11,7 @@
#define BB_REPO_URL "https://libgit2@bitbucket.org/libgit2/testgitrepository.git"
#define BB_REPO_URL_WITH_PASS "https://libgit2:libgit2@bitbucket.org/libgit2/testgitrepository.git"
#define BB_REPO_URL_WITH_WRONG_PASS "https://libgit2:wrong@bitbucket.org/libgit2/testgitrepository.git"
+#define ASSEMBLA_REPO_URL "https://libgit2:_Libgit2@git.assembla.com/libgit2-test-repos.git"
static git_repository *g_repo;
static git_clone_options g_options;
@@ -227,6 +228,11 @@ void test_online_clone__bitbucket_style(void)
cl_fixture_cleanup("./foo");
}
+void test_online_clone__assembla_style(void)
+{
+ cl_git_pass(git_clone(&g_repo, ASSEMBLA_REPO_URL, "./foo", NULL));
+}
+
static int cancel_at_half(const git_transfer_progress *stats, void *payload)
{
GIT_UNUSED(payload);
diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c
index 05cef56e7..5a747bba7 100644
--- a/tests-clar/online/push.c
+++ b/tests-clar/online/push.c
@@ -20,7 +20,6 @@ static char *_remote_pass;
static int cred_acquire_cb(git_cred **, const char *, const char *, unsigned int, void *);
static git_remote *_remote;
-static bool _cred_acquire_called;
static record_callbacks_data _record_cbs_data = {{ 0 }};
static git_remote_callbacks _record_cbs = RECORD_CALLBACKS_INIT(&_record_cbs_data);
@@ -38,29 +37,41 @@ static git_oid _tag_lightweight;
static git_oid _tag_tag;
static int cred_acquire_cb(
- git_cred **cred,
- const char *url,
- const char *user_from_url,
- unsigned int allowed_types,
- void *payload)
+ git_cred **cred,
+ const char *url,
+ const char *user_from_url,
+ unsigned int allowed_types,
+ void *payload)
{
GIT_UNUSED(url);
GIT_UNUSED(user_from_url);
+ GIT_UNUSED(payload);
- *((bool*)payload) = true;
+ if (GIT_CREDTYPE_SSH_KEY & allowed_types) {
+ if (!_remote_user || !_remote_ssh_pubkey || !_remote_ssh_key || !_remote_ssh_passphrase) {
+ printf("GITTEST_REMOTE_USER, GITTEST_REMOTE_SSH_PUBKEY, GITTEST_REMOTE_SSH_KEY and GITTEST_REMOTE_SSH_PASSPHRASE must be set\n");
+ return -1;
+ }
+ return git_cred_ssh_key_new(cred, _remote_user, _remote_ssh_pubkey, _remote_ssh_key, _remote_ssh_passphrase);
+ }
- if (GIT_CREDTYPE_SSH_PUBLICKEY & allowed_types)
- return git_cred_ssh_keyfile_passphrase_new(cred, _remote_user, _remote_ssh_pubkey, _remote_ssh_key, _remote_ssh_passphrase);
+ if (GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) {
+ if (!_remote_user || !_remote_pass) {
+ printf("GITTEST_REMOTE_USER and GITTEST_REMOTE_PASS must be set\n");
+ return -1;
+ }
- if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 ||
- git_cred_userpass_plaintext_new(cred, _remote_user, _remote_pass) < 0)
- return -1;
+ return git_cred_userpass_plaintext_new(cred, _remote_user, _remote_pass);
+ }
- return 0;
+ return -1;
}
+/* the results of a push status. when used for expected values, msg may be NULL
+ * to indicate that it should not be matched. */
typedef struct {
const char *ref;
+ int success;
const char *msg;
} push_status;
@@ -75,6 +86,7 @@ static int record_push_status_cb(const char *ref, const char *msg, void *data)
cl_assert(s = git__malloc(sizeof(*s)));
s->ref = ref;
+ s->success = (msg == NULL);
s->msg = msg;
git_vector_insert(statuses, s);
@@ -96,9 +108,8 @@ static void do_verify_push_status(git_push *push, const push_status expected[],
else
git_vector_foreach(&actual, i, iter)
if (strcmp(expected[i].ref, iter->ref) ||
- (expected[i].msg && !iter->msg) ||
- (!expected[i].msg && iter->msg) ||
- (expected[i].msg && iter->msg && strcmp(expected[i].msg, iter->msg))) {
+ (expected[i].success != iter->success) ||
+ (expected[i].msg && (!iter->msg || strcmp(expected[i].msg, iter->msg)))) {
failed = true;
break;
}
@@ -111,13 +122,17 @@ static void do_verify_push_status(git_push *push, const push_status expected[],
for(i = 0; i < expected_len; i++) {
git_buf_printf(&msg, "%s: %s\n",
expected[i].ref,
- expected[i].msg ? expected[i].msg : "<NULL>");
+ expected[i].success ? "success" : "failed");
}
git_buf_puts(&msg, "\nACTUAL:\n");
- git_vector_foreach(&actual, i, iter)
- git_buf_printf(&msg, "%s: %s\n", iter->ref, iter->msg);
+ git_vector_foreach(&actual, i, iter) {
+ if (iter->success)
+ git_buf_printf(&msg, "%s: success\n", iter->ref);
+ else
+ git_buf_printf(&msg, "%s: failed with message: %s", iter->ref, iter->msg);
+ }
cl_fail(git_buf_cstr(&msg));
@@ -251,7 +266,6 @@ void test_online_push__initialize(void)
git_vector delete_specs = GIT_VECTOR_INIT;
size_t i;
char *curr_del_spec;
- _cred_acquire_called = false;
_repo = cl_git_sandbox_init("push_src");
@@ -349,16 +363,20 @@ void test_online_push__cleanup(void)
cl_git_sandbox_cleanup();
}
-static void push_pack_progress_cb(int stage, unsigned int current, unsigned int total, void* payload)
+static int push_pack_progress_cb(int stage, unsigned int current, unsigned int total, void* payload)
{
int *was_called = (int *) payload;
+ GIT_UNUSED(stage); GIT_UNUSED(current); GIT_UNUSED(total);
*was_called = 1;
+ return 0;
}
-static void push_transfer_progress_cb(unsigned int current, unsigned int total, size_t bytes, void* payload)
+static int push_transfer_progress_cb(unsigned int current, unsigned int total, size_t bytes, void* payload)
{
int *was_called = (int *) payload;
+ GIT_UNUSED(current); GIT_UNUSED(total); GIT_UNUSED(bytes);
*was_called = 1;
+ return 0;
}
/**
@@ -434,7 +452,7 @@ void test_online_push__noop(void)
void test_online_push__b1(void)
{
const char *specs[] = { "refs/heads/b1:refs/heads/b1" };
- push_status exp_stats[] = { { "refs/heads/b1", NULL } };
+ push_status exp_stats[] = { { "refs/heads/b1", 1 } };
expected_ref exp_refs[] = { { "refs/heads/b1", &_oid_b1 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -444,7 +462,7 @@ void test_online_push__b1(void)
void test_online_push__b2(void)
{
const char *specs[] = { "refs/heads/b2:refs/heads/b2" };
- push_status exp_stats[] = { { "refs/heads/b2", NULL } };
+ push_status exp_stats[] = { { "refs/heads/b2", 1 } };
expected_ref exp_refs[] = { { "refs/heads/b2", &_oid_b2 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -454,7 +472,7 @@ void test_online_push__b2(void)
void test_online_push__b3(void)
{
const char *specs[] = { "refs/heads/b3:refs/heads/b3" };
- push_status exp_stats[] = { { "refs/heads/b3", NULL } };
+ push_status exp_stats[] = { { "refs/heads/b3", 1 } };
expected_ref exp_refs[] = { { "refs/heads/b3", &_oid_b3 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -464,7 +482,7 @@ void test_online_push__b3(void)
void test_online_push__b4(void)
{
const char *specs[] = { "refs/heads/b4:refs/heads/b4" };
- push_status exp_stats[] = { { "refs/heads/b4", NULL } };
+ push_status exp_stats[] = { { "refs/heads/b4", 1 } };
expected_ref exp_refs[] = { { "refs/heads/b4", &_oid_b4 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -474,7 +492,7 @@ void test_online_push__b4(void)
void test_online_push__b5(void)
{
const char *specs[] = { "refs/heads/b5:refs/heads/b5" };
- push_status exp_stats[] = { { "refs/heads/b5", NULL } };
+ push_status exp_stats[] = { { "refs/heads/b5", 1 } };
expected_ref exp_refs[] = { { "refs/heads/b5", &_oid_b5 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -491,11 +509,11 @@ void test_online_push__multi(void)
"refs/heads/b5:refs/heads/b5"
};
push_status exp_stats[] = {
- { "refs/heads/b1", NULL },
- { "refs/heads/b2", NULL },
- { "refs/heads/b3", NULL },
- { "refs/heads/b4", NULL },
- { "refs/heads/b5", NULL }
+ { "refs/heads/b1", 1 },
+ { "refs/heads/b2", 1 },
+ { "refs/heads/b3", 1 },
+ { "refs/heads/b4", 1 },
+ { "refs/heads/b5", 1 }
};
expected_ref exp_refs[] = {
{ "refs/heads/b1", &_oid_b1 },
@@ -512,11 +530,11 @@ void test_online_push__multi(void)
void test_online_push__implicit_tgt(void)
{
const char *specs1[] = { "refs/heads/b1:" };
- push_status exp_stats1[] = { { "refs/heads/b1", NULL } };
+ push_status exp_stats1[] = { { "refs/heads/b1", 1 } };
expected_ref exp_refs1[] = { { "refs/heads/b1", &_oid_b1 } };
const char *specs2[] = { "refs/heads/b2:" };
- push_status exp_stats2[] = { { "refs/heads/b2", NULL } };
+ push_status exp_stats2[] = { { "refs/heads/b2", 1 } };
expected_ref exp_refs2[] = {
{ "refs/heads/b1", &_oid_b1 },
{ "refs/heads/b2", &_oid_b2 }
@@ -535,11 +553,11 @@ void test_online_push__fast_fwd(void)
/* Fast forward b1 in tgt from _oid_b1 to _oid_b6. */
const char *specs_init[] = { "refs/heads/b1:refs/heads/b1" };
- push_status exp_stats_init[] = { { "refs/heads/b1", NULL } };
+ push_status exp_stats_init[] = { { "refs/heads/b1", 1 } };
expected_ref exp_refs_init[] = { { "refs/heads/b1", &_oid_b1 } };
const char *specs_ff[] = { "refs/heads/b6:refs/heads/b1" };
- push_status exp_stats_ff[] = { { "refs/heads/b1", NULL } };
+ push_status exp_stats_ff[] = { { "refs/heads/b1", 1 } };
expected_ref exp_refs_ff[] = { { "refs/heads/b1", &_oid_b6 } };
/* Do a force push to reset b1 in target back to _oid_b1 */
@@ -567,7 +585,7 @@ void test_online_push__fast_fwd(void)
void test_online_push__tag_commit(void)
{
const char *specs[] = { "refs/tags/tag-commit:refs/tags/tag-commit" };
- push_status exp_stats[] = { { "refs/tags/tag-commit", NULL } };
+ push_status exp_stats[] = { { "refs/tags/tag-commit", 1 } };
expected_ref exp_refs[] = { { "refs/tags/tag-commit", &_tag_commit } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -577,7 +595,7 @@ void test_online_push__tag_commit(void)
void test_online_push__tag_tree(void)
{
const char *specs[] = { "refs/tags/tag-tree:refs/tags/tag-tree" };
- push_status exp_stats[] = { { "refs/tags/tag-tree", NULL } };
+ push_status exp_stats[] = { { "refs/tags/tag-tree", 1 } };
expected_ref exp_refs[] = { { "refs/tags/tag-tree", &_tag_tree } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -587,7 +605,7 @@ void test_online_push__tag_tree(void)
void test_online_push__tag_blob(void)
{
const char *specs[] = { "refs/tags/tag-blob:refs/tags/tag-blob" };
- push_status exp_stats[] = { { "refs/tags/tag-blob", NULL } };
+ push_status exp_stats[] = { { "refs/tags/tag-blob", 1 } };
expected_ref exp_refs[] = { { "refs/tags/tag-blob", &_tag_blob } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -597,7 +615,7 @@ void test_online_push__tag_blob(void)
void test_online_push__tag_lightweight(void)
{
const char *specs[] = { "refs/tags/tag-lightweight:refs/tags/tag-lightweight" };
- push_status exp_stats[] = { { "refs/tags/tag-lightweight", NULL } };
+ push_status exp_stats[] = { { "refs/tags/tag-lightweight", 1 } };
expected_ref exp_refs[] = { { "refs/tags/tag-lightweight", &_tag_lightweight } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -607,7 +625,7 @@ void test_online_push__tag_lightweight(void)
void test_online_push__tag_to_tag(void)
{
const char *specs[] = { "refs/tags/tag-tag:refs/tags/tag-tag" };
- push_status exp_stats[] = { { "refs/tags/tag-tag", NULL } };
+ push_status exp_stats[] = { { "refs/tags/tag-tag", 1 } };
expected_ref exp_refs[] = { { "refs/tags/tag-tag", &_tag_tag } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
@@ -617,13 +635,13 @@ void test_online_push__tag_to_tag(void)
void test_online_push__force(void)
{
const char *specs1[] = {"refs/heads/b3:refs/heads/tgt"};
- push_status exp_stats1[] = { { "refs/heads/tgt", NULL } };
+ push_status exp_stats1[] = { { "refs/heads/tgt", 1 } };
expected_ref exp_refs1[] = { { "refs/heads/tgt", &_oid_b3 } };
const char *specs2[] = {"refs/heads/b4:refs/heads/tgt"};
const char *specs2_force[] = {"+refs/heads/b4:refs/heads/tgt"};
- push_status exp_stats2_force[] = { { "refs/heads/tgt", NULL } };
+ push_status exp_stats2_force[] = { { "refs/heads/tgt", 1 } };
expected_ref exp_refs2_force[] = { { "refs/heads/tgt", &_oid_b4 } };
do_push(specs1, ARRAY_SIZE(specs1),
@@ -647,8 +665,8 @@ void test_online_push__delete(void)
"refs/heads/b1:refs/heads/tgt2"
};
push_status exp_stats1[] = {
- { "refs/heads/tgt1", NULL },
- { "refs/heads/tgt2", NULL }
+ { "refs/heads/tgt1", 1 },
+ { "refs/heads/tgt2", 1 }
};
expected_ref exp_refs1[] = {
{ "refs/heads/tgt1", &_oid_b1 },
@@ -658,10 +676,10 @@ void test_online_push__delete(void)
const char *specs_del_fake[] = { ":refs/heads/fake" };
/* Force has no effect for delete. */
const char *specs_del_fake_force[] = { "+:refs/heads/fake" };
- push_status exp_stats_fake[] = { { "refs/heads/fake", NULL } };
+ push_status exp_stats_fake[] = { { "refs/heads/fake", 1 } };
const char *specs_delete[] = { ":refs/heads/tgt1" };
- push_status exp_stats_delete[] = { { "refs/heads/tgt1", NULL } };
+ push_status exp_stats_delete[] = { { "refs/heads/tgt1", 1 } };
expected_ref exp_refs_delete[] = { { "refs/heads/tgt2", &_oid_b1 } };
/* Force has no effect for delete. */
const char *specs_delete_force[] = { "+:refs/heads/tgt1" };
@@ -720,8 +738,10 @@ void test_online_push__expressions(void)
/* TODO: Expressions in refspecs doesn't actually work yet */
const char *specs_left_expr[] = { "refs/heads/b2~1:refs/heads/b2" };
+ /* expect not NULL to indicate failure (core git replies "funny refname",
+ * other servers may be less pithy. */
const char *specs_right_expr[] = { "refs/heads/b2:refs/heads/b2~1" };
- push_status exp_stats_right_expr[] = { { "refs/heads/b2~1", "funny refname" } };
+ push_status exp_stats_right_expr[] = { { "refs/heads/b2~1", 0 } };
/* TODO: Find a more precise way of checking errors than a exit code of -1. */
do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr),
@@ -738,7 +758,7 @@ void test_online_push__notes(void)
git_oid note_oid, *target_oid, expected_oid;
git_signature *signature;
const char *specs[] = { "refs/notes/commits:refs/notes/commits" };
- push_status exp_stats[] = { { "refs/notes/commits", NULL } };
+ push_status exp_stats[] = { { "refs/notes/commits", 1 } };
expected_ref exp_refs[] = { { "refs/notes/commits", &expected_oid } };
git_oid_fromstr(&expected_oid, "8461a99b27b7043e58ff6e1f5d2cf07d282534fb");
diff --git a/tests-clar/pack/indexer.c b/tests-clar/pack/indexer.c
new file mode 100644
index 000000000..17ec7b3f8
--- /dev/null
+++ b/tests-clar/pack/indexer.c
@@ -0,0 +1,128 @@
+#include "clar_libgit2.h"
+#include <git2.h>
+#include "fileops.h"
+#include "hash.h"
+#include "iterator.h"
+#include "vector.h"
+#include "posix.h"
+
+
+/*
+ * This is a packfile with three objects. The second is a delta which
+ * depends on the third, which is also a delta.
+ */
+unsigned char out_of_order_pack[] = {
+ 0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03,
+ 0x32, 0x78, 0x9c, 0x63, 0x67, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x76,
+ 0xe6, 0x8f, 0xe8, 0x12, 0x9b, 0x54, 0x6b, 0x10, 0x1a, 0xee, 0x95, 0x10,
+ 0xc5, 0x32, 0x8e, 0x7f, 0x21, 0xca, 0x1d, 0x18, 0x78, 0x9c, 0x63, 0x62,
+ 0x66, 0x4e, 0xcb, 0xcf, 0x07, 0x00, 0x02, 0xac, 0x01, 0x4d, 0x75, 0x01,
+ 0xd7, 0x71, 0x36, 0x66, 0xf4, 0xde, 0x82, 0x27, 0x76, 0xc7, 0x62, 0x2c,
+ 0x10, 0xf1, 0xb0, 0x7d, 0xe2, 0x80, 0xdc, 0x78, 0x9c, 0x63, 0x62, 0x62,
+ 0x62, 0xb7, 0x03, 0x00, 0x00, 0x69, 0x00, 0x4c, 0xde, 0x7d, 0xaa, 0xe4,
+ 0x19, 0x87, 0x58, 0x80, 0x61, 0x09, 0x9a, 0x33, 0xca, 0x7a, 0x31, 0x92,
+ 0x6f, 0xae, 0x66, 0x75
+};
+unsigned int out_of_order_pack_len = 112;
+
+/*
+ * Packfile with two objects. The second is a delta against an object
+ * which is not in the packfile
+ */
+unsigned char thin_pack[] = {
+ 0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
+ 0x32, 0x78, 0x9c, 0x63, 0x67, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x76,
+ 0xe6, 0x8f, 0xe8, 0x12, 0x9b, 0x54, 0x6b, 0x10, 0x1a, 0xee, 0x95, 0x10,
+ 0xc5, 0x32, 0x8e, 0x7f, 0x21, 0xca, 0x1d, 0x18, 0x78, 0x9c, 0x63, 0x62,
+ 0x66, 0x4e, 0xcb, 0xcf, 0x07, 0x00, 0x02, 0xac, 0x01, 0x4d, 0x42, 0x52,
+ 0x3a, 0x6f, 0x39, 0xd1, 0xfe, 0x66, 0x68, 0x6b, 0xa5, 0xe5, 0xe2, 0x97,
+ 0xac, 0x94, 0x6c, 0x76, 0x0b, 0x04
+};
+unsigned int thin_pack_len = 78;
+
+unsigned char base_obj[] = { 07, 076 };
+unsigned int base_obj_len = 2;
+
+void test_pack_indexer__out_of_order(void)
+{
+ git_indexer_stream *idx;
+ git_transfer_progress stats;
+
+ cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL, NULL));
+ cl_git_pass(git_indexer_stream_add(idx, out_of_order_pack, out_of_order_pack_len, &stats));
+ cl_git_pass(git_indexer_stream_finalize(idx, &stats));
+
+ cl_assert_equal_i(stats.total_objects, 3);
+ cl_assert_equal_i(stats.received_objects, 3);
+ cl_assert_equal_i(stats.indexed_objects, 3);
+
+ git_indexer_stream_free(idx);
+}
+
+void test_pack_indexer__fix_thin(void)
+{
+ git_indexer_stream *idx;
+ git_transfer_progress stats;
+ git_repository *repo;
+ git_odb *odb;
+ git_oid id, should_id;
+
+ cl_git_pass(git_repository_init(&repo, "thin.git", true));
+ cl_git_pass(git_repository_odb(&odb, repo));
+
+ /* Store the missing base into your ODB so the indexer can fix the pack */
+ cl_git_pass(git_odb_write(&id, odb, base_obj, base_obj_len, GIT_OBJ_BLOB));
+ git_oid_fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18");
+ cl_assert(!git_oid_cmp(&id, &should_id));
+
+ cl_git_pass(git_indexer_stream_new(&idx, ".", odb, NULL, NULL));
+ cl_git_pass(git_indexer_stream_add(idx, thin_pack, thin_pack_len, &stats));
+ cl_git_pass(git_indexer_stream_finalize(idx, &stats));
+
+ cl_assert_equal_i(stats.total_objects, 2);
+ cl_assert_equal_i(stats.received_objects, 2);
+ cl_assert_equal_i(stats.indexed_objects, 2);
+ cl_assert_equal_i(stats.local_objects, 1);
+
+ git_oid_fromstr(&should_id, "11f0f69b334728fdd8bc86b80499f22f29d85b15");
+ cl_assert(!git_oid_cmp(git_indexer_stream_hash(idx), &should_id));
+
+ git_indexer_stream_free(idx);
+ git_odb_free(odb);
+ git_repository_free(repo);
+
+ /*
+ * The pack's name/hash only tells us what objects there are,
+ * so we need to go through the packfile again in order to
+ * figure out whether we calculated the trailer correctly.
+ */
+ {
+ unsigned char buffer[128];
+ int fd;
+ ssize_t read;
+ git_off_t left;
+ struct stat st;
+ const char *name = "pack-11f0f69b334728fdd8bc86b80499f22f29d85b15.pack";
+
+ fd = p_open(name, O_RDONLY);
+ cl_assert(fd != -1);
+
+ cl_git_pass(p_stat(name, &st));
+ left = st.st_size;
+
+ cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL, NULL));
+ read = p_read(fd, buffer, sizeof(buffer));
+ cl_assert(read != -1);
+ p_close(fd);
+
+ cl_git_pass(git_indexer_stream_add(idx, buffer, read, &stats));
+ cl_git_pass(git_indexer_stream_finalize(idx, &stats));
+
+ cl_assert_equal_i(stats.total_objects, 3);
+ cl_assert_equal_i(stats.received_objects, 3);
+ cl_assert_equal_i(stats.indexed_objects, 3);
+ cl_assert_equal_i(stats.local_objects, 0);
+
+ git_indexer_stream_free(idx);
+ }
+}
diff --git a/tests-clar/pack/packbuilder.c b/tests-clar/pack/packbuilder.c
index 764fba213..69292567e 100644
--- a/tests-clar/pack/packbuilder.c
+++ b/tests-clar/pack/packbuilder.c
@@ -92,7 +92,7 @@ void test_pack_packbuilder__create_pack(void)
seed_packbuilder();
- cl_git_pass(git_indexer_stream_new(&_indexer, ".", NULL, NULL));
+ cl_git_pass(git_indexer_stream_new(&_indexer, ".", NULL, NULL, NULL));
cl_git_pass(git_packbuilder_foreach(_packbuilder, feed_indexer, &stats));
cl_git_pass(git_indexer_stream_finalize(_indexer, &stats));
@@ -141,7 +141,7 @@ void test_pack_packbuilder__foreach(void)
git_indexer_stream *idx;
seed_packbuilder();
- cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL));
+ cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL, NULL));
cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx));
cl_git_pass(git_indexer_stream_finalize(idx, &stats));
git_indexer_stream_free(idx);
diff --git a/tests-clar/refs/lookup.c b/tests-clar/refs/lookup.c
index 0dbebc5c2..2e31cf0f6 100644
--- a/tests-clar/refs/lookup.c
+++ b/tests-clar/refs/lookup.c
@@ -46,3 +46,15 @@ void test_refs_lookup__oid(void)
cl_git_pass(git_oid_fromstr(&expected, "1385f264afb75a56a5bec74243be9b367ba4ca08"));
cl_assert(git_oid_cmp(&tag, &expected) == 0);
}
+
+void test_refs_lookup__namespace(void)
+{
+ int error;
+ git_reference *ref;
+
+ error = git_reference_lookup(&ref, g_repo, "refs/heads");
+ cl_assert_equal_i(error, GIT_ENOTFOUND);
+
+ error = git_reference_lookup(&ref, g_repo, "refs/heads/");
+ cl_assert_equal_i(error, GIT_EINVALIDSPEC);
+}
diff --git a/tests-clar/refs/reflog/drop.c b/tests-clar/refs/reflog/drop.c
index 21cc847bf..916bd9933 100644
--- a/tests-clar/refs/reflog/drop.c
+++ b/tests-clar/refs/reflog/drop.c
@@ -8,15 +8,10 @@ static size_t entrycount;
void test_refs_reflog_drop__initialize(void)
{
- git_reference *ref;
-
g_repo = cl_git_sandbox_init("testrepo.git");
- cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
- git_reflog_read(&g_reflog, ref);
+ git_reflog_read(&g_reflog, g_repo, "HEAD");
entrycount = git_reflog_entrycount(g_reflog);
-
- git_reference_free(ref);
}
void test_refs_reflog_drop__cleanup(void)
@@ -106,19 +101,15 @@ void test_refs_reflog_drop__can_drop_all_the_entries(void)
void test_refs_reflog_drop__can_persist_deletion_on_disk(void)
{
- git_reference *ref;
-
cl_assert(entrycount > 2);
- cl_git_pass(git_reference_lookup(&ref, g_repo, g_reflog->ref_name));
cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
cl_git_pass(git_reflog_write(g_reflog));
git_reflog_free(g_reflog);
- git_reflog_read(&g_reflog, ref);
- git_reference_free(ref);
+ git_reflog_read(&g_reflog, g_repo, "HEAD");
cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
}
diff --git a/tests-clar/refs/reflog/reflog.c b/tests-clar/refs/reflog/reflog.c
index 095cabf04..bcd224270 100644
--- a/tests-clar/refs/reflog/reflog.c
+++ b/tests-clar/refs/reflog/reflog.c
@@ -13,7 +13,7 @@ static git_repository *g_repo;
// helpers
-static void assert_signature(git_signature *expected, git_signature *actual)
+static void assert_signature(const git_signature *expected, const git_signature *actual)
{
cl_assert(actual);
cl_assert_equal_s(expected->name, actual->name);
@@ -34,30 +34,13 @@ void test_refs_reflog_reflog__cleanup(void)
cl_git_sandbox_cleanup();
}
-void test_refs_reflog_reflog__append_then_read(void)
+static void assert_appends(const git_signature *committer, const git_oid *oid)
{
- // write a reflog for a given reference and ensure it can be read back
git_repository *repo2;
- git_reference *ref, *lookedup_ref;
- git_oid oid;
- git_signature *committer;
+ git_reference *lookedup_ref;
git_reflog *reflog;
const git_reflog_entry *entry;
- /* Create a new branch pointing at the HEAD */
- git_oid_fromstr(&oid, current_master_tip);
- cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0));
-
- cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
-
- cl_git_pass(git_reflog_read(&reflog, ref));
-
- cl_git_fail(git_reflog_append(reflog, &oid, committer, "no inner\nnewline"));
- cl_git_pass(git_reflog_append(reflog, &oid, committer, NULL));
- cl_git_pass(git_reflog_append(reflog, &oid, committer, commit_msg "\n"));
- cl_git_pass(git_reflog_write(reflog));
- git_reflog_free(reflog);
-
/* Reopen a new instance of the repository */
cl_git_pass(git_repository_open(&repo2, "testrepo.git"));
@@ -65,29 +48,78 @@ void test_refs_reflog_reflog__append_then_read(void)
cl_git_pass(git_reference_lookup(&lookedup_ref, repo2, new_ref));
/* Read and parse the reflog for this branch */
- cl_git_pass(git_reflog_read(&reflog, lookedup_ref));
+ cl_git_pass(git_reflog_read(&reflog, repo2, new_ref));
cl_assert_equal_i(2, (int)git_reflog_entrycount(reflog));
entry = git_reflog_entry_byindex(reflog, 1);
assert_signature(committer, entry->committer);
cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
- cl_assert(git_oid_cmp(&oid, &entry->oid_cur) == 0);
+ cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
cl_assert(entry->msg == NULL);
entry = git_reflog_entry_byindex(reflog, 0);
assert_signature(committer, entry->committer);
- cl_assert(git_oid_cmp(&oid, &entry->oid_old) == 0);
- cl_assert(git_oid_cmp(&oid, &entry->oid_cur) == 0);
+ cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0);
+ cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
cl_assert_equal_s(commit_msg, entry->msg);
- git_signature_free(committer);
git_reflog_free(reflog);
git_repository_free(repo2);
- git_reference_free(ref);
git_reference_free(lookedup_ref);
}
+void test_refs_reflog_reflog__append_then_read(void)
+{
+ /* write a reflog for a given reference and ensure it can be read back */
+ git_reference *ref;
+ git_oid oid;
+ git_signature *committer;
+ git_reflog *reflog;
+
+ /* Create a new branch pointing at the HEAD */
+ git_oid_fromstr(&oid, current_master_tip);
+ cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0));
+ git_reference_free(ref);
+
+ cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
+
+ cl_git_pass(git_reflog_read(&reflog, g_repo, new_ref));
+
+ cl_git_fail(git_reflog_append(reflog, &oid, committer, "no inner\nnewline"));
+ cl_git_pass(git_reflog_append(reflog, &oid, committer, NULL));
+ cl_git_pass(git_reflog_append(reflog, &oid, committer, commit_msg "\n"));
+ cl_git_pass(git_reflog_write(reflog));
+ git_reflog_free(reflog);
+
+ assert_appends(committer, &oid);
+
+ git_signature_free(committer);
+}
+
+void test_refs_reflog_reflog__append_to_then_read(void)
+{
+ /* write a reflog for a given reference and ensure it can be read back */
+ git_reference *ref;
+ git_oid oid;
+ git_signature *committer;
+
+ /* Create a new branch pointing at the HEAD */
+ git_oid_fromstr(&oid, current_master_tip);
+ cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0));
+ git_reference_free(ref);
+
+ cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
+
+ cl_git_fail(git_reflog_append_to(g_repo, new_ref, &oid, committer, "no inner\nnewline"));
+ cl_git_pass(git_reflog_append_to(g_repo, new_ref, &oid, committer, NULL));
+ cl_git_pass(git_reflog_append_to(g_repo, new_ref, &oid, committer, commit_msg "\n"));
+
+ assert_appends(committer, &oid);
+
+ git_signature_free(committer);
+}
+
void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
{
git_reference *master, *new_master;
@@ -133,21 +165,18 @@ void test_refs_reflog_reflog__reference_has_reflog(void)
void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_returns_an_empty_one(void)
{
- git_reference *subtrees;
git_reflog *reflog;
+ const char *refname = "refs/heads/subtrees";
git_buf subtrees_log_path = GIT_BUF_INIT;
- cl_git_pass(git_reference_lookup(&subtrees, g_repo, "refs/heads/subtrees"));
-
- git_buf_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, git_reference_name(subtrees));
+ git_buf_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname);
cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&subtrees_log_path)));
- cl_git_pass(git_reflog_read(&reflog, subtrees));
+ cl_git_pass(git_reflog_read(&reflog, g_repo, refname));
cl_assert_equal_i(0, (int)git_reflog_entrycount(reflog));
git_reflog_free(reflog);
- git_reference_free(subtrees);
git_buf_free(&subtrees_log_path);
}
@@ -158,7 +187,7 @@ void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
git_reflog *reflog;
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
- cl_git_pass(git_reflog_read(&reflog, master));
+ cl_git_pass(git_reflog_read(&reflog, g_repo, "refs/heads/master"));
cl_git_pass(git_reflog_write(reflog));
@@ -175,12 +204,6 @@ void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
void test_refs_reflog_reflog__renaming_with_an_invalid_name_returns_EINVALIDSPEC(void)
{
- git_reference *master;
-
- cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
-
cl_assert_equal_i(GIT_EINVALIDSPEC,
- git_reflog_rename(master, "refs/heads/Inv@{id"));
-
- git_reference_free(master);
+ git_reflog_rename(g_repo, "refs/heads/master", "refs/heads/Inv@{id"));
}
diff --git a/tests-clar/refs/unicode.c b/tests-clar/refs/unicode.c
index 2ec103275..b56012869 100644
--- a/tests-clar/refs/unicode.c
+++ b/tests-clar/refs/unicode.c
@@ -4,17 +4,13 @@ static git_repository *repo;
void test_refs_unicode__initialize(void)
{
- cl_fixture_sandbox("testrepo.git");
-
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+ repo = cl_git_sandbox_init("testrepo.git");
}
void test_refs_unicode__cleanup(void)
{
- git_repository_free(repo);
+ cl_git_sandbox_cleanup();
repo = NULL;
-
- cl_fixture_cleanup("testrepo.git");
}
void test_refs_unicode__create_and_lookup(void)
@@ -22,23 +18,39 @@ void test_refs_unicode__create_and_lookup(void)
git_reference *ref0, *ref1, *ref2;
git_repository *repo2;
- const char *REFNAME = "refs/heads/" "\305" "ngstr" "\366" "m";
+ const char *REFNAME = "refs/heads/" "\303\205" "ngstr" "\303\266" "m";
const char *master = "refs/heads/master";
/* Create the reference */
cl_git_pass(git_reference_lookup(&ref0, repo, master));
- cl_git_pass(git_reference_create(&ref1, repo, REFNAME, git_reference_target(ref0), 0));
+ cl_git_pass(git_reference_create(
+ &ref1, repo, REFNAME, git_reference_target(ref0), 0));
cl_assert_equal_s(REFNAME, git_reference_name(ref1));
+ git_reference_free(ref0);
/* Lookup the reference in a different instance of the repository */
cl_git_pass(git_repository_open(&repo2, "testrepo.git"));
+
cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME));
+ cl_assert_equal_i(
+ 0, git_oid_cmp(git_reference_target(ref1), git_reference_target(ref2)));
+ cl_assert_equal_s(REFNAME, git_reference_name(ref2));
+ git_reference_free(ref2);
- cl_assert(git_oid_cmp(git_reference_target(ref1), git_reference_target(ref2)) == 0);
+#if GIT_USE_ICONV
+ /* Lookup reference by decomposed unicode name */
+
+#define REFNAME_DECOMPOSED "refs/heads/" "A" "\314\212" "ngstro" "\314\210" "m"
+
+ cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME_DECOMPOSED));
+ cl_assert_equal_i(
+ 0, git_oid_cmp(git_reference_target(ref1), git_reference_target(ref2)));
cl_assert_equal_s(REFNAME, git_reference_name(ref2));
+ git_reference_free(ref2);
+#endif
+
+ /* Cleanup */
- git_reference_free(ref0);
git_reference_free(ref1);
- git_reference_free(ref2);
git_repository_free(repo2);
}
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c
index 392be205b..617fdf879 100644
--- a/tests-clar/repo/init.c
+++ b/tests-clar/repo/init.c
@@ -179,41 +179,32 @@ void test_repo_init__additional_templates(void)
git_buf_free(&path);
}
-static void assert_config_entry_on_init_bytype(const char *config_key, int expected_value, bool is_bare)
+static void assert_config_entry_on_init_bytype(
+ const char *config_key, int expected_value, bool is_bare)
{
git_config *config;
- int current_value;
- git_buf repo_path = GIT_BUF_INIT;
+ int error, current_value;
+ const char *repo_path = is_bare ?
+ "config_entry/test.bare.git" : "config_entry/test.non.bare.git";
cl_set_cleanup(&cleanup_repository, "config_entry");
- cl_git_pass(git_buf_puts(&repo_path, "config_entry/test."));
-
- if (!is_bare)
- cl_git_pass(git_buf_puts(&repo_path, "non."));
-
- cl_git_pass(git_buf_puts(&repo_path, "bare.git"));
-
- cl_git_pass(git_repository_init(&_repo, git_buf_cstr(&repo_path), is_bare));
+ cl_git_pass(git_repository_init(&_repo, repo_path, is_bare));
- git_buf_free(&repo_path);
-
- git_repository_config(&config, _repo);
+ cl_git_pass(git_repository_config(&config, _repo));
+ error = git_config_get_bool(&current_value, config, config_key);
+ git_config_free(config);
if (expected_value >= 0) {
- cl_git_pass(git_config_get_bool(&current_value, config, config_key));
-
+ cl_assert_equal_i(0, error);
cl_assert_equal_i(expected_value, current_value);
} else {
- int error = git_config_get_bool(&current_value, config, config_key);
-
cl_assert_equal_i(expected_value, error);
}
-
- git_config_free(config);
}
-static void assert_config_entry_on_init(const char *config_key, int expected_value)
+static void assert_config_entry_on_init(
+ const char *config_key, int expected_value)
{
assert_config_entry_on_init_bytype(config_key, expected_value, true);
git_repository_free(_repo);
@@ -223,21 +214,36 @@ static void assert_config_entry_on_init(const char *config_key, int expected_val
void test_repo_init__detect_filemode(void)
{
-#ifdef GIT_WIN32
- assert_config_entry_on_init("core.filemode", false);
-#else
- assert_config_entry_on_init("core.filemode", true);
-#endif
+ assert_config_entry_on_init("core.filemode", cl_is_chmod_supported());
}
-#define CASE_INSENSITIVE_FILESYSTEM (defined GIT_WIN32 || defined __APPLE__)
-
void test_repo_init__detect_ignorecase(void)
{
-#if CASE_INSENSITIVE_FILESYSTEM
- assert_config_entry_on_init("core.ignorecase", true);
+ struct stat st;
+ bool found_without_match;
+
+ cl_git_write2file("testCAPS", "whatever\n", 0, O_CREAT | O_WRONLY, 0666);
+ found_without_match = (p_stat("Testcaps", &st) == 0);
+ cl_must_pass(p_unlink("testCAPS"));
+
+ assert_config_entry_on_init(
+ "core.ignorecase", found_without_match ? true : GIT_ENOTFOUND);
+}
+
+void test_repo_init__detect_precompose_unicode_required(void)
+{
+ char *composed = "ḱṷṓn", *decomposed = "ḱṷṓn";
+ struct stat st;
+ bool found_with_nfd;
+
+ cl_git_write2file(composed, "whatever\n", 0, O_CREAT | O_WRONLY, 0666);
+ found_with_nfd = (p_stat(decomposed, &st) == 0);
+ cl_must_pass(p_unlink(composed));
+
+#ifdef GIT_USE_ICONV
+ assert_config_entry_on_init("core.precomposeunicode", found_with_nfd);
#else
- assert_config_entry_on_init("core.ignorecase", GIT_ENOTFOUND);
+ assert_config_entry_on_init("core.precomposeunicode", GIT_ENOTFOUND);
#endif
}
@@ -270,13 +276,7 @@ void test_repo_init__reinit_doesnot_overwrite_ignorecase(void)
void test_repo_init__reinit_overwrites_filemode(void)
{
- int expected, current_value;
-
-#ifdef GIT_WIN32
- expected = false;
-#else
- expected = true;
-#endif
+ int expected = cl_is_chmod_supported(), current_value;
/* Init a new repo */
cl_set_cleanup(&cleanup_repository, "overwrite.git");
@@ -348,7 +348,10 @@ void test_repo_init__extended_1(void)
cl_git_pass(git_path_lstat(git_repository_path(_repo), &st));
cl_assert(S_ISDIR(st.st_mode));
- cl_assert((S_ISGID & st.st_mode) == S_ISGID);
+ if (cl_is_chmod_supported())
+ cl_assert((S_ISGID & st.st_mode) == S_ISGID);
+ else
+ cl_assert((S_ISGID & st.st_mode) == 0);
cl_git_pass(git_reference_lookup(&ref, _repo, "HEAD"));
cl_assert(git_reference_type(ref) == GIT_REF_SYMBOLIC);
diff --git a/tests-clar/resources/merge-resolve/.gitted/objects/1a/010b1c0f081b2e8901d55307a15c29ff30af0e b/tests-clar/resources/merge-resolve/.gitted/objects/1a/010b1c0f081b2e8901d55307a15c29ff30af0e
new file mode 100644
index 000000000..6039df00e
--- /dev/null
+++ b/tests-clar/resources/merge-resolve/.gitted/objects/1a/010b1c0f081b2e8901d55307a15c29ff30af0e
Binary files differ
diff --git a/tests-clar/resources/merge-resolve/.gitted/objects/72/ea499e108df5ff0a4a913e7655bbeeb1fb69f2 b/tests-clar/resources/merge-resolve/.gitted/objects/72/ea499e108df5ff0a4a913e7655bbeeb1fb69f2
new file mode 100644
index 000000000..4886e492e
--- /dev/null
+++ b/tests-clar/resources/merge-resolve/.gitted/objects/72/ea499e108df5ff0a4a913e7655bbeeb1fb69f2
Binary files differ
diff --git a/tests-clar/resources/merge-resolve/.gitted/objects/8b/fb012a6d809e499bd8d3e194a3929bc8995b93 b/tests-clar/resources/merge-resolve/.gitted/objects/8b/fb012a6d809e499bd8d3e194a3929bc8995b93
new file mode 100644
index 000000000..a90ee08ce
--- /dev/null
+++ b/tests-clar/resources/merge-resolve/.gitted/objects/8b/fb012a6d809e499bd8d3e194a3929bc8995b93
Binary files differ
diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c
index 59413f01e..63ff0377c 100644
--- a/tests-clar/stash/drop.c
+++ b/tests-clar/stash/drop.c
@@ -102,7 +102,7 @@ void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void)
cl_git_pass(git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE));
- cl_git_pass(git_reflog_read(&reflog, stash));
+ cl_git_pass(git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE));
entry = git_reflog_entry_byindex(reflog, 1);
git_oid_cpy(&oid, git_reflog_entry_id_old(entry));
@@ -112,7 +112,7 @@ void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void)
cl_git_pass(git_stash_drop(repo, 1));
- cl_git_pass(git_reflog_read(&reflog, stash));
+ cl_git_pass(git_reflog_read(&reflog, repo, GIT_REFS_STASH_FILE));
entry = git_reflog_entry_byindex(reflog, 0);
cl_assert_equal_i(0, git_oid_cmp(&oid, git_reflog_entry_id_old(entry)));
diff --git a/tests-clar/status/renames.c b/tests-clar/status/renames.c
index de84a574d..16fd02676 100644
--- a/tests-clar/status/renames.c
+++ b/tests-clar/status/renames.c
@@ -69,14 +69,14 @@ static void test_status(
actual = git_status_byindex(status_list, i);
expected = &expected_list[i];
- cl_assert_equal_i_fmt(expected->status, actual->status, "%04x");
-
oldname = actual->head_to_index ? actual->head_to_index->old_file.path :
actual->index_to_workdir ? actual->index_to_workdir->old_file.path : NULL;
newname = actual->index_to_workdir ? actual->index_to_workdir->new_file.path :
actual->head_to_index ? actual->head_to_index->new_file.path : NULL;
+ cl_assert_equal_i_fmt(expected->status, actual->status, "%04x");
+
if (oldname)
cl_assert(git__strcmp(oldname, expected->oldname) == 0);
else
@@ -507,14 +507,14 @@ void test_status_renames__both_casechange_two(void)
"untimely.txt", "untimeliest.txt" }
};
struct status_entry expected_case[] = {
- { GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED |
- GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
- "ikeepsix.txt", "ikeepsix.txt" },
- { GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_RENAMED,
- "sixserving.txt", "SixServing.txt" },
{ GIT_STATUS_INDEX_RENAMED |
GIT_STATUS_WT_MODIFIED | GIT_STATUS_WT_RENAMED,
"songof7cities.txt", "SONGOF7.txt" },
+ { GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_RENAMED,
+ "sixserving.txt", "SixServing.txt" },
+ { GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED |
+ GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
+ "ikeepsix.txt", "ikeepsix.txt" },
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
"untimely.txt", "untimeliest.txt" }
};
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 135a95871..3b569c7ba 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -119,7 +119,7 @@ void test_status_worktree__purged_worktree(void)
/* first purge the contents of the worktree */
cl_git_pass(git_buf_sets(&workdir, git_repository_workdir(repo)));
- cl_git_pass(git_path_direach(&workdir, remove_file_cb, NULL));
+ cl_git_pass(git_path_direach(&workdir, 0, remove_file_cb, NULL));
git_buf_free(&workdir);
/* now get status */
diff --git a/tests-clar/stress/diff.c b/tests-clar/stress/diff.c
index 1d319738e..3d2092614 100644
--- a/tests-clar/stress/diff.c
+++ b/tests-clar/stress/diff.c
@@ -19,7 +19,7 @@ static void test_with_many(int expected_new)
{
git_index *index;
git_tree *tree, *new_tree;
- git_diff_list *diff = NULL;
+ git_diff *diff = NULL;
diff_expects exp;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
@@ -52,7 +52,7 @@ static void test_with_many(int expected_new)
cl_assert_equal_i(expected_new, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(expected_new + 1, exp.files);
- git_diff_list_free(diff);
+ git_diff_free(diff);
cl_repo_commit_from_index(NULL, g_repo, NULL, 1372350000, "yoyoyo");
cl_git_pass(git_revparse_single(
@@ -78,7 +78,7 @@ static void test_with_many(int expected_new)
cl_assert_equal_i(expected_new, exp.file_status[GIT_DELTA_ADDED]);
cl_assert_equal_i(expected_new + 1, exp.files);
- git_diff_list_free(diff);
+ git_diff_free(diff);
git_tree_free(new_tree);
git_tree_free(tree);
diff --git a/tests-clar/submodule/lookup.c b/tests-clar/submodule/lookup.c
index b626cdf04..5f320e702 100644
--- a/tests-clar/submodule/lookup.c
+++ b/tests-clar/submodule/lookup.c
@@ -7,20 +7,7 @@ static git_repository *g_repo = NULL;
void test_submodule_lookup__initialize(void)
{
- g_repo = cl_git_sandbox_init("submod2");
-
- cl_fixture_sandbox("submod2_target");
- p_rename("submod2_target/.gitted", "submod2_target/.git");
-
- /* must create submod2_target before rewrite so prettify will work */
- rewrite_gitmodules(git_repository_workdir(g_repo));
- p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
-}
-
-void test_submodule_lookup__cleanup(void)
-{
- cl_git_sandbox_cleanup();
- cl_fixture_cleanup("submod2_target");
+ g_repo = setup_fixture_submod2();
}
void test_submodule_lookup__simple_lookup(void)
diff --git a/tests-clar/submodule/modify.c b/tests-clar/submodule/modify.c
index c0498ce6e..e326287a6 100644
--- a/tests-clar/submodule/modify.c
+++ b/tests-clar/submodule/modify.c
@@ -11,20 +11,7 @@ static git_repository *g_repo = NULL;
void test_submodule_modify__initialize(void)
{
- g_repo = cl_git_sandbox_init("submod2");
-
- cl_fixture_sandbox("submod2_target");
- p_rename("submod2_target/.gitted", "submod2_target/.git");
-
- /* must create submod2_target before rewrite so prettify will work */
- rewrite_gitmodules(git_repository_workdir(g_repo));
- p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
-}
-
-void test_submodule_modify__cleanup(void)
-{
- cl_git_sandbox_cleanup();
- cl_fixture_cleanup("submod2_target");
+ g_repo = setup_fixture_submod2();
}
void test_submodule_modify__add(void)
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
index f1227a575..f5111c84f 100644
--- a/tests-clar/submodule/status.c
+++ b/tests-clar/submodule/status.c
@@ -388,7 +388,8 @@ void test_submodule_status__iterator(void)
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_INCLUDE_UNMODIFIED |
GIT_STATUS_OPT_INCLUDE_IGNORED |
- GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS |
+ GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, confirm_submodule_status, &exp));
diff --git a/tests-clar/submodule/submodule_helpers.c b/tests-clar/submodule/submodule_helpers.c
index 3e79c77fd..d5750675c 100644
--- a/tests-clar/submodule/submodule_helpers.c
+++ b/tests-clar/submodule/submodule_helpers.c
@@ -4,6 +4,7 @@
#include "util.h"
#include "posix.h"
#include "submodule_helpers.h"
+#include "git2/sys/repository.h"
/* rewrite gitmodules -> .gitmodules
* rewrite the empty or relative urls inside each module
@@ -102,6 +103,8 @@ git_repository *setup_fixture_submodules(void)
cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git");
+ cl_git_pass(git_repository_reinit_filesystem(repo, 1));
+
return repo;
}
@@ -118,5 +121,7 @@ git_repository *setup_fixture_submod2(void)
cl_set_cleanup(cleanup_fixture_submodules, "submod2_target");
+ cl_git_pass(git_repository_reinit_filesystem(repo, 1));
+
return repo;
}
diff --git a/tests-clar/threads/basic.c b/tests-clar/threads/basic.c
index a15c53140..a329ee7f9 100644
--- a/tests-clar/threads/basic.c
+++ b/tests-clar/threads/basic.c
@@ -21,3 +21,16 @@ void test_threads_basic__cache(void)
// run several threads polling the cache at the same time
cl_assert(1 == 1);
}
+
+void test_threads_basic__multiple_init(void)
+{
+ git_repository *nested_repo;
+
+ git_threads_init();
+ cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git")));
+ git_repository_free(nested_repo);
+
+ git_threads_shutdown();
+ cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git")));
+ git_repository_free(nested_repo);
+}