2 test_description='"notmuch git" to save and restore tags'
3 . $(dirname "$0")/test-lib.sh || exit 1
5 if [ $NOTMUCH_HAVE_SFSEXP -ne 1 ]; then
6 printf "Skipping due to missing sfsexp library\n"
10 # be very careful using backup_database / restore_database in this
11 # file, as they fool the cache invalidation checks in notmuch-git.
15 git config --global user.email notmuch@example.org
16 git config --global user.name "Notmuch Test Suite"
18 test_begin_subtest "init"
19 test_expect_success "notmuch git -p '' -C remote.git init"
21 test_begin_subtest "init (git.path)"
22 notmuch config set git.path configured.git
24 notmuch config set git.path
25 output=$(git -C configured.git rev-parse --is-bare-repository)
26 test_expect_equal "$output" "true"
28 test_begin_subtest "clone"
29 test_expect_success "notmuch git -p '' -C tags.git clone remote.git"
31 test_begin_subtest "initial commit needs force"
32 test_expect_code 1 "notmuch git -C tags.git commit"
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
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
46 20091117190054.GU3165@dottiness.seas.harvard.edu
48 test_expect_equal_file_nonempty EXPECTED OUTPUT
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"
53 test_begin_subtest "checkout new prefix works with force"
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
59 +inbox +new-prefix%3a%3afoo +signed +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
61 test_expect_equal_file_nonempty EXPECTED OUTPUT
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
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"
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
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
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
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
108 test_expect_equal_file_nonempty EXPECTED OUTPUT
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
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
127 test_expect_equal_file_nonempty EXPECTED OUTPUT
130 test_begin_subtest "large checkout needs --force"
131 notmuch tag -inbox '*'
132 test_expect_code 1 "notmuch git -C tags.git checkout"
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
143 test_expect_equal_file_nonempty BEFORE AFTER
145 test_begin_subtest "checkout"
146 notmuch dump > BEFORE
147 notmuch tag -inbox '*'
148 notmuch git -C tags.git checkout --force
150 test_expect_equal_file_nonempty BEFORE AFTER
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
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
161 notmuch git -C tags.git checkout
162 test_expect_equal_file EXPECTED OUTPUT
164 test_begin_subtest "status"
165 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
166 notmuch git -C tags.git status > OUTPUT
168 A 20091117190054.GU3165@dottiness.seas.harvard.edu test
170 notmuch git -C tags.git checkout
171 test_expect_equal_file EXPECTED OUTPUT
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
179 A 20091117190054.GU3165@dottiness.seas.harvard.edu test
181 notmuch --config=notmuch-config.new git checkout
182 test_expect_equal_file EXPECTED OUTPUT
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
191 a 20091117190054.GU3165@dottiness.seas.harvard.edu test2
193 notmuch git -C tags.git checkout
194 test_expect_equal_file EXPECTED OUTPUT
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
200 +inbox +signed +test2 +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
202 test_expect_equal_file EXPECTED OUTPUT
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
212 +inbox +signed +test2 +test3 +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
214 test_expect_equal_file EXPECTED OUTPUT
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
220 env NOTMUCH_GIT_DIR = foo
221 env NOTMUCH_GIT_PREFIX = bar
222 env NOTMUCH_PROFILE = default
223 env NOTMUCH_CONFIG = CWD/notmuch-config
225 test_expect_equal_file EXPECTED OUTPUT
227 test_begin_subtest "--nmbug argument sets defaults"
228 notmuch git -ldebug --nmbug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
231 repository = CWD/home/.nmbug
233 test_expect_equal_file EXPECTED OUTPUT
235 test_begin_subtest "invoke as nmbug sets defaults"
236 "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
239 repository = CWD/home/.nmbug
241 test_expect_equal_file EXPECTED OUTPUT
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
248 test_expect_equal_file EXPECTED OUTPUT
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
253 repository = CWD/remote.git
255 test_expect_equal_file EXPECTED OUTPUT
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
263 repository = CWD/remote.git
265 test_expect_equal_file EXPECTED OUTPUT
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
272 repository = CWD/remote.git
274 test_expect_equal_file EXPECTED OUTPUT
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
281 test_expect_equal_file EXPECTED OUTPUT
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
288 test_expect_equal_file EXPECTED OUTPUT
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
297 test_expect_equal_file EXPECTED OUTPUT
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
306 test_expect_equal_file EXPECTED OUTPUT
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
314 repository = CWD/$repo
317 test_expect_equal_file EXPECTED OUTPUT
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
324 repository = CWD/$repo
327 test_expect_equal_file EXPECTED OUTPUT
329 test_begin_subtest "init, configured location"
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
336 repository = CWD/$repo
339 test_expect_equal_file EXPECTED OUTPUT
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
348 test_expect_equal_file EXPECTED OUTPUT
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
355 test_begin_subtest "illegal version"
356 test_expect_code 1 "notmuch git -l debug -C default-version.git init --format-version=42"
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}]}"
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
371 tags/${hash[${ver}]}20091117190054.GU3165@dottiness.seas.harvard.edu/a
372 tags/${hash[${ver}]}20091117190054.GU3165@dottiness.seas.harvard.edu/b
374 test_expect_equal_file_nonempty EXPECTED OUTPUT
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
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
386 test_expect_equal_file_nonempty EXPECTED OUTPUT
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
393 test_expect_equal_file_nonempty BEFORE AFTER