]> git.cworth.org Git - notmuch/blob - test/T850-git.sh
emacs/show: display count of duplicates in headerline
[notmuch] / test / T850-git.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch git" to save and restore tags'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 if [ $NOTMUCH_HAVE_SFSEXP -ne 1 ]; then
6     printf "Skipping due to missing sfsexp library\n"
7     test_done
8 fi
9
10 # be very careful using backup_database / restore_database in this
11 # file, as they fool the cache invalidation checks in notmuch-git.
12
13 add_email_corpus
14
15 git config --global user.email notmuch@example.org
16 git config --global user.name  "Notmuch Test Suite"
17
18 test_begin_subtest "init"
19 test_expect_success "notmuch git -p '' -C remote.git init"
20
21 test_begin_subtest "init (git.path)"
22 notmuch config set git.path configured.git
23 notmuch git init
24 notmuch config set git.path
25 output=$(git -C configured.git rev-parse --is-bare-repository)
26 test_expect_equal "$output" "true"
27
28 test_begin_subtest "clone"
29 test_expect_success "notmuch git -p '' -C tags.git clone remote.git"
30
31 test_begin_subtest "initial commit needs force"
32 test_expect_code 1 "notmuch git -C tags.git commit"
33
34 test_begin_subtest "committing new prefix requires force"
35 notmuch git -C force-prefix.git init
36 notmuch tag +new-prefix::foo id:20091117190054.GU3165@dottiness.seas.harvard.edu
37 test_expect_code 1 "notmuch git -l debug -p 'new-prefix::' -C force-prefix.git commit"
38 notmuch tag -new-prefix::foo id:20091117190054.GU3165@dottiness.seas.harvard.edu
39
40 test_begin_subtest "committing new prefix works with force"
41 notmuch tag +new-prefix::foo id:20091117190054.GU3165@dottiness.seas.harvard.edu
42 notmuch git -l debug -p 'new-prefix::' -C force-prefix.git commit --force
43 git -C force-prefix.git ls-tree -r --name-only HEAD |  notmuch_git_sanitize | xargs dirname | sort -u > OUTPUT
44 notmuch tag -new-prefix::foo id:20091117190054.GU3165@dottiness.seas.harvard.edu
45 cat <<EOF>EXPECTED
46 20091117190054.GU3165@dottiness.seas.harvard.edu
47 EOF
48 test_expect_equal_file_nonempty EXPECTED OUTPUT
49
50 test_begin_subtest "checkout new prefix requires force"
51 test_expect_code 1 "notmuch git -l debug -p 'new-prefix::' -C force-prefix.git checkout"
52
53 test_begin_subtest "checkout new prefix works with force"
54 notmuch dump > BEFORE
55 notmuch git -l debug -p 'new-prefix::' -C force-prefix.git checkout --force
56 notmuch dump --include=tags id:20091117190054.GU3165@dottiness.seas.harvard.edu | grep -v '^#' > OUTPUT
57 notmuch restore < BEFORE
58 cat <<EOF > EXPECTED
59 +inbox +new-prefix%3a%3afoo +signed +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
60 EOF
61 test_expect_equal_file_nonempty EXPECTED OUTPUT
62
63 test_begin_subtest "commit"
64 notmuch git -C tags.git commit --force
65 git -C tags.git ls-tree -r --name-only HEAD | notmuch_git_sanitize | xargs dirname | sort -u > OUTPUT
66 notmuch search --output=messages '*' | sed s/^id:// | sort > EXPECTED
67 test_expect_equal_file_nonempty EXPECTED OUTPUT
68
69 test_begin_subtest "commit --force succeeds"
70 notmuch git -C force.git init
71 test_expect_success "notmuch git -C force.git commit --force"
72
73 test_begin_subtest "changing git.safe_fraction succeeds"
74 notmuch config set git.safe_fraction 1
75 notmuch git -C force2.git init
76 test_expect_success "notmuch git -C force2.git commit"
77 notmuch config set git.safe_fraction
78
79 test_begin_subtest "commit, with quoted tag"
80 notmuch git -C clone2.git clone tags.git
81 git -C clone2.git ls-tree -r --name-only HEAD | grep /inbox > BEFORE
82 notmuch tag '+"quoted tag"' '*'
83 notmuch git -C clone2.git commit
84 notmuch tag '-"quoted tag"' '*'
85 git -C clone2.git ls-tree -r --name-only HEAD | grep /inbox > AFTER
86 test_expect_equal_file_nonempty BEFORE AFTER
87
88 test_begin_subtest "commit (incremental)"
89 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
90 notmuch git -C tags.git commit
91 git -C tags.git ls-tree -r --name-only HEAD | notmuch_git_sanitize | \
92     grep 20091117190054 | sort > OUTPUT
93 echo "--------------------------------------------------" >> OUTPUT
94 notmuch tag -test id:20091117190054.GU3165@dottiness.seas.harvard.edu
95 notmuch git -C tags.git commit
96 git -C tags.git ls-tree -r --name-only HEAD | notmuch_git_sanitize | \
97     grep 20091117190054 | sort >> OUTPUT
98 cat <<EOF > EXPECTED
99 20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
100 20091117190054.GU3165@dottiness.seas.harvard.edu/signed
101 20091117190054.GU3165@dottiness.seas.harvard.edu/test
102 20091117190054.GU3165@dottiness.seas.harvard.edu/unread
103 --------------------------------------------------
104 20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
105 20091117190054.GU3165@dottiness.seas.harvard.edu/signed
106 20091117190054.GU3165@dottiness.seas.harvard.edu/unread
107 EOF
108 test_expect_equal_file_nonempty EXPECTED OUTPUT
109
110 test_begin_subtest "commit (change prefix)"
111 notmuch tag +test::one id:20091117190054.GU3165@dottiness.seas.harvard.edu
112 notmuch git -C tags.git -p 'test::' commit --force
113 git -C tags.git ls-tree -r --name-only HEAD |
114     grep 20091117190054 | notmuch_git_sanitize | sort > OUTPUT
115 echo "--------------------------------------------------" >> OUTPUT
116 notmuch tag -test::one id:20091117190054.GU3165@dottiness.seas.harvard.edu
117 notmuch git -C tags.git commit --force
118 git -C tags.git ls-tree -r --name-only HEAD | notmuch_git_sanitize | \
119     grep 20091117190054 | sort >> OUTPUT
120 cat <<EOF > EXPECTED
121 20091117190054.GU3165@dottiness.seas.harvard.edu/one
122 --------------------------------------------------
123 20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
124 20091117190054.GU3165@dottiness.seas.harvard.edu/signed
125 20091117190054.GU3165@dottiness.seas.harvard.edu/unread
126 EOF
127 test_expect_equal_file_nonempty EXPECTED OUTPUT
128
129 backup_database
130 test_begin_subtest "large checkout needs --force"
131 notmuch tag -inbox '*'
132 test_expect_code 1 "notmuch git -C tags.git checkout"
133 restore_database
134
135 test_begin_subtest "checkout (git.safe_fraction)"
136 notmuch git -C force3.git clone tags.git
137 notmuch dump > BEFORE
138 notmuch tag -inbox '*'
139 notmuch config set git.safe_fraction 1
140 notmuch git -C force3.git checkout
141 notmuch config set git.safe_fraction
142 notmuch dump > AFTER
143 test_expect_equal_file_nonempty BEFORE AFTER
144
145 test_begin_subtest "checkout"
146 notmuch dump > BEFORE
147 notmuch tag -inbox '*'
148 notmuch git -C tags.git checkout --force
149 notmuch dump > AFTER
150 test_expect_equal_file_nonempty BEFORE AFTER
151
152 test_begin_subtest "archive"
153 notmuch git -C tags.git archive | tar tf - | \
154     grep 20091117190054.GU3165@dottiness.seas.harvard.edu | notmuch_git_sanitize | sort > OUTPUT
155 cat <<EOF > EXPECTED
156 20091117190054.GU3165@dottiness.seas.harvard.edu/
157 20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
158 20091117190054.GU3165@dottiness.seas.harvard.edu/signed
159 20091117190054.GU3165@dottiness.seas.harvard.edu/unread
160 EOF
161 notmuch git -C tags.git checkout
162 test_expect_equal_file EXPECTED OUTPUT
163
164 test_begin_subtest "status"
165 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
166 notmuch git -C tags.git status > OUTPUT
167 cat <<EOF > EXPECTED
168 A       20091117190054.GU3165@dottiness.seas.harvard.edu        test
169 EOF
170 notmuch git -C tags.git checkout
171 test_expect_equal_file EXPECTED OUTPUT
172
173 test_begin_subtest "status (global config argument)"
174 cp notmuch-config notmuch-config.new
175 notmuch --config=notmuch-config.new config set git.path tags.git
176 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
177 notmuch --config=./notmuch-config.new git status > OUTPUT
178 cat <<EOF > EXPECTED
179 A       20091117190054.GU3165@dottiness.seas.harvard.edu        test
180 EOF
181 notmuch --config=notmuch-config.new git checkout
182 test_expect_equal_file EXPECTED OUTPUT
183
184 test_begin_subtest "fetch"
185 notmuch tag +test2 id:20091117190054.GU3165@dottiness.seas.harvard.edu
186 notmuch git -C remote.git commit --force
187 notmuch tag -test2 id:20091117190054.GU3165@dottiness.seas.harvard.edu
188 notmuch git -C tags.git fetch
189 notmuch git -C tags.git status > OUTPUT
190 cat <<EOF > EXPECTED
191  a      20091117190054.GU3165@dottiness.seas.harvard.edu        test2
192 EOF
193 notmuch git -C tags.git checkout
194 test_expect_equal_file EXPECTED OUTPUT
195
196 test_begin_subtest "merge"
197 notmuch git -C tags.git merge
198 notmuch dump id:20091117190054.GU3165@dottiness.seas.harvard.edu | grep -v '^#' > OUTPUT
199 cat <<EOF > EXPECTED
200 +inbox +signed +test2 +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
201 EOF
202 test_expect_equal_file EXPECTED OUTPUT
203
204 test_begin_subtest "push"
205 notmuch tag +test3 id:20091117190054.GU3165@dottiness.seas.harvard.edu
206 notmuch git -C tags.git commit
207 notmuch tag -test3 id:20091117190054.GU3165@dottiness.seas.harvard.edu
208 notmuch git -C tags.git push
209 notmuch git -C remote.git checkout
210 notmuch dump id:20091117190054.GU3165@dottiness.seas.harvard.edu | grep -v '^#' > OUTPUT
211 cat <<EOF > EXPECTED
212 +inbox +signed +test2 +test3 +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
213 EOF
214 test_expect_equal_file EXPECTED OUTPUT
215
216 test_begin_subtest "environment passed through when run as 'notmuch git'"
217 env NOTMUCH_GIT_DIR=foo NOTMUCH_GIT_PREFIX=bar NOTMUCH_PROFILE=default notmuch git -C tags.git -p '' -ldebug status |& \
218     grep '^env ' | notmuch_dir_sanitize > OUTPUT
219 cat <<EOF > EXPECTED
220 env NOTMUCH_GIT_DIR = foo
221 env NOTMUCH_GIT_PREFIX = bar
222 env NOTMUCH_PROFILE = default
223 env NOTMUCH_CONFIG = CWD/notmuch-config
224 EOF
225 test_expect_equal_file EXPECTED OUTPUT
226
227 test_begin_subtest "--nmbug argument sets defaults"
228 notmuch git -ldebug --nmbug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
229 cat <<EOF > EXPECTED
230 prefix = notmuch::
231 repository = CWD/home/.nmbug
232 EOF
233 test_expect_equal_file EXPECTED OUTPUT
234
235 test_begin_subtest "invoke as nmbug sets defaults"
236 "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
237 cat <<EOF > EXPECTED
238 prefix = notmuch::
239 repository = CWD/home/.nmbug
240 EOF
241 test_expect_equal_file EXPECTED OUTPUT
242
243 test_begin_subtest "env variable NOTMUCH_GIT_DIR works when invoked as nmbug"
244 NOTMUCH_GIT_DIR=`pwd`/foo "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
245 cat <<EOF > EXPECTED
246 repository = CWD/foo
247 EOF
248 test_expect_equal_file EXPECTED OUTPUT
249
250 test_begin_subtest "env variable NOTMUCH_GIT_DIR works when invoked as 'notmuch git'"
251 NOTMUCH_GIT_DIR=`pwd`/remote.git notmuch git -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
252 cat <<EOF > EXPECTED
253 repository = CWD/remote.git
254 EOF
255 test_expect_equal_file EXPECTED OUTPUT
256
257
258 test_begin_subtest "env variable NOTMUCH_GIT_DIR overrides config when invoked as 'nmbug'"
259 notmuch config set git.path `pwd`/bar
260 NOTMUCH_GIT_DIR=`pwd`/remote.git  "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
261 notmuch config set git.path
262 cat <<EOF > EXPECTED
263 repository = CWD/remote.git
264 EOF
265 test_expect_equal_file EXPECTED OUTPUT
266
267 test_begin_subtest "env variable NOTMUCH_GIT_DIR overrides config when invoked as 'notmuch git'"
268 notmuch config set git.path `pwd`/bar
269 NOTMUCH_GIT_DIR=`pwd`/remote.git notmuch git -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
270 notmuch config set git.path
271 cat <<EOF > EXPECTED
272 repository = CWD/remote.git
273 EOF
274 test_expect_equal_file EXPECTED OUTPUT
275
276 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX works when invoked as 'nmbug'"
277 NOTMUCH_GIT_PREFIX=env:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
278 cat <<EOF > EXPECTED
279 prefix = env::
280 EOF
281 test_expect_equal_file EXPECTED OUTPUT
282
283 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX works when invoked as nmbug"
284 NOTMUCH_GIT_PREFIX=foo:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
285 cat <<EOF > EXPECTED
286 prefix = foo::
287 EOF
288 test_expect_equal_file EXPECTED OUTPUT
289
290 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX overrides config when invoked as 'nmbug'"
291 notmuch config set git.tag_prefix config::
292 NOTMUCH_GIT_PREFIX=env:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
293 notmuch config set git.path
294 cat <<EOF > EXPECTED
295 prefix = env::
296 EOF
297 test_expect_equal_file EXPECTED OUTPUT
298
299 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX overrides config when invoked as 'notmuch git'"
300 notmuch config set git.tag_prefix config::
301 NOTMUCH_GIT_PREFIX=env:: notmuch git -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
302 notmuch config set git.path
303 cat <<EOF > EXPECTED
304 prefix = env::
305 EOF
306 test_expect_equal_file EXPECTED OUTPUT
307
308
309 test_begin_subtest "init, xdg default location"
310 repo=home/.local/share/notmuch/default/git
311 notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
312 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
313 cat <<EOF > EXPECTED
314 repository = CWD/$repo
315 CWD/$repo
316 EOF
317 test_expect_equal_file EXPECTED OUTPUT
318
319 test_begin_subtest "init, xdg default location, with profile"
320 repo=home/.local/share/notmuch/work/git
321 NOTMUCH_PROFILE=work notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
322 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
323 cat <<EOF > EXPECTED
324 repository = CWD/$repo
325 CWD/$repo
326 EOF
327 test_expect_equal_file EXPECTED OUTPUT
328
329 test_begin_subtest "init, configured location"
330 repo=configured-tags
331 notmuch config set git.path `pwd`/$repo
332 notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
333 notmuch config set git.path
334 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
335 cat <<EOF > EXPECTED
336 repository = CWD/$repo
337 CWD/$repo
338 EOF
339 test_expect_equal_file EXPECTED OUTPUT
340
341 test_begin_subtest "configured tag prefix"
342 notmuch config set git.tag_prefix test::
343 notmuch git -ldebug status |& grep '^prefix' > OUTPUT
344 notmuch config set git.tag_prefix
345 cat <<EOF > EXPECTED
346 prefix = test::
347 EOF
348 test_expect_equal_file EXPECTED OUTPUT
349
350 test_begin_subtest "default version is 1"
351 notmuch git -l debug -C default-version.git init
352 output=$(git -C default-version.git cat-file blob HEAD:FORMAT)
353 test_expect_equal "${output}" 1
354
355 test_begin_subtest "illegal version"
356 test_expect_code 1 "notmuch git -l debug -C default-version.git init --format-version=42"
357
358 hash=("" "8d/c3/") # for use in synthetic repo contents.
359 for ver in {0..1}; do
360     test_begin_subtest "init version=${ver}"
361     notmuch git -C version-${ver}.git  -p "test${ver}::" init --format-version=${ver}
362     output=$(git -C version-${ver}.git ls-tree -r --name-only HEAD)
363     expected=("" "FORMAT")
364     test_expect_equal "${output}" "${expected[${ver}]}"
365
366     test_begin_subtest "initial commit version=${ver}"
367     notmuch tag "+test${ver}::a" "+test${ver}::b" id:20091117190054.GU3165@dottiness.seas.harvard.edu
368     notmuch git -C version-${ver}.git -p "test${ver}::" commit --force
369     git -C version-${ver}.git ls-tree -r --name-only HEAD | grep -v FORMAT > OUTPUT
370 cat <<EOF > EXPECTED
371 tags/${hash[${ver}]}20091117190054.GU3165@dottiness.seas.harvard.edu/a
372 tags/${hash[${ver}]}20091117190054.GU3165@dottiness.seas.harvard.edu/b
373 EOF
374     test_expect_equal_file_nonempty EXPECTED OUTPUT
375
376     test_begin_subtest "second commit repo=${ver}"
377     notmuch tag "+test${ver}::c" "+test${ver}::d" id:20091117190054.GU3165@dottiness.seas.harvard.edu
378     notmuch git -C version-${ver}.git  -p "test${ver}::" commit --force
379     git -C version-${ver}.git ls-tree -r --name-only HEAD | grep -v FORMAT > OUTPUT
380 cat <<EOF > EXPECTED
381 tags/${hash[$ver]}20091117190054.GU3165@dottiness.seas.harvard.edu/a
382 tags/${hash[$ver]}20091117190054.GU3165@dottiness.seas.harvard.edu/b
383 tags/${hash[$ver]}20091117190054.GU3165@dottiness.seas.harvard.edu/c
384 tags/${hash[$ver]}20091117190054.GU3165@dottiness.seas.harvard.edu/d
385 EOF
386     test_expect_equal_file_nonempty EXPECTED OUTPUT
387
388     test_begin_subtest "checkout repo=${ver} "
389     notmuch dump > BEFORE
390     notmuch tag -test::${ver}::a '*'
391     notmuch git -C version-${ver}.git  -p "test${ver}::" checkout --force
392     notmuch dump > AFTER
393     test_expect_equal_file_nonempty BEFORE AFTER
394 done
395
396 test_done