summaryrefslogtreecommitdiff
path: root/tests-clar/checkout
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2013-11-14 14:05:52 -0800
committerBen Straub <bs@github.com>2013-11-14 14:05:52 -0800
commit1782038144ef3413831801bb9c2f3038a84ac6f4 (patch)
treef074cc30890a20f5418c10fae1815ca516588a27 /tests-clar/checkout
parent7b947bf5cc59eefa83c28eb5f5fd8434207ebb8b (diff)
downloadlibgit2-1782038144ef3413831801bb9c2f3038a84ac6f4.tar.gz
Rename tests-clar to tests
Diffstat (limited to 'tests-clar/checkout')
-rw-r--r--tests-clar/checkout/binaryunicode.c58
-rw-r--r--tests-clar/checkout/checkout_helpers.c130
-rw-r--r--tests-clar/checkout/checkout_helpers.h29
-rw-r--r--tests-clar/checkout/conflict.c1127
-rw-r--r--tests-clar/checkout/crlf.c231
-rw-r--r--tests-clar/checkout/head.c62
-rw-r--r--tests-clar/checkout/index.c620
-rw-r--r--tests-clar/checkout/tree.c742
-rw-r--r--tests-clar/checkout/typechange.c240
9 files changed, 0 insertions, 3239 deletions
diff --git a/tests-clar/checkout/binaryunicode.c b/tests-clar/checkout/binaryunicode.c
deleted file mode 100644
index 14ab9fdfa..000000000
--- a/tests-clar/checkout/binaryunicode.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include "clar_libgit2.h"
-#include "refs.h"
-#include "repo/repo_helpers.h"
-#include "path.h"
-#include "fileops.h"
-
-static git_repository *g_repo;
-
-void test_checkout_binaryunicode__initialize(void)
-{
- g_repo = cl_git_sandbox_init("binaryunicode");
-}
-
-void test_checkout_binaryunicode__cleanup(void)
-{
- cl_git_sandbox_cleanup();
-}
-
-static void execute_test(void)
-{
- git_oid oid, check;
- git_commit *commit;
- git_tree *tree;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/branch1"));
- cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
- cl_git_pass(git_commit_tree(&tree, commit));
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE;
-
- cl_git_pass(git_checkout_tree(g_repo, (git_object *)tree, &opts));
-
- git_tree_free(tree);
- git_commit_free(commit);
-
- /* Verify that the lenna.jpg file was checked out correctly */
- cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1"));
- cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJ_BLOB));
- cl_assert(git_oid_equal(&oid, &check));
-
- /* Verify that the text file was checked out correctly */
- cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a"));
- cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJ_BLOB));
- cl_assert(git_oid_equal(&oid, &check));
-}
-
-void test_checkout_binaryunicode__noautocrlf(void)
-{
- cl_repo_set_bool(g_repo, "core.autocrlf", false);
- execute_test();
-}
-
-void test_checkout_binaryunicode__autocrlf(void)
-{
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
- execute_test();
-}
diff --git a/tests-clar/checkout/checkout_helpers.c b/tests-clar/checkout/checkout_helpers.c
deleted file mode 100644
index 06b4e0682..000000000
--- a/tests-clar/checkout/checkout_helpers.c
+++ /dev/null
@@ -1,130 +0,0 @@
-#include "clar_libgit2.h"
-#include "checkout_helpers.h"
-#include "refs.h"
-#include "fileops.h"
-
-void assert_on_branch(git_repository *repo, const char *branch)
-{
- git_reference *head;
- git_buf bname = GIT_BUF_INIT;
-
- cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
- cl_assert_(git_reference_type(head) == GIT_REF_SYMBOLIC, branch);
-
- cl_git_pass(git_buf_joinpath(&bname, "refs/heads", branch));
- cl_assert_equal_s(bname.ptr, git_reference_symbolic_target(head));
-
- git_reference_free(head);
- git_buf_free(&bname);
-}
-
-void reset_index_to_treeish(git_object *treeish)
-{
- git_object *tree;
- git_index *index;
- git_repository *repo = git_object_owner(treeish);
-
- cl_git_pass(git_object_peel(&tree, treeish, GIT_OBJ_TREE));
-
- cl_git_pass(git_repository_index(&index, repo));
- cl_git_pass(git_index_read_tree(index, (git_tree *)tree));
- cl_git_pass(git_index_write(index));
-
- git_object_free(tree);
- git_index_free(index);
-}
-
-int checkout_count_callback(
- git_checkout_notify_t why,
- const char *path,
- const git_diff_file *baseline,
- const git_diff_file *target,
- const git_diff_file *workdir,
- void *payload)
-{
- checkout_counts *ct = payload;
-
- GIT_UNUSED(baseline); GIT_UNUSED(target); GIT_UNUSED(workdir);
-
- if (why & GIT_CHECKOUT_NOTIFY_CONFLICT) {
- ct->n_conflicts++;
-
- if (ct->debug) {
- if (workdir) {
- if (baseline) {
- if (target)
- fprintf(stderr, "M %s (conflicts with M %s)\n",
- workdir->path, target->path);
- else
- fprintf(stderr, "M %s (conflicts with D %s)\n",
- workdir->path, baseline->path);
- } else {
- if (target)
- fprintf(stderr, "Existing %s (conflicts with A %s)\n",
- workdir->path, target->path);
- else
- fprintf(stderr, "How can an untracked file be a conflict (%s)\n", workdir->path);
- }
- } else {
- if (baseline) {
- if (target)
- fprintf(stderr, "D %s (conflicts with M %s)\n",
- target->path, baseline->path);
- else
- fprintf(stderr, "D %s (conflicts with D %s)\n",
- baseline->path, baseline->path);
- } else {
- if (target)
- fprintf(stderr, "How can an added file with no workdir be a conflict (%s)\n", target->path);
- else
- fprintf(stderr, "How can a nonexistent file be a conflict (%s)\n", path);
- }
- }
- }
- }
-
- if (why & GIT_CHECKOUT_NOTIFY_DIRTY) {
- ct->n_dirty++;
-
- if (ct->debug) {
- if (workdir)
- fprintf(stderr, "M %s\n", workdir->path);
- else
- fprintf(stderr, "D %s\n", baseline->path);
- }
- }
-
- if (why & GIT_CHECKOUT_NOTIFY_UPDATED) {
- ct->n_updates++;
-
- if (ct->debug) {
- if (baseline) {
- if (target)
- fprintf(stderr, "update: M %s\n", path);
- else
- fprintf(stderr, "update: D %s\n", path);
- } else {
- if (target)
- fprintf(stderr, "update: A %s\n", path);
- else
- fprintf(stderr, "update: this makes no sense %s\n", path);
- }
- }
- }
-
- if (why & GIT_CHECKOUT_NOTIFY_UNTRACKED) {
- ct->n_untracked++;
-
- if (ct->debug)
- fprintf(stderr, "? %s\n", path);
- }
-
- if (why & GIT_CHECKOUT_NOTIFY_IGNORED) {
- ct->n_ignored++;
-
- if (ct->debug)
- fprintf(stderr, "I %s\n", path);
- }
-
- return 0;
-}
diff --git a/tests-clar/checkout/checkout_helpers.h b/tests-clar/checkout/checkout_helpers.h
deleted file mode 100644
index 705ee903d..000000000
--- a/tests-clar/checkout/checkout_helpers.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "buffer.h"
-#include "git2/object.h"
-#include "git2/repository.h"
-
-extern void assert_on_branch(git_repository *repo, const char *branch);
-extern void reset_index_to_treeish(git_object *treeish);
-
-#define check_file_contents(PATH,EXP) \
- cl_assert_equal_file(EXP,0,PATH)
-
-#define check_file_contents_nocr(PATH,EXP) \
- cl_assert_equal_file_ignore_cr(EXP,0,PATH)
-
-typedef struct {
- int n_conflicts;
- int n_dirty;
- int n_updates;
- int n_untracked;
- int n_ignored;
- int debug;
-} checkout_counts;
-
-extern int checkout_count_callback(
- git_checkout_notify_t why,
- const char *path,
- const git_diff_file *baseline,
- const git_diff_file *target,
- const git_diff_file *workdir,
- void *payload);
diff --git a/tests-clar/checkout/conflict.c b/tests-clar/checkout/conflict.c
deleted file mode 100644
index 66965a89b..000000000
--- a/tests-clar/checkout/conflict.c
+++ /dev/null
@@ -1,1127 +0,0 @@
-#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;
-
- (void)completed_steps;
- (void)total_steps;
-
- 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/crlf.c b/tests-clar/checkout/crlf.c
deleted file mode 100644
index 9a4cbd313..000000000
--- a/tests-clar/checkout/crlf.c
+++ /dev/null
@@ -1,231 +0,0 @@
-#include "clar_libgit2.h"
-#include "checkout_helpers.h"
-#include "../filter/crlf.h"
-
-#include "git2/checkout.h"
-#include "repository.h"
-#include "posix.h"
-
-static git_repository *g_repo;
-
-void test_checkout_crlf__initialize(void)
-{
- g_repo = cl_git_sandbox_init("crlf");
-}
-
-void test_checkout_crlf__cleanup(void)
-{
- cl_git_sandbox_cleanup();
-}
-
-void test_checkout_crlf__detect_crlf_autocrlf_false(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", false);
-
- git_checkout_head(g_repo, &opts);
-
- check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
- check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
-}
-
-void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
-{
- git_index *index;
- const git_index_entry *entry;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", false);
-
- git_checkout_head(g_repo, &opts);
-
- git_repository_index(&index, g_repo);
-
- cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
- cl_assert(entry->file_size == strlen(ALL_LF_TEXT_RAW));
-
- cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
- cl_assert(entry->file_size == strlen(ALL_CRLF_TEXT_RAW));
-
- git_index_free(index);
-}
-
-void test_checkout_crlf__detect_crlf_autocrlf_true(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- git_checkout_head(g_repo, &opts);
-
- if (GIT_EOL_NATIVE == GIT_EOL_LF)
- check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
- else
- check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
-
- check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
-}
-
-void test_checkout_crlf__more_lf_autocrlf_true(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- git_checkout_head(g_repo, &opts);
-
- if (GIT_EOL_NATIVE == GIT_EOL_LF)
- check_file_contents("./crlf/more-lf", MORE_LF_TEXT_RAW);
- else
- check_file_contents("./crlf/more-lf", MORE_LF_TEXT_AS_CRLF);
-}
-
-void test_checkout_crlf__more_crlf_autocrlf_true(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- git_checkout_head(g_repo, &opts);
-
- if (GIT_EOL_NATIVE == GIT_EOL_LF)
- check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_RAW);
- else
- check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_AS_CRLF);
-}
-
-void test_checkout_crlf__all_crlf_autocrlf_true(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- git_checkout_head(g_repo, &opts);
-
- check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
-}
-
-void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
-{
- git_index *index;
- const git_index_entry *entry;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- git_checkout_head(g_repo, &opts);
-
- git_repository_index(&index, g_repo);
-
- cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
-
- if (GIT_EOL_NATIVE == GIT_EOL_LF)
- cl_assert_equal_sz(strlen(ALL_LF_TEXT_RAW), entry->file_size);
- else
- cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
-
- cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
- cl_assert_equal_sz(strlen(ALL_CRLF_TEXT_RAW), entry->file_size);
-
- git_index_free(index);
-}
-
-void test_checkout_crlf__with_ident(void)
-{
- git_index *index;
- git_blob *blob;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_mkfile("crlf/.gitattributes",
- "*.txt text\n*.bin binary\n"
- "*.crlf text eol=crlf\n"
- "*.lf text eol=lf\n"
- "*.ident text ident\n"
- "*.identcrlf ident text eol=crlf\n"
- "*.identlf ident text eol=lf\n");
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- /* add files with $Id$ */
-
- cl_git_mkfile("crlf/lf.ident", ALL_LF_TEXT_RAW "\n$Id: initial content$\n");
- cl_git_mkfile("crlf/crlf.ident", ALL_CRLF_TEXT_RAW "\r\n$Id$\r\n\r\n");
- cl_git_mkfile("crlf/more1.identlf", "$Id$\n" MORE_LF_TEXT_RAW);
- cl_git_mkfile("crlf/more2.identcrlf", "\r\n$Id: $\r\n" MORE_CRLF_TEXT_RAW);
-
- cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(git_index_add_bypath(index, "lf.ident"));
- cl_git_pass(git_index_add_bypath(index, "crlf.ident"));
- cl_git_pass(git_index_add_bypath(index, "more1.identlf"));
- cl_git_pass(git_index_add_bypath(index, "more2.identcrlf"));
- cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "Some ident files\n");
-
- git_checkout_head(g_repo, &opts);
-
- /* check that blobs have $Id$ */
-
- cl_git_pass(git_blob_lookup(&blob, g_repo,
- & git_index_get_bypath(index, "lf.ident", 0)->oid));
- cl_assert_equal_s(
- ALL_LF_TEXT_RAW "\n$Id$\n", git_blob_rawcontent(blob));
- git_blob_free(blob);
-
- cl_git_pass(git_blob_lookup(&blob, g_repo,
- & git_index_get_bypath(index, "more2.identcrlf", 0)->oid));
- cl_assert_equal_s(
- "\n$Id$\n" MORE_CRLF_TEXT_AS_LF, git_blob_rawcontent(blob));
- git_blob_free(blob);
-
- /* check that filesystem is initially untouched - matching core Git */
-
- cl_assert_equal_file(
- ALL_LF_TEXT_RAW "\n$Id: initial content$\n", 0, "crlf/lf.ident");
-
- /* check that forced checkout rewrites correctly */
-
- p_unlink("crlf/lf.ident");
- p_unlink("crlf/crlf.ident");
- p_unlink("crlf/more1.identlf");
- p_unlink("crlf/more2.identcrlf");
-
- git_checkout_head(g_repo, &opts);
-
- if (GIT_EOL_NATIVE == GIT_EOL_LF) {
- cl_assert_equal_file(
- ALL_LF_TEXT_RAW
- "\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467$\n",
- 0, "crlf/lf.ident");
- cl_assert_equal_file(
- ALL_CRLF_TEXT_AS_LF
- "\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857$\n\n",
- 0, "crlf/crlf.ident");
- } else {
- cl_assert_equal_file(
- ALL_LF_TEXT_AS_CRLF
- "\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467$\r\n",
- 0, "crlf/lf.ident");
- cl_assert_equal_file(
- ALL_CRLF_TEXT_RAW
- "\r\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857$\r\n\r\n",
- 0, "crlf/crlf.ident");
- }
-
- cl_assert_equal_file(
- "$Id: f7830382dac1f1583422be5530fdfbd26289431b$\n"
- MORE_LF_TEXT_AS_LF, 0, "crlf/more1.identlf");
-
- cl_assert_equal_file(
- "\r\n$Id: 74677a68413012ce8d7e7cfc3f12603df3a3eac4$\r\n"
- MORE_CRLF_TEXT_AS_CRLF, 0, "crlf/more2.identcrlf");
-
- git_index_free(index);
-}
diff --git a/tests-clar/checkout/head.c b/tests-clar/checkout/head.c
deleted file mode 100644
index a7a7e9071..000000000
--- a/tests-clar/checkout/head.c
+++ /dev/null
@@ -1,62 +0,0 @@
-#include "clar_libgit2.h"
-#include "refs.h"
-#include "repo/repo_helpers.h"
-#include "path.h"
-#include "fileops.h"
-
-static git_repository *g_repo;
-
-void test_checkout_head__initialize(void)
-{
- g_repo = cl_git_sandbox_init("testrepo");
-}
-
-void test_checkout_head__cleanup(void)
-{
- cl_git_sandbox_cleanup();
-}
-
-void test_checkout_head__unborn_head_returns_GIT_EUNBORNBRANCH(void)
-{
- make_head_unborn(g_repo, NON_EXISTING_HEAD);
-
- cl_assert_equal_i(GIT_EUNBORNBRANCH, git_checkout_head(g_repo, NULL));
-}
-
-void test_checkout_head__with_index_only_tree(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_index *index;
-
- /* let's start by getting things into a known state */
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_checkout_head(g_repo, &opts));
-
- /* now let's stage some new stuff including a new directory */
-
- cl_git_pass(git_repository_index(&index, g_repo));
-
- p_mkdir("testrepo/newdir", 0777);
- cl_git_mkfile("testrepo/newdir/newfile.txt", "new file\n");
-
- cl_git_pass(git_index_add_bypath(index, "newdir/newfile.txt"));
- cl_git_pass(git_index_write(index));
-
- cl_assert(git_path_isfile("testrepo/newdir/newfile.txt"));
- cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) != NULL);
-
- git_index_free(index);
-
- /* okay, so now we have staged this new file; let's see if we can remove */
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
- cl_git_pass(git_checkout_head(g_repo, &opts));
-
- cl_git_pass(git_repository_index(&index, g_repo));
-
- cl_assert(!git_path_isfile("testrepo/newdir/newfile.txt"));
- cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) == NULL);
-
- git_index_free(index);
-}
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
deleted file mode 100644
index 48d6d79f9..000000000
--- a/tests-clar/checkout/index.c
+++ /dev/null
@@ -1,620 +0,0 @@
-#include "clar_libgit2.h"
-#include "checkout_helpers.h"
-
-#include "git2/checkout.h"
-#include "fileops.h"
-#include "repository.h"
-
-static git_repository *g_repo;
-
-void test_checkout_index__initialize(void)
-{
- git_tree *tree;
-
- g_repo = cl_git_sandbox_init("testrepo");
-
- cl_git_pass(git_repository_head_tree(&tree, g_repo));
-
- reset_index_to_treeish((git_object *)tree);
- git_tree_free(tree);
-
- cl_git_rewritefile(
- "./testrepo/.gitattributes",
- "* text eol=lf\n");
-}
-
-void test_checkout_index__cleanup(void)
-{
- cl_git_sandbox_cleanup();
-
- /* try to remove alternative dir */
- if (git_path_isdir("alternative"))
- git_futils_rmdir_r("alternative", NULL, GIT_RMDIR_REMOVE_FILES);
-}
-
-void test_checkout_index__cannot_checkout_a_bare_repository(void)
-{
- test_checkout_index__cleanup();
-
- g_repo = cl_git_sandbox_init("testrepo.git");
-
- cl_git_fail(git_checkout_index(g_repo, NULL, NULL));
-}
-
-void test_checkout_index__can_create_missing_files(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
- cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
- cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/README", "hey there\n");
- check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
- check_file_contents("./testrepo/new.txt", "my new file\n");
-}
-
-void test_checkout_index__can_remove_untracked_files(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- git_futils_mkdir("./testrepo/dir/subdir/subsubdir", NULL, 0755, GIT_MKDIR_PATH);
- cl_git_mkfile("./testrepo/dir/one", "one\n");
- cl_git_mkfile("./testrepo/dir/subdir/two", "two\n");
-
- cl_assert_equal_i(true, git_path_isdir("./testrepo/dir/subdir/subsubdir"));
-
- opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_REMOVE_UNTRACKED;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- cl_assert_equal_i(false, git_path_isdir("./testrepo/dir"));
-}
-
-void test_checkout_index__honor_the_specified_pathspecs(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- char *entries[] = { "*.txt" };
-
- opts.paths.strings = entries;
- opts.paths.count = 1;
-
- cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
- cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
- cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
- check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
- check_file_contents("./testrepo/new.txt", "my new file\n");
-}
-
-void test_checkout_index__honor_the_gitattributes_directives(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- const char *attributes =
- "branch_file.txt text eol=crlf\n"
- "new.txt text eol=lf\n";
-
- cl_git_mkfile("./testrepo/.gitattributes", attributes);
- cl_repo_set_bool(g_repo, "core.autocrlf", false);
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/README", "hey there\n");
- check_file_contents("./testrepo/new.txt", "my new file\n");
- check_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n");
-}
-
-void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
-{
-#ifdef GIT_WIN32
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- const char *expected_readme_text = "hey there\r\n";
-
- cl_git_pass(p_unlink("./testrepo/.gitattributes"));
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/README", expected_readme_text);
-#endif
-}
-
-void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_repo_set_bool(g_repo, "core.symlinks", true);
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
-#ifdef GIT_WIN32
- check_file_contents("./testrepo/link_to_new.txt", "new.txt");
-#else
- {
- char link_data[1024];
- size_t link_size = 1024;
-
- link_size = p_readlink("./testrepo/link_to_new.txt", link_data, link_size);
- link_data[link_size] = '\0';
- cl_assert_equal_i(link_size, strlen("new.txt"));
- cl_assert_equal_s(link_data, "new.txt");
- check_file_contents("./testrepo/link_to_new.txt", "my new file\n");
- }
-#endif
-}
-
-void test_checkout_index__honor_coresymlinks_setting_set_to_false(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_repo_set_bool(g_repo, "core.symlinks", false);
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/link_to_new.txt", "new.txt");
-}
-
-void test_checkout_index__donot_overwrite_modified_file_by_default(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
-
- /* set this up to not return an error code on conflicts, but it
- * still will not have permission to overwrite anything...
- */
- opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/new.txt", "This isn't what's stored!");
-}
-
-void test_checkout_index__can_overwrite_modified_file(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/new.txt", "my new file\n");
-}
-
-void test_checkout_index__options_disable_filters(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_git_mkfile("./testrepo/.gitattributes", "*.txt text eol=crlf\n");
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- opts.disable_filters = false;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/new.txt", "my new file\r\n");
-
- p_unlink("./testrepo/new.txt");
-
- opts.disable_filters = true;
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/new.txt", "my new file\n");
-}
-
-void test_checkout_index__options_dir_modes(void)
-{
- 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));
-
- reset_index_to_treeish((git_object *)commit);
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- opts.dir_mode = 0701;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- /* umask will influence actual directory creation mode */
- (void)p_umask(um = p_umask(022));
-
- cl_git_pass(p_stat("./testrepo/a", &st));
- cl_assert_equal_i_fmt(st.st_mode, (GIT_FILEMODE_TREE | 0701) & ~um, "%07o");
-
- /* File-mode test, since we're on the 'dir' branch */
- cl_git_pass(p_stat("./testrepo/a/b.txt", &st));
- cl_assert_equal_i_fmt(st.st_mode, GIT_FILEMODE_BLOB_EXECUTABLE, "%07o");
-
- git_commit_free(commit);
-}
-
-void test_checkout_index__options_override_file_modes(void)
-{
- 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;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- cl_git_pass(p_stat("./testrepo/new.txt", &st));
- cl_assert_equal_i_fmt(st.st_mode & GIT_MODE_PERMS_MASK, 0700, "%07o");
-}
-
-void test_checkout_index__options_open_flags(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_git_mkfile("./testrepo/new.txt", "hi\n");
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- opts.file_open_flags = O_CREAT | O_RDWR | O_APPEND;
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./testrepo/new.txt", "hi\nmy new file\n");
-}
-
-struct notify_data {
- const char *file;
- const char *sha;
-};
-
-static int test_checkout_notify_cb(
- git_checkout_notify_t why,
- const char *path,
- const git_diff_file *baseline,
- const git_diff_file *target,
- const git_diff_file *workdir,
- void *payload)
-{
- struct notify_data *expectations = (struct notify_data *)payload;
-
- GIT_UNUSED(workdir);
-
- cl_assert_equal_i(GIT_CHECKOUT_NOTIFY_CONFLICT, why);
- cl_assert_equal_s(expectations->file, path);
- cl_assert_equal_i(0, git_oid_streq(&baseline->oid, expectations->sha));
- cl_assert_equal_i(0, git_oid_streq(&target->oid, expectations->sha));
-
- return 0;
-}
-
-void test_checkout_index__can_notify_of_skipped_files(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- struct notify_data data;
-
- cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
-
- /*
- * $ git ls-tree HEAD
- * 100644 blob a8233120f6ad708f843d861ce2b7228ec4e3dec6 README
- * 100644 blob 3697d64be941a53d4ae8f6a271e4e3fa56b022cc branch_file.txt
- * 100644 blob a71586c1dfe8a71c6cbf6c129f404c5642ff31bd new.txt
- */
- data.file = "new.txt";
- data.sha = "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd";
-
- opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
- opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
- opts.notify_cb = test_checkout_notify_cb;
- opts.notify_payload = &data;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-}
-
-static int dont_notify_cb(
- git_checkout_notify_t why,
- const char *path,
- const git_diff_file *baseline,
- const git_diff_file *target,
- const git_diff_file *workdir,
- void *payload)
-{
- GIT_UNUSED(why);
- GIT_UNUSED(path);
- GIT_UNUSED(baseline);
- GIT_UNUSED(target);
- GIT_UNUSED(workdir);
- GIT_UNUSED(payload);
-
- cl_assert(false);
-
- return 0;
-}
-
-void test_checkout_index__wont_notify_of_expected_line_ending_changes(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_git_pass(p_unlink("./testrepo/.gitattributes"));
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- cl_git_mkfile("./testrepo/new.txt", "my new file\r\n");
-
- opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
- opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
- opts.notify_cb = dont_notify_cb;
- opts.notify_payload = NULL;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-}
-
-static void checkout_progress_counter(
- const char *path, size_t cur, size_t tot, void *payload)
-{
- GIT_UNUSED(path); GIT_UNUSED(cur); GIT_UNUSED(tot);
- (*(int *)payload)++;
-}
-
-void test_checkout_index__calls_progress_callback(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- int calls = 0;
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- opts.progress_cb = checkout_progress_counter;
- opts.progress_payload = &calls;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- cl_assert(calls > 0);
-}
-
-void test_checkout_index__can_overcome_name_clashes(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_index *index;
-
- cl_git_pass(git_repository_index(&index, g_repo));
- git_index_clear(index);
-
- cl_git_mkfile("./testrepo/path0", "content\r\n");
- cl_git_pass(p_mkdir("./testrepo/path1", 0777));
- cl_git_mkfile("./testrepo/path1/file1", "content\r\n");
-
- cl_git_pass(git_index_add_bypath(index, "path0"));
- cl_git_pass(git_index_add_bypath(index, "path1/file1"));
-
- cl_git_pass(p_unlink("./testrepo/path0"));
- cl_git_pass(git_futils_rmdir_r(
- "./testrepo/path1", NULL, GIT_RMDIR_REMOVE_FILES));
-
- cl_git_mkfile("./testrepo/path1", "content\r\n");
- cl_git_pass(p_mkdir("./testrepo/path0", 0777));
- cl_git_mkfile("./testrepo/path0/file0", "content\r\n");
-
- cl_assert(git_path_isfile("./testrepo/path1"));
- cl_assert(git_path_isfile("./testrepo/path0/file0"));
-
- opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
- cl_git_pass(git_checkout_index(g_repo, index, &opts));
-
- cl_assert(git_path_isfile("./testrepo/path1"));
- cl_assert(git_path_isfile("./testrepo/path0/file0"));
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_checkout_index(g_repo, index, &opts));
-
- cl_assert(git_path_isfile("./testrepo/path0"));
- cl_assert(git_path_isfile("./testrepo/path1/file1"));
-
- git_index_free(index);
-}
-
-void test_checkout_index__validates_struct_version(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- const git_error *err;
-
- opts.version = 1024;
- cl_git_fail(git_checkout_index(g_repo, NULL, &opts));
-
- err = giterr_last();
- cl_assert_equal_i(err->klass, GITERR_INVALID);
-
- opts.version = 0;
- giterr_clear();
- cl_git_fail(git_checkout_index(g_repo, NULL, &opts));
-
- err = giterr_last();
- cl_assert_equal_i(err->klass, GITERR_INVALID);
-}
-
-void test_checkout_index__can_update_prefixed_files(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
- cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
- cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
-
- cl_git_mkfile("./testrepo/READ", "content\n");
- cl_git_mkfile("./testrepo/README.after", "content\n");
- cl_git_pass(p_mkdir("./testrepo/branch_file", 0777));
- cl_git_pass(p_mkdir("./testrepo/branch_file/contained_dir", 0777));
- cl_git_mkfile("./testrepo/branch_file/contained_file", "content\n");
- cl_git_pass(p_mkdir("./testrepo/branch_file.txt.after", 0777));
-
- opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_REMOVE_UNTRACKED;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- /* remove untracked will remove the .gitattributes file before the blobs
- * were created, so they will have had crlf filtering applied on Windows
- */
- check_file_contents_nocr("./testrepo/README", "hey there\n");
- check_file_contents_nocr("./testrepo/branch_file.txt", "hi\nbye!\n");
- check_file_contents_nocr("./testrepo/new.txt", "my new file\n");
-
- cl_assert(!git_path_exists("testrepo/READ"));
- cl_assert(!git_path_exists("testrepo/README.after"));
- cl_assert(!git_path_exists("testrepo/branch_file"));
- cl_assert(!git_path_exists("testrepo/branch_file.txt.after"));
-}
-
-void test_checkout_index__can_checkout_a_newly_initialized_repository(void)
-{
- test_checkout_index__cleanup();
-
- g_repo = cl_git_sandbox_init("empty_standard_repo");
- cl_git_remove_placeholders(git_repository_path(g_repo), "dummy-marker.txt");
-
- cl_git_pass(git_checkout_index(g_repo, NULL, NULL));
-}
-
-void test_checkout_index__issue_1397(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- test_checkout_index__cleanup();
-
- g_repo = cl_git_sandbox_init("issue_1397");
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- check_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
-}
-
-void test_checkout_index__target_directory(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- checkout_counts cts;
- memset(&cts, 0, sizeof(cts));
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- opts.target_directory = "alternative";
- cl_assert(!git_path_isdir("alternative"));
-
- opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
- opts.notify_cb = checkout_count_callback;
- opts.notify_payload = &cts;
-
- /* create some files that *would* conflict if we were using the wd */
- cl_git_mkfile("testrepo/README", "I'm in the way!\n");
- cl_git_mkfile("testrepo/new.txt", "my new file\n");
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- cl_assert_equal_i(0, cts.n_untracked);
- cl_assert_equal_i(0, cts.n_ignored);
- cl_assert_equal_i(4, cts.n_updates);
-
- check_file_contents("./alternative/README", "hey there\n");
- check_file_contents("./alternative/branch_file.txt", "hi\nbye!\n");
- check_file_contents("./alternative/new.txt", "my new file\n");
-
- cl_git_pass(git_futils_rmdir_r(
- "alternative", NULL, GIT_RMDIR_REMOVE_FILES));
-}
-
-void test_checkout_index__target_directory_from_bare(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_index *index;
- git_object *head = NULL;
- checkout_counts cts;
- memset(&cts, 0, sizeof(cts));
-
- test_checkout_index__cleanup();
-
- g_repo = cl_git_sandbox_init("testrepo.git");
- cl_assert(git_repository_is_bare(g_repo));
-
- cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(git_revparse_single(&head, g_repo, "HEAD^{tree}"));
- cl_git_pass(git_index_read_tree(index, (const git_tree *)head));
- cl_git_pass(git_index_write(index));
- git_index_free(index);
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
- opts.notify_cb = checkout_count_callback;
- opts.notify_payload = &cts;
-
- /* fail to checkout a bare repo */
- cl_git_fail(git_checkout_index(g_repo, NULL, &opts));
-
- opts.target_directory = "alternative";
- cl_assert(!git_path_isdir("alternative"));
-
- cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
-
- cl_assert_equal_i(0, cts.n_untracked);
- cl_assert_equal_i(0, cts.n_ignored);
- cl_assert_equal_i(3, cts.n_updates);
-
- /* files will have been filtered if needed, so strip CR */
- check_file_contents_nocr("./alternative/README", "hey there\n");
- check_file_contents_nocr("./alternative/branch_file.txt", "hi\nbye!\n");
- check_file_contents_nocr("./alternative/new.txt", "my new file\n");
-
- cl_git_pass(git_futils_rmdir_r(
- "alternative", NULL, GIT_RMDIR_REMOVE_FILES));
-
- git_object_free(head);
-}
-
-void test_checkout_index__can_get_repo_from_index(void)
-{
- git_index *index;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
- cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
- cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_pass(git_repository_index(&index, g_repo));
-
- cl_git_pass(git_checkout_index(NULL, index, &opts));
-
- check_file_contents("./testrepo/README", "hey there\n");
- check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
- check_file_contents("./testrepo/new.txt", "my new file\n");
-
- git_index_free(index);
-}
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
deleted file mode 100644
index 66b01bc7f..000000000
--- a/tests-clar/checkout/tree.c
+++ /dev/null
@@ -1,742 +0,0 @@
-#include "clar_libgit2.h"
-#include "checkout_helpers.h"
-
-#include "git2/checkout.h"
-#include "repository.h"
-#include "buffer.h"
-#include "fileops.h"
-
-static git_repository *g_repo;
-static git_checkout_opts g_opts;
-static git_object *g_object;
-
-void test_checkout_tree__initialize(void)
-{
- g_repo = cl_git_sandbox_init("testrepo");
-
- GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION);
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-}
-
-void test_checkout_tree__cleanup(void)
-{
- git_object_free(g_object);
- g_object = NULL;
-
- cl_git_sandbox_cleanup();
-
- if (git_path_isdir("alternative"))
- git_futils_rmdir_r("alternative", NULL, GIT_RMDIR_REMOVE_FILES);
-}
-
-void test_checkout_tree__cannot_checkout_a_non_treeish(void)
-{
- /* blob */
- cl_git_pass(git_revparse_single(&g_object, g_repo, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"));
- cl_git_fail(git_checkout_tree(g_repo, g_object, NULL));
-}
-
-void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void)
-{
- char *entries[] = { "ab/de/" };
-
- g_opts.paths.strings = entries;
- g_opts.paths.count = 1;
-
- cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
-
- cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
- cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt"));
-}
-
-void test_checkout_tree__can_checkout_and_remove_directory(void)
-{
- cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
-
- /* Checkout brach "subtrees" and update HEAD, so that HEAD matches the
- * current working tree
- */
- cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
-
- cl_assert_equal_i(true, git_path_isdir("./testrepo/ab/"));
- cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
- cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt"));
-
- git_object_free(g_object);
- g_object = NULL;
-
- /* Checkout brach "master" and update HEAD, so that HEAD matches the
- * current working tree
- */
- cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
-
- /* This directory should no longer exist */
- cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
-}
-
-void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void)
-{
- char *entries[] = { "de/" };
-
- g_opts.paths.strings = entries;
- g_opts.paths.count = 1;
-
- cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees:ab"));
-
- cl_assert_equal_i(false, git_path_isdir("./testrepo/de/"));
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- cl_assert_equal_i(true, git_path_isfile("./testrepo/de/2.txt"));
- cl_assert_equal_i(true, git_path_isfile("./testrepo/de/fgh/1.txt"));
-}
-
-static void progress(const char *path, size_t cur, size_t tot, void *payload)
-{
- bool *was_called = (bool*)payload;
- GIT_UNUSED(path); GIT_UNUSED(cur); GIT_UNUSED(tot);
- *was_called = true;
-}
-
-void test_checkout_tree__calls_progress_callback(void)
-{
- bool was_called = 0;
-
- g_opts.progress_cb = progress;
- g_opts.progress_payload = &was_called;
-
- cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- cl_assert_equal_i(was_called, true);
-}
-
-void test_checkout_tree__doesnt_write_unrequested_files_to_worktree(void)
-{
- git_oid master_oid;
- git_oid chomped_oid;
- git_commit* p_master_commit;
- git_commit* p_chomped_commit;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- git_oid_fromstr(&master_oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
- git_oid_fromstr(&chomped_oid, "e90810b8df3e80c413d903f631643c716887138d");
- cl_git_pass(git_commit_lookup(&p_master_commit, g_repo, &master_oid));
- cl_git_pass(git_commit_lookup(&p_chomped_commit, g_repo, &chomped_oid));
-
- /* GIT_CHECKOUT_NONE should not add any file to the working tree from the
- * index as it is supposed to be a dry run.
- */
- opts.checkout_strategy = GIT_CHECKOUT_NONE;
- git_checkout_tree(g_repo, (git_object*)p_chomped_commit, &opts);
- cl_assert_equal_i(false, git_path_isfile("testrepo/readme.txt"));
-
- git_commit_free(p_master_commit);
- git_commit_free(p_chomped_commit);
-}
-
-void test_checkout_tree__can_switch_branches(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_oid oid;
- git_object *obj = NULL;
-
- assert_on_branch(g_repo, "master");
-
- /* do first checkout with FORCE because we don't know if testrepo
- * base data is clean for a checkout or not
- */
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
-
- cl_assert(git_path_isfile("testrepo/README"));
- cl_assert(git_path_isfile("testrepo/branch_file.txt"));
- cl_assert(git_path_isfile("testrepo/new.txt"));
- cl_assert(git_path_isfile("testrepo/a/b.txt"));
-
- cl_assert(!git_path_isdir("testrepo/ab"));
-
- assert_on_branch(g_repo, "dir");
-
- git_object_free(obj);
-
- /* do second checkout safe because we should be clean after first */
- opts.checkout_strategy = GIT_CHECKOUT_SAFE;
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/subtrees"));
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
-
- cl_assert(git_path_isfile("testrepo/README"));
- cl_assert(git_path_isfile("testrepo/branch_file.txt"));
- cl_assert(git_path_isfile("testrepo/new.txt"));
- cl_assert(git_path_isfile("testrepo/ab/4.txt"));
- cl_assert(git_path_isfile("testrepo/ab/c/3.txt"));
- cl_assert(git_path_isfile("testrepo/ab/de/2.txt"));
- cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt"));
-
- cl_assert(!git_path_isdir("testrepo/a"));
-
- assert_on_branch(g_repo, "subtrees");
-
- git_object_free(obj);
-}
-
-void test_checkout_tree__can_remove_untracked(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_REMOVE_UNTRACKED;
-
- cl_git_mkfile("testrepo/untracked_file", "as you wish");
- cl_assert(git_path_isfile("testrepo/untracked_file"));
-
- cl_git_pass(git_checkout_head(g_repo, &opts));
-
- cl_assert(!git_path_isfile("testrepo/untracked_file"));
-}
-
-void test_checkout_tree__can_remove_ignored(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- int ignored = 0;
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_REMOVE_IGNORED;
-
- cl_git_mkfile("testrepo/ignored_file", "as you wish");
-
- cl_git_pass(git_ignore_add_rule(g_repo, "ignored_file\n"));
-
- cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "ignored_file"));
- cl_assert_equal_i(1, ignored);
-
- cl_assert(git_path_isfile("testrepo/ignored_file"));
-
- cl_git_pass(git_checkout_head(g_repo, &opts));
-
- cl_assert(!git_path_isfile("testrepo/ignored_file"));
-}
-
-void test_checkout_tree__can_update_only(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_oid oid;
- git_object *obj = NULL;
-
- /* first let's get things into a known state - by checkout out the HEAD */
-
- assert_on_branch(g_repo, "master");
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_checkout_head(g_repo, &opts));
-
- cl_assert(!git_path_isdir("testrepo/a"));
-
- check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n");
-
- /* now checkout branch but with update only */
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY;
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
-
- assert_on_branch(g_repo, "dir");
-
- /* this normally would have been created (which was tested separately in
- * the test_checkout_tree__can_switch_branches test), but with
- * UPDATE_ONLY it will not have been created.
- */
- cl_assert(!git_path_isdir("testrepo/a"));
-
- /* but this file still should have been updated */
- check_file_contents_nocr("testrepo/branch_file.txt", "hi\n");
-
- git_object_free(obj);
-}
-
-void test_checkout_tree__can_checkout_with_pattern(void)
-{
- char *entries[] = { "[l-z]*.txt" };
-
- /* reset to beginning of history (i.e. just a README file) */
-
- g_opts.checkout_strategy =
- GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
-
- cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
- cl_git_pass(
- git_repository_set_head_detached(g_repo, git_object_id(g_object)));
-
- git_object_free(g_object);
- g_object = NULL;
-
- cl_assert(git_path_exists("testrepo/README"));
- cl_assert(!git_path_exists("testrepo/branch_file.txt"));
- cl_assert(!git_path_exists("testrepo/link_to_new.txt"));
- cl_assert(!git_path_exists("testrepo/new.txt"));
-
- /* now to a narrow patterned checkout */
-
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- g_opts.paths.strings = entries;
- g_opts.paths.count = 1;
-
- cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master"));
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- cl_assert(git_path_exists("testrepo/README"));
- cl_assert(!git_path_exists("testrepo/branch_file.txt"));
- cl_assert(git_path_exists("testrepo/link_to_new.txt"));
- cl_assert(git_path_exists("testrepo/new.txt"));
-}
-
-void test_checkout_tree__can_disable_pattern_match(void)
-{
- char *entries[] = { "b*.txt" };
-
- /* reset to beginning of history (i.e. just a README file) */
-
- g_opts.checkout_strategy =
- GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
-
- cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479"));
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
- cl_git_pass(
- git_repository_set_head_detached(g_repo, git_object_id(g_object)));
-
- git_object_free(g_object);
- g_object = NULL;
-
- cl_assert(!git_path_isfile("testrepo/branch_file.txt"));
-
- /* now to a narrow patterned checkout, but disable pattern */
-
- g_opts.checkout_strategy =
- GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
- g_opts.paths.strings = entries;
- g_opts.paths.count = 1;
-
- cl_git_pass(git_revparse_single(&g_object, g_repo, "refs/heads/master"));
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- cl_assert(!git_path_isfile("testrepo/branch_file.txt"));
-
- /* let's try that again, but allow the pattern match */
-
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- cl_assert(git_path_isfile("testrepo/branch_file.txt"));
-}
-
-void assert_conflict(
- const char *entry_path,
- const char *new_content,
- const char *parent_sha,
- const char *commit_sha)
-{
- git_index *index;
- git_object *hack_tree;
- git_reference *branch, *head;
- git_buf file_path = GIT_BUF_INIT;
-
- cl_git_pass(git_repository_index(&index, g_repo));
-
- /* Create a branch pointing at the parent */
- cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha));
- cl_git_pass(git_branch_create(&branch, g_repo,
- "potential_conflict", (git_commit *)g_object, 0));
-
- /* Make HEAD point to this branch */
- cl_git_pass(git_reference_symbolic_create(
- &head, g_repo, "HEAD", git_reference_name(branch), 1));
- git_reference_free(head);
- git_reference_free(branch);
-
- /* Checkout the parent */
- g_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- /* Hack-ishy workaound to ensure *all* the index entries
- * match the content of the tree
- */
- cl_git_pass(git_object_peel(&hack_tree, g_object, GIT_OBJ_TREE));
- cl_git_pass(git_index_read_tree(index, (git_tree *)hack_tree));
- git_object_free(hack_tree);
- git_object_free(g_object);
- g_object = NULL;
-
- /* Create a conflicting file */
- cl_git_pass(git_buf_joinpath(&file_path, "./testrepo", entry_path));
- cl_git_mkfile(git_buf_cstr(&file_path), new_content);
- git_buf_free(&file_path);
-
- /* Trying to checkout the original commit */
- cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha));
-
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
- cl_assert_equal_i(
- GIT_EMERGECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));
-
- /* Stage the conflicting change */
- cl_git_pass(git_index_add_bypath(index, entry_path));
- cl_git_pass(git_index_write(index));
- git_index_free(index);
-
- cl_assert_equal_i(
- GIT_EMERGECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));
-}
-
-void test_checkout_tree__checking_out_a_conflicting_type_change_returns_EMERGECONFLICT(void)
-{
- /*
- * 099faba adds a symlink named 'link_to_new.txt'
- * a65fedf is the parent of 099faba
- */
-
- assert_conflict("link_to_new.txt", "old.txt", "a65fedf", "099faba");
-}
-
-void test_checkout_tree__checking_out_a_conflicting_type_change_returns_EMERGECONFLICT_2(void)
-{
- /*
- * cf80f8d adds a directory named 'a/'
- * a4a7dce is the parent of cf80f8d
- */
-
- assert_conflict("a", "hello\n", "a4a7dce", "cf80f8d");
-}
-
-void test_checkout_tree__checking_out_a_conflicting_content_change_returns_EMERGECONFLICT(void)
-{
- /*
- * c47800c adds a symlink named 'branch_file.txt'
- * 5b5b025 is the parent of 763d71a
- */
-
- assert_conflict("branch_file.txt", "hello\n", "5b5b025", "c47800c");
-}
-
-void test_checkout_tree__donot_update_deleted_file_by_default(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_oid old_id, new_id;
- git_commit *old_commit = NULL, *new_commit = NULL;
- git_index *index = NULL;
- checkout_counts ct;
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE;
-
- memset(&ct, 0, sizeof(ct));
- opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
- opts.notify_cb = checkout_count_callback;
- opts.notify_payload = &ct;
-
- cl_git_pass(git_repository_index(&index, g_repo));
-
- cl_git_pass(git_oid_fromstr(&old_id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
- cl_git_pass(git_commit_lookup(&old_commit, g_repo, &old_id));
- cl_git_pass(git_reset(g_repo, (git_object *)old_commit, GIT_RESET_HARD));
-
- cl_git_pass(p_unlink("testrepo/branch_file.txt"));
- cl_git_pass(git_index_remove_bypath(index ,"branch_file.txt"));
- cl_git_pass(git_index_write(index));
-
- cl_assert(!git_path_exists("testrepo/branch_file.txt"));
-
- cl_git_pass(git_oid_fromstr(&new_id, "099fabac3a9ea935598528c27f866e34089c2eff"));
- cl_git_pass(git_commit_lookup(&new_commit, g_repo, &new_id));
-
-
- cl_git_fail(git_checkout_tree(g_repo, (git_object *)new_commit, &opts));
-
- cl_assert_equal_i(1, ct.n_conflicts);
- cl_assert_equal_i(1, ct.n_updates);
-
- git_commit_free(old_commit);
- git_commit_free(new_commit);
- git_index_free(index);
-}
-
-void test_checkout_tree__can_checkout_with_last_workdir_item_missing(void)
-{
- git_index *index = NULL;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_oid tree_id, commit_id;
- git_tree *tree = NULL;
- git_commit *commit = NULL;
-
- git_repository_index(&index, g_repo);
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- cl_git_pass(git_reference_name_to_id(&commit_id, g_repo, "refs/heads/master"));
- cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
-
- cl_git_pass(git_checkout_tree(g_repo, (git_object *)commit, &opts));
- cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
-
- cl_git_pass(p_mkdir("./testrepo/this-is-dir", 0777));
- cl_git_mkfile("./testrepo/this-is-dir/contained_file", "content\n");
-
- cl_git_pass(git_index_add_bypath(index, "this-is-dir/contained_file"));
- git_index_write_tree(&tree_id, index);
- cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
-
- cl_git_pass(p_unlink("./testrepo/this-is-dir/contained_file"));
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE;
-
- opts.checkout_strategy = 1;
- git_checkout_tree(g_repo, (git_object *)tree, &opts);
-
- git_tree_free(tree);
- git_commit_free(commit);
- git_index_free(index);
-}
-
-void test_checkout_tree__issue_1397(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- const char *partial_oid = "8a7ef04";
- git_object *tree = NULL;
-
- test_checkout_tree__cleanup(); /* cleanup default checkout */
-
- g_repo = cl_git_sandbox_init("issue_1397");
-
- cl_repo_set_bool(g_repo, "core.autocrlf", true);
-
- cl_git_pass(git_revparse_single(&tree, g_repo, partial_oid));
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- cl_git_pass(git_checkout_tree(g_repo, tree, &opts));
-
- check_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
-
- git_object_free(tree);
-}
-
-void test_checkout_tree__can_write_to_empty_dirs(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_oid oid;
- git_object *obj = NULL;
-
- assert_on_branch(g_repo, "master");
-
- cl_git_pass(p_mkdir("testrepo/a", 0777));
-
- /* do first checkout with FORCE because we don't know if testrepo
- * base data is clean for a checkout or not
- */
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
-
- cl_assert(git_path_isfile("testrepo/a/b.txt"));
-
- git_object_free(obj);
-}
-
-void test_checkout_tree__fails_when_dir_in_use(void)
-{
-#ifdef GIT_WIN32
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_oid oid;
- git_object *obj = NULL;
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
-
- cl_assert(git_path_isfile("testrepo/a/b.txt"));
-
- git_object_free(obj);
-
- cl_git_pass(p_chdir("testrepo/a"));
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/master"));
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_fail(git_checkout_tree(g_repo, obj, &opts));
-
- cl_git_pass(p_chdir("../.."));
-
- cl_assert(git_path_is_empty_dir("testrepo/a"));
-
- git_object_free(obj);
-#endif
-}
-
-void test_checkout_tree__can_continue_when_dir_in_use(void)
-{
-#ifdef GIT_WIN32
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_oid oid;
- git_object *obj = NULL;
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE |
- GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES;
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
-
- cl_assert(git_path_isfile("testrepo/a/b.txt"));
-
- git_object_free(obj);
-
- cl_git_pass(p_chdir("testrepo/a"));
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/master"));
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
-
- cl_git_pass(p_chdir("../.."));
-
- cl_assert(git_path_is_empty_dir("testrepo/a"));
-
- git_object_free(obj);
-#endif
-}
-
-void test_checkout_tree__target_directory_from_bare(void)
-{
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_oid oid;
- checkout_counts cts;
- memset(&cts, 0, sizeof(cts));
-
- test_checkout_tree__cleanup(); /* cleanup default checkout */
-
- g_repo = cl_git_sandbox_init("testrepo.git");
- cl_assert(git_repository_is_bare(g_repo));
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
-
- opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
- opts.notify_cb = checkout_count_callback;
- opts.notify_payload = &cts;
-
- cl_git_pass(git_reference_name_to_id(&oid, g_repo, "HEAD"));
- cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY));
-
- cl_git_fail(git_checkout_tree(g_repo, g_object, &opts));
-
- opts.target_directory = "alternative";
- cl_assert(!git_path_isdir("alternative"));
-
- cl_git_pass(git_checkout_tree(g_repo, g_object, &opts));
-
- cl_assert_equal_i(0, cts.n_untracked);
- cl_assert_equal_i(0, cts.n_ignored);
- cl_assert_equal_i(3, cts.n_updates);
-
- check_file_contents_nocr("./alternative/README", "hey there\n");
- check_file_contents_nocr("./alternative/branch_file.txt", "hi\nbye!\n");
- check_file_contents_nocr("./alternative/new.txt", "my new file\n");
-
- cl_git_pass(git_futils_rmdir_r(
- "alternative", NULL, GIT_RMDIR_REMOVE_FILES));
-}
-
-void test_checkout_tree__extremely_long_file_name(void)
-{
- // A utf-8 string with 83 characters, but 249 bytes.
- const char *longname = "\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97";
- char path[1024];
-
- g_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_revparse_single(&g_object, g_repo, "long-file-name"));
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
-
- sprintf(path, "testrepo/%s.txt", longname);
- cl_assert(git_path_exists(path));
-
- git_object_free(g_object);
- cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
- 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/checkout/typechange.c b/tests-clar/checkout/typechange.c
deleted file mode 100644
index 6cf99ac15..000000000
--- a/tests-clar/checkout/typechange.c
+++ /dev/null
@@ -1,240 +0,0 @@
-#include "clar_libgit2.h"
-#include "git2/checkout.h"
-#include "path.h"
-#include "posix.h"
-#include "fileops.h"
-
-static git_repository *g_repo = NULL;
-
-static const char *g_typechange_oids[] = {
- "79b9f23e85f55ea36a472a902e875bc1121a94cb",
- "9bdb75b73836a99e3dbeea640a81de81031fdc29",
- "0e7ed140b514b8cae23254cb8656fe1674403aff",
- "9d0235c7a7edc0889a18f97a42ee6db9fe688447",
- "9b19edf33a03a0c59cdfc113bfa5c06179bf9b1a",
- "1b63caae4a5ca96f78e8dfefc376c6a39a142475",
- "6eae26c90e8ccc4d16208972119c40635489c6f0",
- NULL
-};
-
-static bool g_typechange_empty[] = {
- true, false, false, false, false, false, true, true
-};
-
-void test_checkout_typechange__initialize(void)
-{
- g_repo = cl_git_sandbox_init("typechanges");
-
- cl_fixture_sandbox("submod2_target");
- p_rename("submod2_target/.gitted", "submod2_target/.git");
-}
-
-void test_checkout_typechange__cleanup(void)
-{
- cl_git_sandbox_cleanup();
- cl_fixture_cleanup("submod2_target");
-}
-
-static void assert_file_exists(const char *path)
-{
- cl_assert_(git_path_isfile(path), path);
-}
-
-static void assert_dir_exists(const char *path)
-{
- cl_assert_(git_path_isdir(path), path);
-}
-
-static void assert_workdir_matches_tree(
- git_repository *repo, const git_oid *id, const char *root, bool recurse)
-{
- git_object *obj;
- git_tree *tree;
- size_t i, max_i;
- git_buf path = GIT_BUF_INIT;
-
- if (!root)
- root = git_repository_workdir(repo);
- cl_assert(root);
-
- cl_git_pass(git_object_lookup(&obj, repo, id, GIT_OBJ_ANY));
- cl_git_pass(git_object_peel((git_object **)&tree, obj, GIT_OBJ_TREE));
- git_object_free(obj);
-
- max_i = git_tree_entrycount(tree);
-
- for (i = 0; i < max_i; ++i) {
- const git_tree_entry *te = git_tree_entry_byindex(tree, i);
- cl_assert(te);
-
- cl_git_pass(git_buf_joinpath(&path, root, git_tree_entry_name(te)));
-
- switch (git_tree_entry_type(te)) {
- case GIT_OBJ_COMMIT:
- assert_dir_exists(path.ptr);
- break;
- case GIT_OBJ_TREE:
- assert_dir_exists(path.ptr);
- if (recurse)
- assert_workdir_matches_tree(
- repo, git_tree_entry_id(te), path.ptr, true);
- break;
- case GIT_OBJ_BLOB:
- switch (git_tree_entry_filemode(te)) {
- case GIT_FILEMODE_BLOB:
- case GIT_FILEMODE_BLOB_EXECUTABLE:
- assert_file_exists(path.ptr);
- /* because of cross-platform, don't confirm exec bit yet */
- break;
- case GIT_FILEMODE_LINK:
- cl_assert_(git_path_exists(path.ptr), path.ptr);
- /* because of cross-platform, don't confirm link yet */
- break;
- default:
- cl_assert(false); /* really?! */
- }
- break;
- default:
- cl_assert(false); /* really?!! */
- }
- }
-
- git_tree_free(tree);
- git_buf_free(&path);
-}
-
-void test_checkout_typechange__checkout_typechanges_safe(void)
-{
- int i;
- git_object *obj;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
-
- for (i = 0; g_typechange_oids[i] != NULL; ++i) {
- cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i]));
-
- opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
- /* There are bugs in some submodule->tree changes that prevent
- * SAFE from passing here, even though the following should work:
- */
- /* !i ? GIT_CHECKOUT_FORCE : GIT_CHECKOUT_SAFE; */
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
-
- cl_git_pass(
- git_repository_set_head_detached(g_repo, git_object_id(obj)));
-
- assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);
-
- git_object_free(obj);
-
- if (!g_typechange_empty[i]) {
- cl_assert(git_path_isdir("typechanges"));
- cl_assert(git_path_exists("typechanges/a"));
- cl_assert(git_path_exists("typechanges/b"));
- cl_assert(git_path_exists("typechanges/c"));
- cl_assert(git_path_exists("typechanges/d"));
- cl_assert(git_path_exists("typechanges/e"));
- } else {
- cl_assert(git_path_isdir("typechanges"));
- cl_assert(!git_path_exists("typechanges/a"));
- cl_assert(!git_path_exists("typechanges/b"));
- cl_assert(!git_path_exists("typechanges/c"));
- cl_assert(!git_path_exists("typechanges/d"));
- cl_assert(!git_path_exists("typechanges/e"));
- }
- }
-}
-
-typedef struct {
- int conflicts;
- int dirty;
- int updates;
- int untracked;
- int ignored;
-} notify_counts;
-
-static int notify_counter(
- git_checkout_notify_t why,
- const char *path,
- const git_diff_file *baseline,
- const git_diff_file *target,
- const git_diff_file *workdir,
- void *payload)
-{
- notify_counts *cts = payload;
-
- GIT_UNUSED(path);
- GIT_UNUSED(baseline);
- GIT_UNUSED(target);
- GIT_UNUSED(workdir);
-
- switch (why) {
- case GIT_CHECKOUT_NOTIFY_CONFLICT: cts->conflicts++; break;
- case GIT_CHECKOUT_NOTIFY_DIRTY: cts->dirty++; break;
- case GIT_CHECKOUT_NOTIFY_UPDATED: cts->updates++; break;
- case GIT_CHECKOUT_NOTIFY_UNTRACKED: cts->untracked++; break;
- case GIT_CHECKOUT_NOTIFY_IGNORED: cts->ignored++; break;
- default: break;
- }
-
- return 0;
-}
-
-static void force_create_file(const char *file)
-{
- int error = git_futils_rmdir_r(file, NULL,
- GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
- cl_assert(!error || error == GIT_ENOTFOUND);
- cl_git_pass(git_futils_mkpath2file(file, 0777));
- cl_git_rewritefile(file, "yowza!!");
-}
-
-void test_checkout_typechange__checkout_with_conflicts(void)
-{
- int i;
- git_object *obj;
- git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- notify_counts cts = {0};
-
- opts.notify_flags =
- GIT_CHECKOUT_NOTIFY_CONFLICT | GIT_CHECKOUT_NOTIFY_UNTRACKED;
- opts.notify_cb = notify_counter;
- opts.notify_payload = &cts;
-
- for (i = 0; g_typechange_oids[i] != NULL; ++i) {
- cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i]));
-
- force_create_file("typechanges/a/blocker");
- force_create_file("typechanges/b");
- force_create_file("typechanges/c/sub/sub/file");
- git_futils_rmdir_r("typechanges/d", NULL, GIT_RMDIR_REMOVE_FILES);
- p_mkdir("typechanges/d", 0777); /* intentionally empty dir */
- force_create_file("typechanges/untracked");
-
- opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- memset(&cts, 0, sizeof(cts));
-
- cl_git_fail(git_checkout_tree(g_repo, obj, &opts));
- cl_assert(cts.conflicts > 0);
- cl_assert(cts.untracked > 0);
-
- opts.checkout_strategy =
- GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
- memset(&cts, 0, sizeof(cts));
-
- cl_assert(git_path_exists("typechanges/untracked"));
-
- cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
- cl_assert_equal_i(0, cts.conflicts);
-
- cl_assert(!git_path_exists("typechanges/untracked"));
-
- cl_git_pass(
- git_repository_set_head_detached(g_repo, git_object_id(obj)));
-
- assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);
-
- git_object_free(obj);
- }
-}