1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
| | #!/usr/bin/env bash
test_description='git-remote-notmuch'
. $(dirname "$0")/test-lib.sh || exit 1
notmuch_sanitize_git() {
sed 's/^committer \(.*\) \(<[^>]*>\) [1-9][0-9]* [-+][0-9]*/committer \1 \2 TIMESTAMP TIMEZONE/'
}
add_email_corpus
mkdir repo
git_tmp=$(mktemp -d gitXXXXXXXX)
run_helper () {
env -u NOTMUCH_CONFIG GIT_DIR=${git_tmp} git-remote-notmuch dummy-alias "?config=${NOTMUCH_CONFIG}"
}
export GIT_COMMITTER_NAME="Notmuch Test Suite"
export GIT_COMMITTER_EMAIL="notmuch@example.com"
export GIT_REMOTE_NM_DEBUG="s"
export GIT_REMOTE_NM_LOG=grn-log.txt
EXPECTED=$NOTMUCH_SRCDIR/test/git-remote.expected-output
MAKE_EXPORT_PY=$NOTMUCH_SRCDIR/test/make-export.py
TAG_FILE="87/b1/4EFC743A.3060609@april.org/tags"
test_begin_subtest 'capabilities'
echo capabilities | run_helper > OUTPUT
cat <<EOF > EXPECTED
import
export
refspec refs/heads/*:refs/notmuch/*
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest 'list'
echo list | run_helper > OUTPUT
cat <<EOF > EXPECTED
? refs/heads/master
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest 'import writes lastmod file'
echo import | run_helper dummy-alias dummy-url > /dev/null
lastmod=$(notmuch count --lastmod '*' | cut -f2-)
test_expect_equal "${lastmod}" "$(cat < ${git_tmp}/notmuch/lastmod)"
# note that this test must not be the first time import is run,
# because it depends on the lastmod file
test_begin_subtest 'import produces expected output'
echo import | run_helper | notmuch_sanitize_git > OUTPUT
test_expect_equal_file $EXPECTED/default.import OUTPUT
test_begin_subtest "clone notmuch://"
test_expect_success "git clone notmuch:// $(mktemp -d cloneXXXXXX)"
test_begin_subtest "clone notmuch://?config=notmuch-config"
test_expect_success "git clone notmuch://?config=notmuch-config $(mktemp -d cloneXXXXXX)"
test_begin_subtest "clone notmuch://?profile=default"
test_expect_success "git clone notmuch://?profile=default $(mktemp -d cloneXXXXXX)"
test_begin_subtest "clone notmuch://?config=notmuch-config&profile=default"
test_expect_success "git clone notmuch://?config=notmuch-config\&profile=default $(mktemp -d cloneXXXXXX)"
test_begin_subtest 'clone notmuch://`pwd`/mail'
test_expect_success "env -u NOTMUCH_CONFIG git clone notmuch://`pwd`/mail $(mktemp -d cloneXXXXXX)"
test_begin_subtest 'clone notmuch://`pwd`/mail/?config=`pwd`/notmuch-config'
test_expect_success "env -u NOTMUCH_CONFIG git clone notmuch://`pwd`/mail?config=`pwd`/notmuch-config $(mktemp -d cloneXXXXXX)"
test_begin_subtest 'clone notmuch://.../mail/?config=.../notmuch-config&profile=default'
test_expect_success "env -u NOTMUCH_CONFIG git clone notmuch://`pwd`/mail/?config=`pwd`/notmuch-config\&profile=default $(mktemp -d clone XXX)"
test_begin_subtest 'clone notmuch://?path=.../mail/&config=.../notmuch-config&profile=default'
test_expect_success "env -u NOTMUCH_CONFIG git clone notmuch://?path=`pwd`/mail\&config=notmuch-config\&profile=default $(mktemp -d cloneXXXXXX)"
test_begin_subtest "clone notmuch::"
test_expect_success "git clone notmuch:: $(mktemp -d cloneXXXXXX)"
test_begin_subtest 'clone notmuch::`pwd`/mail'
test_expect_success "env -u NOTMUCH_CONFIG git clone notmuch::`pwd`/mail $(mktemp -d cloneXXXXXX)"
test_begin_subtest 'clone notmuch::`pwd`/mail?config=`pwd`/notmuch-config'
test_expect_success "env -u NOTMUCH_CONFIG git clone notmuch::`pwd`/mail?config=`pwd`/notmuch-config $(mktemp -d cloneXXXXXX)"
test_begin_subtest "clone has every message"
git clone notmuch:: repo
find repo -name tags -type f | sed -e s,repo/../../,id:, -e s,/tags$,, | sort > OUTPUT
notmuch search --output=messages '*' | sort > EXPECTED
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "pull get new tag"
notmuch tag +zznew -- id:4EFC743A.3060609@april.org
git -C repo pull
cat<<EOF >EXPECTED
inbox
unread
zznew
EOF
test_expect_equal_file EXPECTED repo/$TAG_FILE
test_begin_subtest "pull sees deletion"
notmuch tag -unread -- id:4EFC743A.3060609@april.org
git -C repo pull
cat<<EOF >EXPECTED
inbox
zznew
EOF
test_expect_equal_file EXPECTED repo/$TAG_FILE
test_begin_subtest 'export runs'
run_helper <<EOF | notmuch_sanitize_git > OUTPUT
export
blob
mark :1
data 10
tag1
tag2
commit refs/heads/master
mark :2
author Notmuch Test Suite <notmuch@example.com> 1234 +0000
committer Notmuch Test Suite <notmuch@example.com> 1234 +0000
data 8
ignored
M 100644 :1 $TAG_FILE
done
EOF
cat <<EOF > EXPECTED
ok refs/heads/master
EOF
test_expect_equal_file EXPECTED OUTPUT
# this test depends on the previous one
test_begin_subtest 'export modifies database'
notmuch dump id:4EFC743A.3060609@april.org | tail -n 1 > OUTPUT
cat <<EOF > EXPECTED
+tag1 +tag2 -- id:4EFC743A.3060609@april.org
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest 'restore via export'
notmuch dump > BEFORE
python3 $MAKE_EXPORT_PY > export.in
notmuch tag +transient -- id:4EFC743A.3060609@april.org
run_helper < export.in > OUTPUT
notmuch dump id:4EFC743A.3060609@april.org | tail -n 1 > OUTPUT
cat <<EOF > EXPECTED
+tag1 +tag2 -- id:4EFC743A.3060609@april.org
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "push updates database"
git -C repo push origin master
notmuch dump id:4EFC743A.3060609@april.org | tail -n 1 > OUTPUT
cat <<EOF > EXPECTED
+tag1 +tag2 -- id:4EFC743A.3060609@april.org
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "adding tag via repo"
cat<<EOF >repo/$TAG_FILE
tag1
tag2
tag3
EOF
git -C repo add $TAG_FILE
git -C repo commit -m 'testing push'
git -C repo push origin master
notmuch dump id:4EFC743A.3060609@april.org | tail -n 1 > OUTPUT
cat <<EOF > EXPECTED
+tag1 +tag2 +tag3 -- id:4EFC743A.3060609@april.org
EOF
test_expect_equal_file EXPECTED OUTPUT
test_done
|