-
Notifications
You must be signed in to change notification settings - Fork 4
/
magit-imerge-tests.el
232 lines (214 loc) · 9 KB
/
magit-imerge-tests.el
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
;;; magit-imerge-tests.el --- tests for Magit-imerge
;; Copyright (C) 2017-2024 all Magit-imerge contributors
;;
;; License: GPLv3
;;; Code:
(require 'cl-lib)
(require 'ert)
(require 'magit)
(require 'magit-imerge)
;; Modified from magit-tests.el.
(defmacro magit-imerge-with-test-repository (&rest body)
(declare (indent 0) (debug t))
(let ((dir (make-symbol "dir")))
`(let ((,dir (file-name-as-directory (make-temp-file "magit-imerge-" t)))
(process-environment process-environment))
(push "GIT_AUTHOR_NAME=A U Thor" process-environment)
(push "[email protected]" process-environment)
(push "GIT_EDITOR=cat" process-environment)
(condition-case err
(cl-flet ((modify (file &optional content)
(write-region
(insert (or content
(make-temp-name "content")))
nil file)))
(cl-letf (((symbol-function #'message) (lambda (&rest _))))
(let ((default-directory ,dir)
(magit-list-refs-sortby nil)
(magit-inhibit-refresh t))
(magit-git "init" ".")
(magit-git "commit" "-m" "root" "--allow-empty")
;; Branch "a" .
(magit-git "checkout" "-b" "a")
(modify "foo")
(magit-git "add" "foo")
(magit-git "commit" "-m" "add foo")
(modify "foo")
(magit-git "add" "foo")
(magit-git "commit" "-m" "update foo")
;; Branch "b", which doesn't have conflicts with "a".
(magit-git "checkout" "-b" "b" "master")
(modify "bar")
(magit-git "add" "bar")
(magit-git "commit" "-m" "add bar")
(modify "bar")
(magit-git "add" "bar")
(magit-git "commit" "-m" "update bar")
;; Branch "c", which does have conflicts with "a".
(magit-git "checkout" "-b" "c" "master")
(modify "foo")
(magit-git "add" "foo")
(magit-git "commit" "-m" "add foo on c")
(modify "foo")
(magit-git "add" "foo")
(magit-git "commit" "-m" "update foo on c")
(modify "foo")
(magit-git "add" "foo")
(magit-git "commit" "-m" "update foo on c, again")
(magit-git "checkout" "master")
,@body)))
(error (message "Keeping test directory:\n %s" ,dir)
(signal (car err) (cdr err))))
(delete-directory ,dir t))))
(defun magit-imerge-tests-wait ()
(while (and magit-this-process
(eq (process-status magit-this-process) 'run))
(sleep-for 0.01)))
(ert-deftest magit-imerge-names ()
(magit-imerge-with-test-repository
(should-not (magit-imerge-names))
(magit-git "checkout" "a")
(magit-git "imerge" "merge" "b")
(should (equal (magit-imerge-names) (list "b")))
(magit-git "checkout" "b")
(magit-git "imerge" "merge" "a")
(should (equal (magit-imerge-names) (list "a" "b")))
(magit-git "imerge" "continue" "--name=b")
(magit-git "imerge" "finish")
(should (equal (magit-imerge-names) (list "a")))
(magit-git "checkout" "a")
(magit-git "imerge" "merge" "--name=foo/ctoa" "c")
(should (equal (magit-imerge-names) (list "a" "foo/ctoa")))))
(ert-deftest magit-imerge-state ()
(magit-imerge-with-test-repository
(should-not (magit-imerge-state "null"))
(magit-git "checkout" "a")
(magit-git "imerge" "merge" "b")
(let ((state (magit-imerge-state "b")))
(should (equal (cdr (assq 'tip1 state)) "a"))
(should (equal (cdr (assq 'tip2 state)) "b"))
(should (equal (cdr (assq 'goal state)) "merge"))
(should (equal (cdr (assq 'branch state)) "a")))
(magit-git "checkout" "a")
(magit-git "imerge" "rebase" "--name=aonc" "--branch=new" "c")
(let ((state (magit-imerge-state "aonc")))
(should (equal (cdr (assq 'tip1 state)) "c"))
(should (equal (cdr (assq 'tip2 state)) "a"))
(should (equal (cdr (assq 'goal state)) "rebase"))
(should (equal (cdr (assq 'branch state)) "new")))))
(ert-deftest magit-imerge-current-name ()
(magit-imerge-with-test-repository
(should-not (magit-imerge-current-name))
(magit-git "checkout" "a")
(magit-git "imerge" "merge" "b")
(should (equal (magit-imerge-current-name) "b"))
(magit-git "checkout" "a")
(magit-git "imerge" "rebase" "--name=aonc" "--branch=new" "c")
(should (equal (magit-imerge-current-name) "aonc"))))
(ert-deftest magit-imerge-merge ()
(magit-imerge-with-test-repository
(magit-git "checkout" "a")
(magit-imerge-merge "b")
(magit-imerge-tests-wait)
(let ((state (magit-imerge-state "b")))
(should state)
(should (equal (cdr (assq 'tip1 state)) "a"))
(should (equal (cdr (assq 'tip2 state)) "b"))
(should (equal (cdr (assq 'goal state)) "merge"))
(should (equal (cdr (assq 'branch state)) "a")))
(magit-git "checkout" "a")
(magit-imerge-merge "c" (list "--name=cmerge"
"--goal=full"
"--branch=new"))
(magit-imerge-tests-wait)
(let ((state (magit-imerge-state "cmerge")))
(should state)
(should (equal (cdr (assq 'goal state)) "full"))
(should (equal (cdr (assq 'branch state)) "new")))))
(ert-deftest magit-imerge-rebase ()
(magit-imerge-with-test-repository
(magit-git "checkout" "a")
(magit-imerge-rebase "b")
(magit-imerge-tests-wait)
(let ((state (magit-imerge-state "a")))
(should state)
(should (equal (cdr (assq 'tip1 state)) "b"))
(should (equal (cdr (assq 'tip2 state)) "a"))
(should (equal (cdr (assq 'goal state)) "rebase"))
(should (equal (cdr (assq 'branch state)) "a")))
(magit-git "checkout" "a")
(magit-imerge-rebase "c" (list "--name=aonc"
"--goal=full"
"--branch=new"))
(magit-imerge-tests-wait)
(let ((state (magit-imerge-state "aonc")))
(should state)
(should (equal (cdr (assq 'goal state)) "full"))
(should (equal (cdr (assq 'branch state)) "new")))))
(ert-deftest magit-imerge-revert:commit ()
(magit-imerge-with-test-repository
(magit-git "checkout" "a")
(magit-imerge-revert "a^")
(magit-imerge-tests-wait)
(let ((state (magit-imerge-state "a")))
(should state)
(should (equal (cdr (assq 'tip1 state)) "a"))
(should (equal (cdr (assq 'goal state)) "revert"))
(should (equal (cdr (assq 'branch state)) "a")))))
(ert-deftest magit-imerge-revert:range ()
(magit-imerge-with-test-repository
(magit-git "checkout" "c")
(magit-imerge-revert "HEAD~3..HEAD~1")
(magit-imerge-tests-wait)
(let ((state (magit-imerge-state "c")))
(should state)
(should (equal (cdr (assq 'tip1 state)) "c"))
(should (equal (cdr (assq 'goal state)) "revert"))
(should (equal (cdr (assq 'branch state)) "c")))))
(ert-deftest magit-imerge-drop:commit ()
(magit-imerge-with-test-repository
(magit-git "checkout" "a")
(magit-imerge-drop "a^")
(magit-imerge-tests-wait)
(let ((state (magit-imerge-state "a")))
(should state)
(should (equal (cdr (assq 'tip1 state)) "a"))
(should (equal (cdr (assq 'base (cdr (assq 'goalopts state))))
(magit-rev-parse "a~2")))
(should (equal (cdr (assq 'goal state)) "drop"))
(should (equal (cdr (assq 'branch state)) "a")))))
(ert-deftest magit-imerge-drop:range ()
(magit-imerge-with-test-repository
(magit-git "checkout" "c")
(magit-imerge-drop "HEAD~3..HEAD~1")
(magit-imerge-tests-wait)
(let ((state (magit-imerge-state "c")))
(should state)
(should (equal (cdr (assq 'tip1 state)) "c"))
(should (equal (cdr (assq 'base (cdr (assq 'goalopts state))))
(magit-rev-parse "c~3")))
(should (equal (cdr (assq 'goal state)) "drop"))
(should (equal (cdr (assq 'branch state)) "c")))))
(ert-deftest magit-imerge-abort ()
(magit-imerge-with-test-repository
(magit-git "checkout" "a")
(magit-imerge-merge "c")
(magit-imerge-tests-wait)
(should (magit-anything-unmerged-p))
(should (equal (magit-get-current-branch) "imerge/c"))
(let ((magit-no-confirm '(abort-merge)))
(magit-imerge-abort))
(magit-imerge-tests-wait)
(should-not (magit-anything-unmerged-p))
(should (equal (magit-get-current-branch) "a"))))
(ert-deftest magit-imerge-finish ()
(magit-imerge-with-test-repository
(magit-git "checkout" "a")
(magit-imerge-merge "b")
(magit-imerge-tests-wait)
(magit-imerge-finish (list "--branch=new" "--goal=rebase"))
(magit-imerge-tests-wait)
(should (equal (magit-get-current-branch) "new"))
(should-not (magit-rev-verify "HEAD^2"))))
(provide 'magit-imerge-tests)
;;; magit-imerge-tests.el ends here