]> git.proxmox.com Git - libgit2.git/blob - tests/merge/trees/whitespace.c
Added tests to merge files and branches with whitespace problems and fixes
[libgit2.git] / tests / merge / trees / whitespace.c
1 #include "clar_libgit2.h"
2 #include "git2/repository.h"
3 #include "git2/merge.h"
4 #include "buffer.h"
5 #include "merge.h"
6 #include "../merge_helpers.h"
7 #include "fileops.h"
8
9 static git_repository *repo;
10
11 #define TEST_REPO_PATH "merge-whitespace"
12
13 #define BRANCH_A_EOL "branch_a_eol"
14 #define BRANCH_B_EOL "branch_b_eol"
15
16 #define BRANCH_A_CHANGE "branch_a_change"
17 #define BRANCH_B_CHANGE "branch_b_change"
18
19 // Fixture setup and teardown
20 void test_merge_trees_whitespace__initialize(void)
21 {
22 repo = cl_git_sandbox_init(TEST_REPO_PATH);
23 }
24
25 void test_merge_trees_whitespace__cleanup(void)
26 {
27 cl_git_sandbox_cleanup();
28 }
29
30 void test_merge_trees_whitespace__conflict(void)
31 {
32 git_index *index;
33 git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
34
35 struct merge_index_entry merge_index_entries[] = {
36 { 0100644, "4026a6c83f39c56881c9ac62e7582db9e3d33a4f", 1, "test.txt" },
37 { 0100644, "c3b1fb31424c98072542cc8e42b48c92e52f494a", 2, "test.txt" },
38 { 0100644, "262f67de0de2e535a59ae1bc3c739601e98c354d", 3, "test.txt" },
39 };
40
41 cl_git_pass(merge_trees_from_branches(&index, repo, BRANCH_A_EOL, BRANCH_B_EOL, &opts));
42
43 cl_assert(merge_test_index(index, merge_index_entries, 3));
44
45 git_index_free(index);
46 }
47
48 void test_merge_trees_whitespace__eol(void)
49 {
50 git_index *index;
51 git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
52
53 struct merge_index_entry merge_index_entries[] = {
54 { 0100644, "ee3c2aac8e03224c323b58ecb1f9eef616745467", 0, "test.txt" },
55 };
56
57 opts.whitespace_flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL;
58
59 cl_git_pass(merge_trees_from_branches(&index, repo, BRANCH_A_EOL, BRANCH_B_EOL, &opts));
60
61 cl_assert(merge_test_index(index, merge_index_entries, 1));
62
63 git_index_free(index);
64 }
65
66 void test_merge_trees_whitespace__change(void)
67 {
68 git_index *index;
69 git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
70
71 struct merge_index_entry merge_index_entries[] = {
72 { 0100644, "a827eab4fd66ab37a6ebcfaa7b7e341abfd55947", 0, "test.txt" },
73 };
74
75 opts.whitespace_flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE;
76
77 cl_git_pass(merge_trees_from_branches(&index, repo, BRANCH_A_CHANGE, BRANCH_B_CHANGE, &opts));
78
79 cl_assert(merge_test_index(index, merge_index_entries, 1));
80
81 git_index_free(index);
82 }