]> git.cworth.org Git - notmuch/blob - test/T850-git.sh
CLI/git: change defaults for repo and 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 "clone"
19 test_expect_success "notmuch git -p '' -C tags.git clone remote.git"
20
21 test_begin_subtest "commit"
22 notmuch git -C tags.git commit
23 git -C tags.git ls-tree -r --name-only HEAD | xargs dirname | sort -u | sed s,tags/,id:, > OUTPUT
24 notmuch search --output=messages '*' | sort > EXPECTED
25 test_expect_equal_file_nonempty EXPECTED OUTPUT
26
27 test_begin_subtest "commit, with quoted tag"
28 notmuch git -C clone2.git clone tags.git
29 git -C clone2.git ls-tree -r --name-only HEAD | grep /inbox > BEFORE
30 notmuch tag '+"quoted tag"' '*'
31 notmuch git -C clone2.git commit
32 notmuch tag '-"quoted tag"' '*'
33 git -C clone2.git ls-tree -r --name-only HEAD | grep /inbox > AFTER
34 test_expect_equal_file_nonempty BEFORE AFTER
35
36 test_begin_subtest "commit (incremental)"
37 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
38 notmuch git -C tags.git commit
39 git -C tags.git ls-tree -r --name-only HEAD |
40     grep 20091117190054 | sort > OUTPUT
41 echo "--------------------------------------------------" >> OUTPUT
42 notmuch tag -test id:20091117190054.GU3165@dottiness.seas.harvard.edu
43 notmuch git -C tags.git commit
44 git -C tags.git ls-tree -r --name-only HEAD |
45     grep 20091117190054 | sort >> OUTPUT
46 cat <<EOF > EXPECTED
47 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
48 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/signed
49 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/test
50 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/unread
51 --------------------------------------------------
52 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
53 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/signed
54 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/unread
55 EOF
56 test_expect_equal_file_nonempty EXPECTED OUTPUT
57
58 test_begin_subtest "commit (change prefix)"
59 notmuch tag +test::one id:20091117190054.GU3165@dottiness.seas.harvard.edu
60 notmuch git -C tags.git -p 'test::' commit
61 git -C tags.git ls-tree -r --name-only HEAD |
62     grep 20091117190054 | sort > OUTPUT
63 echo "--------------------------------------------------" >> OUTPUT
64 notmuch tag -test::one id:20091117190054.GU3165@dottiness.seas.harvard.edu
65 notmuch git -C tags.git commit
66 git -C tags.git ls-tree -r --name-only HEAD |
67     grep 20091117190054 | sort >> OUTPUT
68 cat <<EOF > EXPECTED
69 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/one
70 --------------------------------------------------
71 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
72 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/signed
73 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/unread
74 EOF
75 test_expect_equal_file_nonempty EXPECTED OUTPUT
76
77 test_begin_subtest "checkout"
78 notmuch dump > BEFORE
79 notmuch tag -inbox '*'
80 notmuch git -C tags.git checkout
81 notmuch dump > AFTER
82 test_expect_equal_file_nonempty BEFORE AFTER
83
84 test_begin_subtest "archive"
85 notmuch git -C tags.git archive | tar tf - | \
86     grep 20091117190054.GU3165@dottiness.seas.harvard.edu | sort > OUTPUT
87 cat <<EOF > EXPECTED
88 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/
89 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/inbox
90 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/signed
91 tags/20091117190054.GU3165@dottiness.seas.harvard.edu/unread
92 EOF
93 notmuch git -C tags.git checkout
94 test_expect_equal_file EXPECTED OUTPUT
95
96 test_begin_subtest "status"
97 notmuch tag +test id:20091117190054.GU3165@dottiness.seas.harvard.edu
98 notmuch git -C tags.git status > OUTPUT
99 cat <<EOF > EXPECTED
100 A       20091117190054.GU3165@dottiness.seas.harvard.edu        test
101 EOF
102 notmuch git -C tags.git checkout
103 test_expect_equal_file EXPECTED OUTPUT
104
105 test_begin_subtest "fetch"
106 notmuch tag +test2 id:20091117190054.GU3165@dottiness.seas.harvard.edu
107 notmuch git -C remote.git commit
108 notmuch tag -test2 id:20091117190054.GU3165@dottiness.seas.harvard.edu
109 notmuch git -C tags.git fetch
110 notmuch git -C tags.git status > OUTPUT
111 cat <<EOF > EXPECTED
112  a      20091117190054.GU3165@dottiness.seas.harvard.edu        test2
113 EOF
114 notmuch git -C tags.git checkout
115 test_expect_equal_file EXPECTED OUTPUT
116
117 test_begin_subtest "merge"
118 notmuch git -C tags.git merge
119 notmuch dump id:20091117190054.GU3165@dottiness.seas.harvard.edu | grep -v '^#' > OUTPUT
120 cat <<EOF > EXPECTED
121 +inbox +signed +test2 +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
122 EOF
123 test_expect_equal_file EXPECTED OUTPUT
124
125 test_begin_subtest "push"
126 notmuch tag +test3 id:20091117190054.GU3165@dottiness.seas.harvard.edu
127 notmuch git -C tags.git commit
128 notmuch tag -test3 id:20091117190054.GU3165@dottiness.seas.harvard.edu
129 notmuch git -C tags.git push
130 notmuch git -C remote.git checkout
131 notmuch dump id:20091117190054.GU3165@dottiness.seas.harvard.edu | grep -v '^#' > OUTPUT
132 cat <<EOF > EXPECTED
133 +inbox +signed +test2 +test3 +unread -- id:20091117190054.GU3165@dottiness.seas.harvard.edu
134 EOF
135 test_expect_equal_file EXPECTED OUTPUT
136
137 test_begin_subtest "environment passed through when run as 'notmuch git'"
138 env NOTMUCH_GIT_DIR=foo NOTMUCH_GIT_PREFIX=bar NOTMUCH_PROFILE=default notmuch git -C tags.git -p '' -ldebug status |& \
139     grep '^env ' | notmuch_dir_sanitize > OUTPUT
140 cat <<EOF > EXPECTED
141 env NOTMUCH_GIT_DIR = foo
142 env NOTMUCH_GIT_PREFIX = bar
143 env NOTMUCH_PROFILE = default
144 env NOTMUCH_CONFIG = CWD/notmuch-config
145 EOF
146 test_expect_equal_file EXPECTED OUTPUT
147
148 test_begin_subtest "--nmbug argument sets defaults"
149 notmuch git -ldebug --nmbug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
150 cat <<EOF > EXPECTED
151 prefix = notmuch::
152 repository = CWD/home/.nmbug
153 EOF
154 test_expect_equal_file EXPECTED OUTPUT
155
156 test_begin_subtest "invoke as nmbug sets defaults"
157 "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^\(prefix\|repository\)' | notmuch_dir_sanitize > OUTPUT
158 cat <<EOF > EXPECTED
159 prefix = notmuch::
160 repository = CWD/home/.nmbug
161 EOF
162 test_expect_equal_file EXPECTED OUTPUT
163
164 test_begin_subtest "env variable NOTMUCH_GIT_DIR works when invoked as nmbug"
165 NOTMUCH_GIT_DIR=`pwd`/foo "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
166 cat <<EOF > EXPECTED
167 repository = CWD/foo
168 EOF
169 test_expect_equal_file EXPECTED OUTPUT
170
171 test_begin_subtest "env variable NOTMUCH_GIT_DIR works when invoked as 'notmuch git'"
172 NOTMUCH_GIT_DIR=`pwd`/remote.git notmuch git -ldebug status |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
173 cat <<EOF > EXPECTED
174 repository = CWD/remote.git
175 EOF
176 test_expect_equal_file EXPECTED OUTPUT
177
178 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX works when invoked as nmbug"
179 NOTMUCH_GIT_PREFIX=foo:: "$NOTMUCH_BUILDDIR"/nmbug -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
180 cat <<EOF > EXPECTED
181 prefix = foo::
182 EOF
183 test_expect_equal_file EXPECTED OUTPUT
184
185 test_begin_subtest "env variable NOTMUCH_GIT_PREFIX works when invoked as 'notmuch git'"
186 NOTMUCH_GIT_PREFIX=env:: notmuch git -ldebug status |& grep '^prefix' | notmuch_dir_sanitize > OUTPUT
187 cat <<EOF > EXPECTED
188 prefix = env::
189 EOF
190 test_expect_equal_file EXPECTED OUTPUT
191
192
193 test_begin_subtest "init, xdg default location"
194 repo=home/.local/share/notmuch/default/git
195 notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
196 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
197 cat <<EOF > EXPECTED
198 repository = CWD/$repo
199 CWD/$repo
200 EOF
201 test_expect_equal_file EXPECTED OUTPUT
202
203 test_begin_subtest "init, xdg default location, with profile"
204 repo=home/.local/share/notmuch/work/git
205 NOTMUCH_PROFILE=work notmuch git -ldebug init |& grep '^repository' | notmuch_dir_sanitize > OUTPUT
206 git -C $repo rev-parse --absolute-git-dir | notmuch_dir_sanitize >> OUTPUT
207 cat <<EOF > EXPECTED
208 repository = CWD/$repo
209 CWD/$repo
210 EOF
211 test_expect_equal_file EXPECTED OUTPUT
212
213 test_done