]> git.proxmox.com Git - libgit2.git/blobdiff - tests/revert/workdir.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / revert / workdir.c
index 47abeb8f012946011ca5adac02a08a62aeae0cc5..3f54280caf6f2171fadc4128189024266c7b8daa 100644 (file)
@@ -1,8 +1,7 @@
 #include "clar.h"
 #include "clar_libgit2.h"
 
-#include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/revert.h"
 
 #include "../merge/merge_helpers.h"
@@ -12,7 +11,7 @@
 static git_repository *repo;
 static git_index *repo_index;
 
-// Fixture setup and teardown
+/* Fixture setup and teardown */
 void test_revert_workdir__initialize(void)
 {
        git_config *cfg;
@@ -48,7 +47,7 @@ void test_revert_workdir__automerge(void)
 
        git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac");
        cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -66,7 +65,7 @@ void test_revert_workdir__conflicts(void)
        git_reference *head_ref;
        git_commit *head, *commit;
        git_oid revert_oid;
-       git_buf conflicting_buf = GIT_BUF_INIT;
+       git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
 
        struct merge_index_entry merge_index_entries[] = {
                { 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 1, "file1.txt" },
@@ -80,8 +79,8 @@ void test_revert_workdir__conflicts(void)
        git_oid_fromstr(&revert_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
 
        cl_git_pass(git_repository_head(&head_ref, repo));
-       cl_git_pass(git_reference_peel((git_object **)&head, head_ref, GIT_OBJ_COMMIT));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reference_peel((git_object **)&head, head_ref, GIT_OBJECT_COMMIT));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
        cl_git_pass(git_revert(repo, commit, NULL));
@@ -112,10 +111,22 @@ void test_revert_workdir__conflicts(void)
                "File one\n" \
                ">>>>>>> parent of 72333f4... automergeable changes\n") == 0);
 
+       cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+       cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
+               TEST_REPO_PATH "/.git/MERGE_MSG"));
+       cl_assert(strcmp(mergemsg_buf.ptr,
+               "Revert \"automergeable changes\"\n" \
+               "\n" \
+               "This reverts commit 72333f47d4e83616630ff3b0ffe4c0faebcc3c45.\n"
+               "\n" \
+               "#Conflicts:\n" \
+               "#\tfile1.txt\n") == 0);
+
        git_commit_free(commit);
        git_commit_free(head);
        git_reference_free(head_ref);
-       git_buf_free(&conflicting_buf);
+       git_str_dispose(&mergemsg_buf);
+       git_str_dispose(&conflicting_buf);
 }
 
 /* git reset --hard 39467716290f6df775a91cdb9a4eb39295018145
@@ -132,7 +143,7 @@ void test_revert_workdir__orphan(void)
 
        git_oid_fromstr(&head_oid, "39467716290f6df775a91cdb9a4eb39295018145");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        git_oid_fromstr(&revert_oid, "ebb03002cee5d66c7732dd06241119fe72ab96a5");
        cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -166,8 +177,8 @@ void test_revert_workdir__again(void)
        };
 
        cl_git_pass(git_repository_head(&head_ref, repo));
-       cl_git_pass(git_reference_peel((git_object **)&orig_head, head_ref, GIT_OBJ_COMMIT));
-       cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reference_peel((git_object **)&orig_head, head_ref, GIT_OBJECT_COMMIT));
+       cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL));
 
        cl_git_pass(git_revert(repo, orig_head, NULL));
 
@@ -215,7 +226,7 @@ void test_revert_workdir__again_after_automerge(void)
 
        git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac");
        cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -263,7 +274,7 @@ void test_revert_workdir__again_after_edit(void)
 
        cl_git_pass(git_oid_fromstr(&orig_head_oid, "399fb3aba3d9d13f7d40a9254ce4402067ef3149"));
        cl_git_pass(git_commit_lookup(&orig_head, repo, &orig_head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL));
 
        cl_git_pass(git_oid_fromstr(&revert_oid, "2d440f2b3147d3dc7ad1085813478d6d869d5a4d"));
        cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -291,19 +302,17 @@ void test_revert_workdir__again_after_edit(void)
 /*
  * revert the same commit twice (when the first reverts cleanly):
  *
- * git reset --hard e34ef1a
- * git revert 71eb9c2
+ * git reset --hard 75ec9929465623f17ff3ad68c0438ea56faba815
+ * git revert 97e52d5e81f541080cd6b92829fb85bc4d81d90b
  */
 void test_revert_workdir__again_after_edit_two(void)
 {
-       git_buf diff_buf = GIT_BUF_INIT;
+       git_str diff_buf = GIT_STR_INIT;
        git_config *config;
        git_oid head_commit_oid, revert_commit_oid;
        git_commit *head_commit, *revert_commit;
 
        struct merge_index_entry merge_index_entries[] = {
-               { 0100644, "1ff0c423042b46cb1d617b81efb715defbe8054d", 0, ".gitattributes" },
-               { 0100644, "1bc915c5cb7185a9438de28a7b1a7dfe8c01ee7f", 0, ".gitignore" },
                { 0100644, "a8c86221b400b836010567cc3593db6e96c1a83a", 1, "file.txt" },
                { 0100644, "46ff0854663aeb2182b9838c8da68e33ac23bc1e", 2, "file.txt" },
                { 0100644, "21a96a98ed84d45866e1de6e266fd3a61a4ae9dc", 3, "file.txt" },
@@ -312,33 +321,35 @@ void test_revert_workdir__again_after_edit_two(void)
        cl_git_pass(git_repository_config(&config, repo));
        cl_git_pass(git_config_set_bool(config, "core.autocrlf", 0));
 
-       cl_git_pass(git_oid_fromstr(&head_commit_oid, "e34ef1afe54eb526fd92eec66084125f340f1d65"));
+       cl_git_pass(git_oid_fromstr(&head_commit_oid, "75ec9929465623f17ff3ad68c0438ea56faba815"));
        cl_git_pass(git_commit_lookup(&head_commit, repo, &head_commit_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL));
 
-       cl_git_pass(git_oid_fromstr(&revert_commit_oid, "71eb9c2b53dbbf3c45fb28b27c850db4b7fb8011"));
+       cl_git_pass(git_oid_fromstr(&revert_commit_oid, "97e52d5e81f541080cd6b92829fb85bc4d81d90b"));
        cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_commit_oid));
 
        cl_git_pass(git_revert(repo, revert_commit, NULL));
 
