Skip to content

Commit aadbe44

Browse files
peffgitster
authored andcommitted
grep portability fix: don't use "-e" or "-q"
System V versions of grep (such as Solaris /usr/bin/grep) don't understand either of these options. git's usage of "grep -e pattern" fell into one of two categories: 1. equivalent to "grep pattern". -e is only useful here if the pattern begins with a "-", but all of the patterns are hardcoded and do not begin with a dash. 2. stripping comments and blank lines with grep -v -e "^$" -e "^#" We can fortunately do this in the affirmative as grep '^[^#]' Uses of "-q" can be replaced with redirection to /dev/null. In many tests, however, "grep -q" is used as "if this string is in the expected output, we are OK". In this case, it is fine to just remove the "-q" entirely; it simply makes the "verbose" mode of the test slightly more verbose. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e85fe4d commit aadbe44

9 files changed

+42
-43
lines changed

git-rebase--interactive.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ mark_action_done () {
7878
sed -e 1q < "$TODO" >> "$DONE"
7979
sed -e 1d < "$TODO" >> "$TODO".new
8080
mv -f "$TODO".new "$TODO"
81-
count=$(($(grep -ve '^$' -e '^#' < "$DONE" | wc -l)))
82-
total=$(($count+$(grep -ve '^$' -e '^#' < "$TODO" | wc -l)))
81+
count=$(grep -c '^[^#]' < "$DONE")
82+
total=$(($count+$(grep -c '^[^#]' < "$TODO")))
8383
if test "$last_count" != "$count"
8484
then
8585
last_count=$count
@@ -110,7 +110,7 @@ die_abort () {
110110
}
111111

112112
has_action () {
113-
grep -vqe '^$' -e '^#' "$1"
113+
grep '^[^#]' "$1" >/dev/null
114114
}
115115

116116
pick_one () {

git-submodule.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ cmd_init()
230230
shift
231231
done
232232

233-
git ls-files --stage -- "$@" | grep -e '^160000 ' |
233+
git ls-files --stage -- "$@" | grep '^160000 ' |
234234
while read mode sha1 stage path
235235
do
236236
# Skip already registered paths
@@ -284,7 +284,7 @@ cmd_update()
284284
shift
285285
done
286286

287-
git ls-files --stage -- "$@" | grep -e '^160000 ' |
287+
git ls-files --stage -- "$@" | grep '^160000 ' |
288288
while read mode sha1 stage path
289289
do
290290
name=$(module_name "$path") || exit
@@ -367,7 +367,7 @@ cmd_status()
367367
shift
368368
done
369369

370-
git ls-files --stage -- "$@" | grep -e '^160000 ' |
370+
git ls-files --stage -- "$@" | grep '^160000 ' |
371371
while read mode sha1 stage path
372372
do
373373
name=$(module_name "$path") || exit

t/t0030-stripspace.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ test_expect_success \
245245

246246
test_expect_success \
247247
'text plus spaces without newline at end should not show spaces' '
248-
! (printf "$ttt$sss" | git stripspace | grep -q " ") &&
249-
! (printf "$ttt$ttt$sss" | git stripspace | grep -q " ") &&
250-
! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep -q " ") &&
251-
! (printf "$ttt$sss$sss" | git stripspace | grep -q " ") &&
252-
! (printf "$ttt$ttt$sss$sss" | git stripspace | grep -q " ") &&
253-
! (printf "$ttt$sss$sss$sss" | git stripspace | grep -q " ")
248+
! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
249+
! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
250+
! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
251+
! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
252+
! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
253+
! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
254254
'
255255

256256
test_expect_success \
@@ -282,12 +282,12 @@ test_expect_success \
282282

283283
test_expect_success \
284284
'text plus spaces at end should not show spaces' '
285-
! (echo "$ttt$sss" | git stripspace | grep -q " ") &&
286-
! (echo "$ttt$ttt$sss" | git stripspace | grep -q " ") &&
287-
! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep -q " ") &&
288-
! (echo "$ttt$sss$sss" | git stripspace | grep -q " ") &&
289-
! (echo "$ttt$ttt$sss$sss" | git stripspace | grep -q " ") &&
290-
! (echo "$ttt$sss$sss$sss" | git stripspace | grep -q " ")
285+
! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
286+
! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
287+
! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
288+
! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
289+
! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
290+
! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
291291
'
292292

