blob: 2bcc53188509a390695a933706a76a85013984a2 (
plain) (
blame)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
#!/bin/sh
set -u
. tests/lib.sh
TESTDIR="$(mkdtemp)"
cp -R . "$TESTDIR"
cd "$TESTDIR" || exit
TEST_PREFIX="$PWD/tests/prefix/$(uuid)"
make clean >/dev/null
make PREFIX="$TEST_PREFIX" install >/dev/null
PATH="$PWD/tests:$TEST_PREFIX/bin:$PATH"
if ! git config --global user.email > /dev/null; then
git config --global user.email email@example.com
fi
if ! git config --global user.name > /dev/null; then
git config --global user.name Example
fi
new_repo() {
REPO="$PWD/tests/remotes/$(uuid)"
mkdir -p "$REPO"
cd "$REPO" || exit 1
git init 1>/dev/null 2>/dev/null || {
git config --global init.defaultBranch
}
git remote add origin "$1"
echo '' > f.txt
git add f.txt
git commit -qam f.txt
}
test_supported_remotes() {
testing 'supported remotes'
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo git://euandreh.xyz/remembering
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_empty_stdout
assert_fgrep_stderr 'Opening https://euandreh.xyz'
assert_fgrep_stderr 'xdg-open: https://euandreh.xyz'
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://git.sr.ht/~sircmpwn/ctools
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_fgrep_stdout 'https://git.sr.ht'
assert_empty_stderr
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://git.kernel.org/pub/scm/git/git.git
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_empty_stdout
assert_fgrep_stderr 'Opening https://git.kernel.org'
assert_fgrep_stderr 'xdg-open: https://git.kernel.org'
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://git.savannah.gnu.org/guix.git
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_fgrep_stdout 'https://git.savannah.gnu.org'
assert_empty_stderr
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://notabug.org/cwebber/guile-gcrypt
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_empty_stdout
assert_fgrep_stderr 'Opening https://notabug.org'
assert_fgrep_stderr 'xdg-open: https://notabug.org'
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://codeberg.org/dnkl/yambar
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_fgrep_stdout 'https://codeberg.org'
assert_empty_stderr
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://bitbucket.org/uprojects/jsmn
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_empty_stdout
assert_fgrep_stderr 'Opening https://bitbucket.org'
assert_fgrep_stderr 'xdg-open: https://bitbucket.org'
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://pagure.io/aquedoc
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_fgrep_stdout 'https://pagure.io'
assert_empty_stderr
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://gitlab.com/nonguix/nonguix
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_empty_stdout
assert_fgrep_stderr 'Opening https://gitlab.com/nonguix/nonguix'
assert_fgrep_stderr 'xdg-open: https://gitlab.com/nonguix/nonguix'
cd - > /dev/null || exit 1
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://github.com/skeeto/elfeed
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_fgrep_stdout 'https://github.com'
assert_empty_stderr
cd - > /dev/null || exit 1
test_ok
}
test_unsupported_remote() {
testing 'unsupported remotes'
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
new_repo https://example.com/a/b
LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 1
assert_empty_stdout
assert_fgrep_stderr 'Unsupported origin: https://example.com'
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
git config git-permalink.template-commit-file \
'before %s middle %s after'
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_grep_stdout 'before .+ middle README.md after'
assert_empty_stderr
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
git config --unset git-permalink.template-commit-file
git config git-permalink.template-file-commit \
'before %s middle %s after'
git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 0
assert_grep_stdout 'before README.md middle .+ after'
assert_empty_stderr
N="$LINENO"
OUT="$(mkstemp)"
ERR="$(mkstemp)"
git config --unset git-permalink.template-file-commit
LANG=POSIX git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_status 1
assert_empty_stdout
assert_fgrep_stderr 'Unsupported origin: https://example.com'
test_ok
}
test_supported_remotes
test_unsupported_remote
|