]> git.notmuchmail.org Git - notmuch/blob - test/T850-git.sh
emacs: Add new option notmuch-search-hide-excluded
[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-0}" != "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 test_subtest_broken_for_installed
237 "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
238 cat <<EOF > EXPECTED
239 prefix = notmuch::
240 repository = CWD/home/.nmbug
241 EOF
242 test_expect_equal_file EXPECTED OUTPUT
243
244 test_begin_subtest "env variable NOTMUCH_GIT_DIR works when invoked as nmbug"
245 test_subtest_broken_for_installed
246 NOTMUCH_GIT_DIR=`pwd`/foo "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
247 cat <<EOF > EXPECTED
248 repository = CWD/foo
249 EOF
250 test_expect_equal_file EXPECTED OUTPUT
251
252 test_begin_subtest "env variable NOTMUCH_GIT_DIR works when invoked as 'notmuch git'"
253 NOTMUCH_GIT_DIR=`pwd`/remote.git notmuch git -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
254 cat <<EOF > EXPECTED
255 repository = CWD/remote.git
256 EOF
257 test_expect_equal_file EXPECTED OUTPUT
258
259
260 test_begin_subtest "env variable NOTMUCH_GIT_DIR overrides config when invoked as 'nmbug'"
261 test_subtest_broken_for_installed
262 notmuch config set git.path `pwd`/bar
263 NOTMUCH_GIT_DIR=`pwd`/remote.git  "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
264 notmuch config set git.path
265 cat <<EOF > EXPECTED
266 repository = CWD/remote.git
267 EOF
268 test_expect_equal_file EXPECTED OUTPUT
269
270 test_begin_subtest "env variable NOTMUCH_GIT_DIR overrides config when invoked as 'notmuch git'"
271 notmuch config set git.path `pwd`/bar
272 NOTMUCH_GIT_DIR=`pwd`/remote.git notmuch git -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
273 notmuch config set git.path
274 cat <<EOF > EXPECTED
275 repository = CWD/remote.git
276 EOF
277 test_expect_equal_file EXPECTED OUTPUT
278
279 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX works when invoked as 'nmbug'"
280 test_subtest_broken_for_installed
281 NOTMUCH_GIT_PREFIX=env:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
282 cat <<EOF > EXPECTED
283 prefix = env::
284 EOF
285 test_expect_equal_file EXPECTED OUTPUT
286
287 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX works when invoked as nmbug"
288 test_subtest_broken_for_installed
289 NOTMUCH_GIT_PREFIX=foo:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
290 cat <<EOF > EXPECTED
291 prefix = foo::
292 EOF
293 test_expect_equal_file EXPECTED OUTPUT
294
295 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX overrides config when invoked as 'nmbug'"
296 test_subtest_broken_for_installed
297 notmuch config set git.tag_prefix config::
298 NOTMUCH_GIT_PREFIX=env:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
299 notmuch config set git.path
300 cat <<EOF > EXPECTED
301 prefix = env::
302 EOF
303 test_expect_equal_file EXPECTED OUTPUT
304
305 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX overrides config when invoked as 'notmuch git'"
306 notmuch config set git.tag_prefix config::
307 NOTMUCH_GIT_PREFIX=env:: notmuch git -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
308 notmuch config set git.path
309 cat <<EOF > EXPECTED
310 prefix = env::
311 EOF
312 test_expect_equal_file EXPECTED OUTPUT
313
314
315 test_begin_subtest "init, xdg default location"
316 repo=home/.local/share/notmuch/default/git
317 notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
318 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
319 cat <<EOF > EXPECTED
320 repository = CWD/$repo
321 CWD/$repo
322 EOF
323 test_expect_equal_file EXPECTED OUTPUT
324
325 test_begin_subtest "init, xdg default location, with profile"
326 repo=home/.local/share/notmuch/work/git
327 NOTMUCH_PROFILE=work notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
328 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
329 cat <<EOF > EXPECTED
330 repository = CWD/$repo
331 CWD/$repo
332 EOF
333 test_expect_equal_file EXPECTED OUTPUT
334
335 test_begin_subtest "init, configured location"
336 repo=configured-tags
337 notmuch config set git.path `pwd`/$repo
338 notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
339 notmuch config set git.path
340 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
341 cat <<EOF > EXPECTED
342 repository = CWD/$repo
343 CWD/$repo
344 EOF
345 test_expect_equal_file EXPECTED OUTPUT
346
347 test_begin_subtest "configured tag prefix"
348 notmuch config set git.tag_prefix test::
349 notmuch git -ldebug status |& grep '^prefix' > OUTPUT
350 notmuch config set git.tag_prefix
351 cat <<EOF > EXPECTED
352 prefix = test::
353 EOF
354 test_expect_equal_file EXPECTED OUTPUT
355
356 test_begin_subtest "default version is 1"
357 notmuch git -l debug -C default-version.git init
358 output=$(git -C default-version.git cat-file blob HEAD:FORMAT)
359 test_expect_equal "${output}" 1
360
361 test_begin_subtest "illegal version"
362 test_expect_code 1 "notmuch git -l debug -C default-version.git init --format-version=42"
363
364 hash=("" "8d/c3/") # for use in synthetic repo contents.
365 for ver in {0..1}; do
366     test_begin_subtest "init version=${ver}"
367     notmuch git -C version-${ver}.git  -p "test${ver}::" init --format-version=${ver}
368     output=$(git -C version-${ver}.git ls-tree -r --name-only HEAD)
369     expected=("" "FORMAT")
370     test_expect_equal "${output}" "${expected[${ver}]}"
371
372     test_begin_subtest "initial commit version=${ver}"
373     notmuch tag "+test${ver}::a" "+test${ver}::b" id:20091117190054.GU3165@dottiness.seas.harvard.edu
374     notmuch git -C version-${ver}.git -p "test${ver}::" commit --force
375     git -C version-${ver}.git ls-tree -r --name-only HEAD | grep -v FORMAT > OUTPUT
376 cat <<EOF > EXPECTED
377 tags/${hash[${ver}]}20091117190054.GU3165@dottiness.seas.harvard.edu/a
378 tags/${hash[${ver}]}20091117190054.GU3165@dottiness.seas.harvard.edu/b
379 EOF
380     test_expect_equal_file_nonempty EXPECTED OUTPUT
381
382     test_begin_subtest "second commit repo=${ver}"
383     notmuch tag "+test${ver}::c" "+test${ver}::d" id:20091117190054.GU3165@dottiness.seas.harvard.edu
384     notmuch git -C version-${ver}.git  -p "test${ver}::" commit --force
385     git -C version-${ver}.git ls-tree -r --name-only HEAD | grep -v FORMAT > OUTPUT
386 cat <<EOF > EXPECTED
387 tags/${hash[$ver]}20091117190054.GU3165@dottiness.seas.harvard.edu/a
388 tags/${hash[$ver]}20091117190054.GU3165@dottiness.seas.harvard.edu/b
389 tags/${hash[$ver]}20091117190054.GU3165@dottiness.seas.harvard.edu/c
390 tags/${hash[$ver]}20091117190054.GU3165@dottiness.seas.harvard.edu/d
391 EOF
392     test_expect_equal_file_nonempty EXPECTED OUTPUT
393
394     test_begin_subtest "checkout repo=${ver} "
395     notmuch dump > BEFORE
396     notmuch tag -test::${ver}::a '*'
397     notmuch git -C version-${ver}.git  -p "test${ver}::" checkout --force
398     notmuch dump > AFTER
399     test_expect_equal_file_nonempty BEFORE AFTER
400 done
401
402 test_done