293293
test_expect_success \
@@ -341,11 +341,11 @@ test_expect_success \
341341

342342
test_expect_success \
343343
'spaces without newline at end should not show spaces' '
344-
! (printf "" | git stripspace | grep -q " ") &&
345-
! (printf "$sss" | git stripspace | grep -q " ") &&
346-
! (printf "$sss$sss" | git stripspace | grep -q " ") &&
347-
! (printf "$sss$sss$sss" | git stripspace | grep -q " ") &&
348-
! (printf "$sss$sss$sss$sss" | git stripspace | grep -q " ")
344+
! (printf "" | git stripspace | grep " " >/dev/null) &&
345+
! (printf "$sss" | git stripspace | grep " " >/dev/null) &&
346+
! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) &&
347+
! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) &&
348+
! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null)
349349
'
350350

351351
test_expect_success \

t/t3404-rebase-interactive.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ test_expect_success 'stop on conflicting pick' '
149149
diff -u expect .git/.dotest-merge/patch &&
150150
diff -u expect2 file1 &&
151151
test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) &&
152-
test 0 = $(grep -ve "^#" -e "^$" < .git/.dotest-merge/git-rebase-todo |
153-
wc -l)
152+
test 0 = $(grep -c "^[^#]" < .git/.dotest-merge/git-rebase-todo)
154153
'
155154

156155
test_expect_success 'abort' '

t/t3800-mktag.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ check_verify_failure () {
1515
expect="$2"
1616
test_expect_success "$1" '
1717
( ! git-mktag <tag.sig 2>message ) &&
18-
grep -q "$expect" message
18+
grep "$expect" message
1919
'
2020
}
2121

t/t5400-send-pack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test_expect_success \
120120
cd .. &&
121121
git-clone parent child && cd child && git-push --all &&
122122
cd ../parent &&
123-
git-branch -a >branches && ! grep -q origin/master branches
123+
git-branch -a >branches && ! grep origin/master branches
124124
'
125125