-       cl_assert(merge_test_index(repo_index, merge_index_entries, 5));
+       cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
 
        cl_git_pass(git_futils_readbuffer(&diff_buf, "revert/file.txt"));
-       cl_assert(strcmp(diff_buf.ptr,  "a\n" \
-               "<<<<<<< HEAD\n" \
-               "=======\n" \
-               "a\n" \
-               ">>>>>>> parent of 71eb9c2... revert me\n" \
-               "a\n" \
-               "a\n" \
-               "a\n" \
-               "a\n" \
-               "ab\n") == 0);
+       cl_assert_equal_s(
+                       "a\n" \
+                       "<<<<<<< HEAD\n" \
+                       "=======\n" \
+                       "a\n" \
+                       ">>>>>>> parent of 97e52d5... Revert me\n" \
+                       "a\n" \
+                       "a\n" \
+                       "a\n" \
+                       "a\n" \
+                       "ab",
+               diff_buf.ptr);
 
        git_commit_free(revert_commit);
        git_commit_free(head_commit);
        git_config_free(config);
-       git_buf_free(&diff_buf);
+       git_str_dispose(&diff_buf);
 }
 
 /* git reset --hard 72333f47d4e83616630ff3b0ffe4c0faebcc3c45
@@ -347,7 +358,7 @@ void test_revert_workdir__conflict_use_ours(void)
 {
        git_commit *head, *commit;
        git_oid head_oid, revert_oid;
-       git_revert_opts opts = GIT_REVERT_OPTS_INIT;
+       git_revert_options opts = GIT_REVERT_OPTIONS_INIT;
 
        struct merge_index_entry merge_index_entries[] = {
                { 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 0, "file1.txt" },
@@ -367,7 +378,7 @@ void test_revert_workdir__conflict_use_ours(void)
 
        git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac");
        cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -387,7 +398,7 @@ void test_revert_workdir__rename_1_of_2(void)
 {
        git_commit *head, *commit;
        git_oid head_oid, revert_oid;
-       git_revert_opts opts = GIT_REVERT_OPTS_INIT;
+       git_revert_options opts = GIT_REVERT_OPTIONS_INIT;
 
        struct merge_index_entry merge_index_entries[] = {
                { 0100644, "747726e021bc5f44b86de60e3032fd6f9f1b8383", 0, "file1.txt" },
@@ -398,12 +409,12 @@ void test_revert_workdir__rename_1_of_2(void)
                { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 2, "file6.txt" },
        };
 
-       opts.merge_tree_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
-       opts.merge_tree_opts.rename_threshold = 50;
+       opts.merge_opts.flags |= GIT_MERGE_FIND_RENAMES;
+       opts.merge_opts.rename_threshold = 50;
 
        git_oid_fromstr(&head_oid, "cef56612d71a6af8d8015691e4865f7fece905b5");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        git_oid_fromstr(&revert_oid, "55568c8de5322ff9a95d72747a239cdb64a19965");
        cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -421,7 +432,7 @@ void test_revert_workdir__rename(void)
 {
        git_commit *head, *commit;
        git_oid head_oid, revert_oid;
-       git_revert_opts opts = GIT_REVERT_OPTS_INIT;
+       git_revert_options opts = GIT_REVERT_OPTIONS_INIT;
 
        struct merge_index_entry merge_index_entries[] = {
                { 0100644, "55acf326a69f0aab7a974ec53ffa55a50bcac14e", 1, "file4.txt" },
@@ -432,12 +443,12 @@ void test_revert_workdir__rename(void)
                { "file4.txt", "file5.txt", "" },
        };
 
-       opts.merge_tree_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
-       opts.merge_tree_opts.rename_threshold = 50;
+       opts.merge_opts.flags |= GIT_MERGE_FIND_RENAMES;
+       opts.merge_opts.rename_threshold = 50;
 
        git_oid_fromstr(&head_oid, "55568c8de5322ff9a95d72747a239cdb64a19965");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        git_oid_fromstr(&revert_oid, "0aa8c7e40d342fff78d60b29a4ba8e993ed79c51");
        cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
@@ -465,8 +476,8 @@ void test_revert_workdir__head(void)
 
        /* HEAD is 2d440f2b3147d3dc7ad1085813478d6d869d5a4d */
        cl_git_pass(git_repository_head(&head, repo));
