1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#include "clar_libgit2.h"
#include "git2/rebase.h"
#include "merge.h"
#include "posix.h"
#include <fcntl.h>
static git_repository *repo;
// Fixture setup and teardown
void test_rebase_abort__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
}
void test_rebase_abort__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void test_abort(git_merge_head *branch, git_merge_head *onto)
{
git_reference *head_ref, *branch_ref = NULL;
git_signature *signature;
git_status_list *statuslist;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
cl_git_pass(git_rebase_abort(repo, signature));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
/* Make sure the refs are updated appropriately */
cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD"));
if (branch->ref_name == NULL)
cl_assert_equal_oid(git_merge_head_id(branch), git_reference_target(head_ref));
else {
cl_assert_equal_s("refs/heads/beef", git_reference_symbolic_target(head_ref));
cl_git_pass(git_reference_lookup(&branch_ref, repo, git_reference_symbolic_target(head_ref)));
cl_assert_equal_oid(git_merge_head_id(branch), git_reference_target(branch_ref));
}
git_status_list_new(&statuslist, repo, NULL);
cl_assert_equal_i(0, git_status_list_entrycount(statuslist));
git_status_list_free(statuslist);
/* Make sure the reflogs are updated appropriately */
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(git_merge_head_id(onto), git_reflog_entry_id_old(reflog_entry));
cl_assert_equal_oid(git_merge_head_id(branch), git_reflog_entry_id_new(reflog_entry));
cl_assert_equal_s("rebase: aborting", git_reflog_entry_message(reflog_entry));
git_reflog_free(reflog);
git_reference_free(head_ref);
git_reference_free(branch_ref);
git_signature_free(signature);
}
void test_rebase_abort__merge(void)
{
git_reference *branch_ref, *onto_ref;
git_signature *signature;
git_merge_head *branch_head, *onto_head;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_merge_head_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_merge_head_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
cl_git_pass(git_rebase(repo, branch_head, NULL, onto_head, signature, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
git_signature_free(signature);
git_merge_head_free(branch_head);
git_merge_head_free(onto_head);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
}
void test_rebase_abort__detached_head(void)
{
git_oid branch_id;
git_reference *onto_ref;
git_signature *signature;
git_merge_head *branch_head, *onto_head;
git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64");
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_merge_head_from_id(&branch_head, repo, &branch_id));
cl_git_pass(git_merge_head_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
cl_git_pass(git_rebase(repo, branch_head, NULL, onto_head, signature, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
git_signature_free(signature);
git_merge_head_free(branch_head);
git_merge_head_free(onto_head);
git_reference_free(onto_ref);
}
void test_rebase_abort__old_style_head_file(void)
{
git_reference *branch_ref, *onto_ref;
git_signature *signature;
git_merge_head *branch_head, *onto_head;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_merge_head_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_merge_head_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_signature_new(&signature, "Rebaser", "rebaser@example.com", 1404157834, -400));
cl_git_pass(git_rebase(repo, branch_head, NULL, onto_head, signature, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
p_rename("rebase-merge/.git/rebase-merge/orig-head",
"rebase-merge/.git/rebase-merge/head");
test_abort(branch_head, onto_head);
git_signature_free(signature);
git_merge_head_free(branch_head);
git_merge_head_free(onto_head);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
}
|