]> git.cworth.org Git - notmuch/blob - test/T850-git.sh
CLI/git: support configuration for repo location / prefix
[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 add_email_corpus
11
12 git config --global user.email notmuch@example.org
13 git config --global user.name  "Notmuch Test Suite"
14
15 test_begin_subtest "init"
16 test_expect_success "notmuch git -p '' -C remote.git init"
17
18 test_begin_subtest "init (git.path)"
19 notmuch config set git.path configured.git
20 notmuch git init
21 notmuch config set git.path
22 output=$(git -C configured.git rev-parse --is-bare-repository)
23 test_expect_equal "$output" "true"
24
25 test_begin_subtest "clone"
26 test_expect_success "notmuch git -p '' -C tags.git clone remote.git"
27
28 test_begin_subtest "commit"
29 notmuch git -C tags.git commit
30 git -C tags.git ls-tree -r --name-only HEAD | xargs dirname | sort -u | sed s,tags/,id:, > OUTPUT
31 notmuch search --output=messages '*' | sort > EXPECTED
32 test_expect_equal_file_nonempty EXPECTED OUTPUT
33
34 test_begin_subtest "commit, with quoted tag"
35 notmuch git -C clone2.git clone tags.git
36 git -C clone2.git ls-tree -r --name-only HEAD | grep /inbox > BEFORE
37 notmuch tag '+"quoted tag"' '*'
38 notmuch git -C clone2.git commit
39 notmuch tag '-"quoted tag"' '*'
40 git -C clone2.git ls-tree -r --name-only HEAD | grep /inbox > AFTER
41 test_expect_equal_file_nonempty BEFORE AFTER
42
43 test_begin_subtest "commit (incremental)"
44 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
45 notmuch git -C tags.git commit
46 git -C tags.git ls-tree -r --name-only HEAD |
47     grep 20091117190054 | sort > OUTPUT
48 echo "--------------------------------------------------" >> OUTPUT
49 notmuch tag -test id:20091117190054.GU3165@dottiness.seas.harvard.edu
50 notmuch git -C tags.git commit
51 git -C tags.git ls-tree -r --name-only HEAD |
52     grep 20091117190054 | sort >> OUTPUT
53 cat <<EOF > EXPECTED
54 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
55 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/signed
56 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/test
57 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/unread
58 --------------------------------------------------
59 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
60 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/signed
61 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/unread
62 EOF
63 test_expect_equal_file_nonempty EXPECTED OUTPUT
64
65 test_begin_subtest "commit (change prefix)"
66 notmuch tag +test::one id:20091117190054.GU3165@dottiness.seas.harvard.edu
67 notmuch git -C tags.git -p 'test::' commit
68 git -C tags.git ls-tree -r --name-only HEAD |
69     grep 20091117190054 | sort > OUTPUT
70 echo "--------------------------------------------------" >> OUTPUT
71 notmuch tag -test::one id:20091117190054.GU3165@dottiness.seas.harvard.edu
72 notmuch git -C tags.git commit
73 git -C tags.git ls-tree -r --name-only HEAD |
74     grep 20091117190054 | sort >> OUTPUT
75 cat <<EOF > EXPECTED
76 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/one
77 --------------------------------------------------
78 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
79 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/signed
80 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/unread
81 EOF
82 test_expect_equal_file_nonempty EXPECTED OUTPUT
83
84 test_begin_subtest "checkout"
85 notmuch dump > BEFORE
86 notmuch tag -inbox '*'
87 notmuch git -C tags.git checkout
88 notmuch dump > AFTER
89 test_expect_equal_file_nonempty BEFORE AFTER
90
91 test_begin_subtest "archive"
92 notmuch git -C tags.git archive | tar tf - | \
93     grep 20091117190054.GU3165@dottiness.seas.harvard.edu | sort > OUTPUT
94 cat <<EOF > EXPECTED
95 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/
96 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
97 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/signed
98 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/unread
99 EOF
100 notmuch git -C tags.git checkout
101 test_expect_equal_file EXPECTED OUTPUT
102
103 test_begin_subtest "status"
104 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
105 notmuch git -C tags.git status > OUTPUT
106 cat <<EOF > EXPECTED
107 A       20091117190054.GU3165@dottiness.seas.harvard.edu        test
108 EOF
109 notmuch git -C tags.git checkout
110 test_expect_equal_file EXPECTED OUTPUT
111
112 test_begin_subtest "status (global config argument)"
113 cp notmuch-config notmuch-config.new
114 notmuch --config=notmuch-config.new config set git.path tags.git
115 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
116 notmuch --config=./notmuch-config.new git status > OUTPUT
117 cat <<EOF > EXPECTED
118 A       20091117190054.GU3165@dottiness.seas.harvard.edu        test
119 EOF
120 notmuch --config=notmuch-config.new git checkout
121 test_expect_equal_file EXPECTED OUTPUT
122
123 test_begin_subtest "fetch"
124 notmuch tag +test2 id:20091117190054.GU3165@dottiness.seas.harvard.edu
125 notmuch git -C remote.git commit
126 notmuch tag -test2 id:20091117190054.GU3165@dottiness.seas.harvard.edu
127 notmuch git -C tags.git fetch
128 notmuch git -C tags.git status > OUTPUT
129 cat <<EOF > EXPECTED
130  a      20091117190054.GU3165@dottiness.seas.harvard.edu        test2
131 EOF
132 notmuch git -C tags.git checkout
133 test_expect_equal_file EXPECTED OUTPUT
134
135 test_begin_subtest "merge"
136 notmuch git -C tags.git merge
137 notmuch dump id:20091117190054.GU3165@dottiness.seas.harvard.edu | grep -v '^#' > OUTPUT
138 cat <<EOF > EXPECTED
139 +inbox +signed +test2 +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
140 EOF
141 test_expect_equal_file EXPECTED OUTPUT
142
143 test_begin_subtest "push"
144 notmuch tag +test3 id:20091117190054.GU3165@dottiness.seas.harvard.edu
145 notmuch git -C tags.git commit
146 notmuch tag -test3 id:20091117190054.GU3165@dottiness.seas.harvard.edu
147 notmuch git -C tags.git push
148 notmuch git -C remote.git checkout
149 notmuch dump id:20091117190054.GU3165@dottiness.seas.harvard.edu | grep -v '^#' > OUTPUT
150 cat <<EOF > EXPECTED
151 +inbox +signed +test2 +test3 +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
152 EOF
153 test_expect_equal_file EXPECTED OUTPUT
154
155 test_begin_subtest "environment passed through when run as 'notmuch git'"
156 env NOTMUCH_GIT_DIR=foo NOTMUCH_GIT_PREFIX=bar NOTMUCH_PROFILE=default notmuch git -C tags.git -p '' -ldebug status |& \
157     grep '^env ' | notmuch_dir_sanitize > OUTPUT
158 cat <<EOF > EXPECTED
159 env NOTMUCH_GIT_DIR = foo
160 env NOTMUCH_GIT_PREFIX = bar
161 env NOTMUCH_PROFILE = default
162 env NOTMUCH_CONFIG = CWD/notmuch-config
163 EOF
164 test_expect_equal_file EXPECTED OUTPUT
165
166 test_begin_subtest "--nmbug argument sets defaults"
167 notmuch git -ldebug --nmbug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
168 cat <<EOF > EXPECTED
169 prefix = notmuch::
170 repository = CWD/home/.nmbug
171 EOF
172 test_expect_equal_file EXPECTED OUTPUT
173
174 test_begin_subtest "invoke as nmbug sets defaults"
175 "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
176 cat <<EOF > EXPECTED
177 prefix = notmuch::
178 repository = CWD/home/.nmbug
179 EOF
180 test_expect_equal_file EXPECTED OUTPUT
181
182 test_begin_subtest "env variable NOTMUCH_GIT_DIR works when invoked as nmbug"
183 NOTMUCH_GIT_DIR=`pwd`/foo "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
184 cat <<EOF > EXPECTED
185 repository = CWD/foo
186 EOF
187 test_expect_equal_file EXPECTED OUTPUT
188
189 test_begin_subtest "env variable NOTMUCH_GIT_DIR works when invoked as 'notmuch git'"
190 NOTMUCH_GIT_DIR=`pwd`/remote.git notmuch git -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
191 cat <<EOF > EXPECTED
192 repository = CWD/remote.git
193 EOF
194 test_expect_equal_file EXPECTED OUTPUT
195
196
197 test_begin_subtest "env variable NOTMUCH_GIT_DIR overrides config when invoked as 'nmbug'"
198 notmuch config set git.path `pwd`/bar
199 NOTMUCH_GIT_DIR=`pwd`/remote.git  "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
200 notmuch config set git.path
201 cat <<EOF > EXPECTED
202 repository = CWD/remote.git
203 EOF
204 test_expect_equal_file EXPECTED OUTPUT
205
206 test_begin_subtest "env variable NOTMUCH_GIT_DIR overrides config when invoked as 'notmuch git'"
207 notmuch config set git.path `pwd`/bar
208 NOTMUCH_GIT_DIR=`pwd`/remote.git notmuch git -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
209 notmuch config set git.path
210 cat <<EOF > EXPECTED
211 repository = CWD/remote.git
212 EOF
213 test_expect_equal_file EXPECTED OUTPUT
214
215 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX works when invoked as 'nmbug'"
216 NOTMUCH_GIT_PREFIX=env:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
217 cat <<EOF > EXPECTED
218 prefix = env::
219 EOF
220 test_expect_equal_file EXPECTED OUTPUT
221
222 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX works when invoked as nmbug"
223 NOTMUCH_GIT_PREFIX=foo:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
224 cat <<EOF > EXPECTED
225 prefix = foo::
226 EOF
227 test_expect_equal_file EXPECTED OUTPUT
228
229 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX overrides config when invoked as 'nmbug'"
230 notmuch config set git.tag_prefix config::
231 NOTMUCH_GIT_PREFIX=env:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
232 notmuch config set git.path
233 cat <<EOF > EXPECTED
234 prefix = env::
235 EOF
236 test_expect_equal_file EXPECTED OUTPUT
237
238 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX overrides config when invoked as 'notmuch git'"
239 notmuch config set git.tag_prefix config::
240 NOTMUCH_GIT_PREFIX=env:: notmuch git -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
241 notmuch config set git.path
242 cat <<EOF > EXPECTED
243 prefix = env::
244 EOF
245 test_expect_equal_file EXPECTED OUTPUT
246
247
248 test_begin_subtest "init, xdg default location"
249 repo=home/.local/share/notmuch/default/git
250 notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
251 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
252 cat <<EOF > EXPECTED
253 repository = CWD/$repo
254 CWD/$repo
255 EOF
256 test_expect_equal_file EXPECTED OUTPUT
257
258 test_begin_subtest "init, xdg default location, with profile"
259 repo=home/.local/share/notmuch/work/git
260 NOTMUCH_PROFILE=work notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
261 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
262 cat <<EOF > EXPECTED
263 repository = CWD/$repo
264 CWD/$repo
265 EOF
266 test_expect_equal_file EXPECTED OUTPUT
267
268 test_begin_subtest "init, configured location"
269 repo=configured-tags
270 notmuch config set git.path `pwd`/$repo
271 notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
272 notmuch config set git.path
273 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
274 cat <<EOF > EXPECTED
275 repository = CWD/$repo
276 CWD/$repo
277 EOF
278 test_expect_equal_file EXPECTED OUTPUT
279
280 test_begin_subtest "configured tag prefix"
281 notmuch config set git.tag_prefix test::
282 notmuch git -ldebug status |& grep '^prefix' > OUTPUT
283 notmuch config set git.tag_prefix
284 cat <<EOF > EXPECTED
285 prefix = test::
286 EOF
287 test_expect_equal_file EXPECTED OUTPUT
288
289 test_done