-       cl_git_pass(git_reference_peel((git_object **)&commit, head, GIT_OBJ_COMMIT));
-       cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reference_peel((git_object **)&commit, head, GIT_OBJECT_COMMIT));
+       cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL));
        cl_git_pass(git_revert(repo, commit, NULL));
 
        cl_assert(merge_test_index(repo_index, merge_index_entries, 4));
@@ -480,15 +491,15 @@ void test_revert_workdir__nonmerge_fails_mainline_specified(void)
 {
        git_reference *head;
        git_commit *commit;
-       git_revert_opts opts = GIT_REVERT_OPTS_INIT;
+       git_revert_options opts = GIT_REVERT_OPTIONS_INIT;
 
        cl_git_pass(git_repository_head(&head, repo));
-       cl_git_pass(git_reference_peel((git_object **)&commit, head, GIT_OBJ_COMMIT));
+       cl_git_pass(git_reference_peel((git_object **)&commit, head, GIT_OBJECT_COMMIT));
 
        opts.mainline = 1;
        cl_must_fail(git_revert(repo, commit, &opts));
-       cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
-       cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD"));
+       cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+       cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD"));
 
        git_reference_free(head);
        git_commit_free(commit);
@@ -503,11 +514,11 @@ void test_revert_workdir__merge_fails_without_mainline_specified(void)
 
        git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        cl_must_fail(git_revert(repo, head, NULL));
-       cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
-       cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD"));
+       cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
+       cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD"));
 
        git_commit_free(head);
 }
@@ -518,7 +529,7 @@ void test_revert_workdir__merge_first_parent(void)
 {
        git_commit *head;
        git_oid head_oid;
-       git_revert_opts opts = GIT_REVERT_OPTS_INIT;
+       git_revert_options opts = GIT_REVERT_OPTIONS_INIT;
 
        struct merge_index_entry merge_index_entries[] = {
                { 0100644, "296a6d3be1dff05c5d1f631d2459389fa7b619eb", 0, "file-mainline.txt" },
@@ -530,7 +541,7 @@ void test_revert_workdir__merge_first_parent(void)
 
        git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        cl_git_pass(git_revert(repo, head, &opts));
 
@@ -543,7 +554,7 @@ void test_revert_workdir__merge_second_parent(void)
 {
        git_commit *head;
        git_oid head_oid;
-       git_revert_opts opts = GIT_REVERT_OPTS_INIT;
+       git_revert_options opts = GIT_REVERT_OPTIONS_INIT;
 
        struct merge_index_entry merge_index_entries[] = {
                { 0100644, "33c6fd981c49a2abf2971482089350bfc5cda8ea", 0, "file-branch.txt" },
@@ -555,7 +566,7 @@ void test_revert_workdir__merge_second_parent(void)
 
        git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579");
        cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
-       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
+       cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
 
        cl_git_pass(git_revert(repo, head, &opts));