126126
rewound_push_setup() {

t/t7502-status.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test_expect_success 'setup' '
3333

3434
test_expect_success 'status (1)' '
3535
36-
grep -e "use \"git rm --cached <file>\.\.\.\" to unstage" output
36+
grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
3737
3838
'
3939

t/t7600-merge.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ test_expect_success 'override config option -n' '
371371
git merge --summary c2 >diffstat.txt &&
372372
verify_merge file result.1-5 msg.1-5 &&
373373
verify_parents $c1 $c2 &&
374-
if ! grep -e "^ file | *2 +-$" diffstat.txt
374+
if ! grep "^ file | *2 +-$" diffstat.txt
375375
then
376376
echo "[OOPS] diffstat was not generated"
377377
fi
@@ -386,7 +386,7 @@ test_expect_success 'override config option --summary' '
386386
git merge -n c2 >diffstat.txt &&
387387
verify_merge file result.1-5 msg.1-5 &&
388388
verify_parents $c1 $c2 &&
389-
if grep -e "^ file | *2 +-$" diffstat.txt
389+
if grep "^ file | *2 +-$" diffstat.txt
390390
then
391391
echo "[OOPS] diffstat was generated"
392392
false

t/t9400-git-cvsserver-server.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ EOF
9494

9595
test_expect_success 'pserver authentication' \
9696
'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
97-
tail -n1 log | grep -q "^I LOVE YOU$"'
97+
tail -n1 log | grep "^I LOVE YOU$"'
9898

9999
test_expect_success 'pserver authentication failure (non-anonymous user)' \
100100
'if cat request-git | git-cvsserver pserver >log 2>&1
@@ -103,11 +103,11 @@ test_expect_success 'pserver authentication failure (non-anonymous user)' \
103103
else
104104
true
105105
fi &&
106-
tail -n1 log | grep -q "^I HATE YOU$"'
106+
tail -n1 log | grep "^I HATE YOU$"'
107107

108108
test_expect_success 'pserver authentication (login)' \
109109
'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
110-
tail -n1 log | grep -q "^I LOVE YOU$"'
110+
tail -n1 log | grep "^I LOVE YOU$"'
111111

112112
test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
113113
'if cat login-git | git-cvsserver pserver >log 2>&1
@@ -116,7 +116,7 @@ test_expect_success 'pserver authentication failure (login/non-anonymous user)'
116116
else
117117
true
118118
fi &&
119-
tail -n1 log | grep -q "^I HATE YOU$"'
119+
tail -n1 log | grep "^I HATE YOU$"'
120120

121121

122122
# misuse pserver authentication for testing of req_Root
@@ -146,15 +146,15 @@ test_expect_success 'req_Root failure (relative pathname)' \
146146
else
147147
true
148148
fi &&
149-
tail log | grep -q "^error 1 Root must be an absolute pathname$"'
149+
tail log | grep "^error 1 Root must be an absolute pathname$"'
150150

151151
test_expect_success 'req_Root failure (conflicting roots)' \
152152
'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
153-
tail log | grep -q "^error 1 Conflicting roots specified$"'
153+
tail log | grep "^error 1 Conflicting roots specified$"'
154154

155155
test_expect_success 'req_Root (strict paths)' \
156156
'cat request-anonymous | git-cvsserver --strict-paths pserver $SERVERDIR >log 2>&1 &&
157-
tail -n1 log | grep -q "^I LOVE YOU$"'
157+
tail -n1 log | grep "^I LOVE YOU$"'
158158

159159
test_expect_success 'req_Root failure (strict-paths)' '
160160
! cat request-anonymous |
@@ -163,7 +163,7 @@ test_expect_success 'req_Root failure (strict-paths)' '
163163

164164
test_expect_success 'req_Root (w/o strict-paths)' \
165165
'cat request-anonymous | git-cvsserver pserver $WORKDIR/ >log 2>&1 &&
166-
tail -n1 log | grep -q "^I LOVE YOU$"'
166+
tail -n1 log | grep "^I LOVE YOU$"'
167167

168168
test_expect_success 'req_Root failure (w/o strict-paths)' '
169169
! cat request-anonymous |
@@ -181,7 +181,7 @@ EOF
181181

182182
test_expect_success 'req_Root (base-path)' \
183183
'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
184-
tail -n1 log | grep -q "^I LOVE YOU$"'
184+
tail -n1 log | grep "^I LOVE YOU$"'
185185

186186
test_expect_success 'req_Root failure (base-path)' '
187187
! cat request-anonymous |
@@ -192,14 +192,14 @@ GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
192192

193193
test_expect_success 'req_Root (export-all)' \
194194
'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 &&
195-
tail -n1 log | grep -q "^I LOVE YOU$"'
195+
tail -n1 log | grep "^I LOVE YOU$"'
196196

197197
test_expect_success 'req_Root failure (export-all w/o whitelist)' \
198198
'! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
199199

200200
test_expect_success 'req_Root (everything together)' \
201201
'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
202-
tail -n1 log | grep -q "^I LOVE YOU$"'
202+
tail -n1 log | grep "^I LOVE YOU$"'
203203

204204
GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
205205

@@ -216,7 +216,7 @@ test_expect_success 'gitcvs.enabled = false' \
216216
else
217217
true
218218
fi &&
219-
cat cvs.log | grep -q "GITCVS emulation disabled" &&
219+
grep "GITCVS emulation disabled" cvs.log &&
220220
test ! -d cvswork2'
221221

222222
rm -fr cvswork2
@@ -237,7 +237,7 @@ test_expect_success 'gitcvs.ext.enabled = false' \
237237
else
238238
true
239239
fi &&
240-
cat cvs.log | grep -q "GITCVS emulation disabled" &&
240+
grep "GITCVS emulation disabled" cvs.log &&
241241
test ! -d cvswork2'
242242

243243
rm -fr cvswork2

0 commit comments

Comments
 (0)