Skip to content

Commit e568572

Browse files
committed
Merge branch 'ep/avoid-test-a-o'
Update tests and scripts to avoid "test ... -a ...", which is often more error-prone than "test ... && test ...". Squashed misconversion fix-up into git-submodule.sh updates. * ep/avoid-test-a-o: git-submodule.sh: avoid "echo" path-like values git-submodule.sh: avoid "test <cond> -a/-o <cond>" t/test-lib-functions.sh: avoid "test <cond> -a/-o <cond>" t/t9814-git-p4-rename.sh: avoid "test <cond> -a/-o <cond>" t/t5538-push-shallow.sh: avoid "test <cond> -a/-o <cond>" t/t5403-post-checkout-hook.sh: avoid "test <cond> -a/-o <cond>" t/t5000-tar-tree.sh: avoid "test <cond> -a/-o <cond>" t/t4102-apply-rename.sh: avoid "test <cond> -a/-o <cond>" t/t0026-eol-config.sh: avoid "test <cond> -a/-o <cond>" t/t0025-crlf-auto.sh: avoid "test <cond> -a/-o <cond>" t/lib-httpd.sh: avoid "test <cond> -a/-o <cond>" git-rebase--interactive.sh: avoid "test <cond> -a/-o <cond>" git-mergetool.sh: avoid "test <cond> -a/-o <cond>" git-bisect.sh: avoid "test <cond> -a/-o <cond>" contrib/examples/git-resolve.sh: avoid "test <cond> -a/-o <cond>" contrib/examples/git-repack.sh: avoid "test <cond> -a/-o <cond>" contrib/examples/git-merge.sh: avoid "test <cond> -a/-o <cond>" contrib/examples/git-commit.sh: avoid "test <cond> -a/-o <cond>" contrib/examples/git-clone.sh: avoid "test <cond> -a/-o <cond>" check_bindir: avoid "test <cond> -a/-o <cond>"
2 parents 5b9b715 + 6a06623 commit e568572

18 files changed

+58
-50
lines changed

Diff for: check_bindir

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
bindir="$1"
33
gitexecdir="$2"
44
gitcmd="$3"
5-
if test "$bindir" != "$gitexecdir" -a -x "$gitcmd"
5+
if test "$bindir" != "$gitexecdir" && test -x "$gitcmd"
66
then
77
echo
88
echo "!! You have installed git-* commands to new gitexecdir."

Diff for: contrib/examples/git-clone.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ then
516516

517517
case "$no_checkout" in
518518
'')
519-
test "z$quiet" = z -a "z$no_progress" = z && v=-v || v=
519+
test "z$quiet" = z && test "z$no_progress" = z && v=-v || v=
520520
git read-tree -m -u $v HEAD HEAD
521521
esac
522522
fi

Diff for: contrib/examples/git-commit.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ run_status () {
5151
export GIT_INDEX_FILE
5252
fi
5353

54-
if test "$status_only" = "t" -o "$use_status_color" = "t"; then
54+
if test "$status_only" = "t" || test "$use_status_color" = "t"; then
5555
color=
5656
else
5757
color=--nocolor
@@ -296,7 +296,7 @@ t,,,[1-9]*)
296296
die "No paths with -i does not make sense." ;;
297297
esac
298298

299-
if test ! -z "$templatefile" -a -z "$log_given"
299+
if test ! -z "$templatefile" && test -z "$log_given"
300300
then
301301
if test ! -f "$templatefile"
302302
then

Diff for: contrib/examples/git-merge.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ merge_name () {
161161
return
162162
fi
163163
fi
164-
if test "$remote" = "FETCH_HEAD" -a -r "$GIT_DIR/FETCH_HEAD"
164+
if test "$remote" = "FETCH_HEAD" && test -r "$GIT_DIR/FETCH_HEAD"
165165
then
166166
sed -e 's/ not-for-merge / /' -e 1q \
167167
"$GIT_DIR/FETCH_HEAD"
@@ -527,7 +527,7 @@ do
527527
git diff-files --name-only
528528
git ls-files --unmerged
529529
} | wc -l`
530-
if test $best_cnt -le 0 -o $cnt -le $best_cnt
530+
if test $best_cnt -le 0 || test $cnt -le $best_cnt
531531
then
532532
best_strategy=$strategy
533533
best_cnt=$cnt

Diff for: contrib/examples/git-repack.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ case ",$all_into_one," in
7676
existing="$existing $e"
7777
fi
7878
done
79-
if test -n "$existing" -a -n "$unpack_unreachable" -a \
80-
-n "$remove_redundant"
79+
if test -n "$existing" && test -n "$unpack_unreachable" && \
80+
test -n "$remove_redundant"
8181
then
8282
# This may have arbitrary user arguments, so we
8383
# have to protect it against whitespace splitting

Diff for: contrib/examples/git-resolve.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ case "$common" in
7676
2>/dev/null || continue
7777
# Count the paths that are unmerged.
7878
cnt=$(GIT_INDEX_FILE=$G git ls-files --unmerged | wc -l)
79-
if test $best_cnt -le 0 -o $cnt -le $best_cnt
79+
if test $best_cnt -le 0 || test $cnt -le $best_cnt
8080
then
8181
best=$c
8282
best_cnt=$cnt

Diff for: git-bisect.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ bisect_replay () {
408408
bisect_reset
409409
while read git bisect command rev
410410
do
411-
test "$git $bisect" = "git bisect" -o "$git" = "git-bisect" || continue
411+
test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue
412412
if test "$git" = "git-bisect"
413413
then
414414
rev="$command"

Diff for: git-mergetool.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ checkout_staged_file () {
205205
"$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" \
206206
: '\([^ ]*\) ')
207207

208-
if test $? -eq 0 -a -n "$tmpfile"
208+
if test $? -eq 0 && test -n "$tmpfile"
209209
then
210210
mv -- "$(git rev-parse --show-cdup)$tmpfile" "$3"
211211
else
@@ -256,7 +256,7 @@ merge_file () {
256256
checkout_staged_file 2 "$MERGED" "$LOCAL"
257257
checkout_staged_file 3 "$MERGED" "$REMOTE"
258258

259-
if test -z "$local_mode" -o -z "$remote_mode"
259+
if test -z "$local_mode" || test -z "$remote_mode"
260260
then
261261
echo "Deleted merge conflict for '$MERGED':"
262262
describe_file "$local_mode" "local" "$LOCAL"

Diff for: git-rebase--interactive.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ then
10131013
git rev-list $revisions |
10141014
while read rev
10151015
do
1016-
if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
1016+
if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
10171017
then
10181018
# Use -f2 because if rev-list is telling us this commit is
10191019
# not worthwhile, we don't want to track its multiple heads,

Diff for: git-submodule.sh

+27-19
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ module_name()
235235
sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
236236
test -z "$name" &&
237237
die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$sm_path'")"
238-
echo "$name"
238+
printf '%s\n' "$name"
239239
}
240240

241241
#
@@ -305,10 +305,10 @@ module_clone()
305305
b=${b%/}
306306

307307
# Turn each leading "*/" component into "../"
308-
rel=$(echo $b | sed -e 's|[^/][^/]*|..|g')
309-
echo "gitdir: $rel/$a" >"$sm_path/.git"
308+
rel=$(printf '%s\n' "$b" | sed -e 's|[^/][^/]*|..|g')
309+
printf '%s\n' "gitdir: $rel/$a" >"$sm_path/.git"
310310

311-
rel=$(echo $a | sed -e 's|[^/][^/]*|..|g')
311+
rel=$(printf '%s\n' "$a" | sed -e 's|[^/][^/]*|..|g')
312312
(clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
313313
}
314314

@@ -389,11 +389,11 @@ cmd_add()
389389
sm_path=$2
390390

391391
if test -z "$sm_path"; then
392-
sm_path=$(echo "$repo" |
392+
sm_path=$(printf '%s\n' "$repo" |
393393
sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
394394
fi
395395

396-
if test -z "$repo" -o -z "$sm_path"; then
396+
if test -z "$repo" || test -z "$sm_path"; then
397397
usage
398398
fi
399399

@@ -450,7 +450,7 @@ Use -f if you really want to add it." >&2
450450
# perhaps the path exists and is already a git repo, else clone it
451451
if test -e "$sm_path"
452452
then
453-
if test -d "$sm_path"/.git -o -f "$sm_path"/.git
453+
if test -d "$sm_path"/.git || test -f "$sm_path"/.git
454454
then
455455
eval_gettextln "Adding existing repo at '\$sm_path' to the index"
456456
else
@@ -832,7 +832,7 @@ Maybe you want to use 'update --init'?")"
832832
continue
833833
fi
834834

835-
if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
835+
if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
836836
then
837837
module_clone "$sm_path" "$name" "$url" "$reference" "$depth" || exit
838838
cloned_modules="$cloned_modules;$name"
@@ -857,11 +857,11 @@ Maybe you want to use 'update --init'?")"
857857
die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
858858
fi
859859

860-
if test "$subsha1" != "$sha1" -o -n "$force"
860+
if test "$subsha1" != "$sha1" || test -n "$force"
861861
then
862862
subforce=$force
863863
# If we don't already have a -f flag and the submodule has never been checked out
864-
if test -z "$subsha1" -a -z "$force"
864+
if test -z "$subsha1" && test -z "$force"
865865
then
866866
subforce="-f"
867867
fi
@@ -1031,7 +1031,7 @@ cmd_summary() {
10311031
then
10321032
head=$rev
10331033
test $# = 0 || shift
1034-
elif test -z "$1" -o "$1" = "HEAD"
1034+
elif test -z "$1" || test "$1" = "HEAD"
10351035
then
10361036
# before the first commit: compare with an empty tree
10371037
head=$(git hash-object -w -t tree --stdin </dev/null)
@@ -1056,17 +1056,21 @@ cmd_summary() {
10561056
while read mod_src mod_dst sha1_src sha1_dst status sm_path
10571057
do
10581058
# Always show modules deleted or type-changed (blob<->module)
1059-
test $status = D -o $status = T && echo "$sm_path" && continue
1059+
if test "$status" = D || test "$status" = T
1060+
then
1061+
printf '%s\n' "$sm_path"
1062+
continue
1063+
fi
10601064
# Respect the ignore setting for --for-status.
10611065
if test -n "$for_status"
10621066
then
10631067
name=$(module_name "$sm_path")
10641068
ignore_config=$(get_submodule_config "$name" ignore none)
1065-
test $status != A -a $ignore_config = all && continue
1069+
test $status != A && test $ignore_config = all && continue
10661070
fi
10671071
# Also show added or modified modules which are checked out
10681072
GIT_DIR="$sm_path/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
1069-
echo "$sm_path"
1073+
printf '%s\n' "$sm_path"
10701074
done
10711075
)
10721076

@@ -1122,7 +1126,7 @@ cmd_summary() {
11221126
*)
11231127
errmsg=
11241128
total_commits=$(
1125-
if test $mod_src = 160000 -a $mod_dst = 160000
1129+
if test $mod_src = 160000 && test $mod_dst = 160000
11261130
then
11271131
range="$sha1_src...$sha1_dst"
11281132
elif test $mod_src = 160000
@@ -1159,7 +1163,7 @@ cmd_summary() {
11591163
# i.e. deleted or changed to blob
11601164
test $mod_dst = 160000 && echo "$errmsg"
11611165
else
1162-
if test $mod_src = 160000 -a $mod_dst = 160000
1166+
if test $mod_src = 160000 && test $mod_dst = 160000
11631167
then
11641168
limit=
11651169
test $summary_limit -gt 0 && limit="-$summary_limit"
@@ -1230,7 +1234,11 @@ cmd_status()
12301234
say "U$sha1 $displaypath"
12311235
continue
12321236
fi
1233-
if test -z "$url" || ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
1237+
if test -z "$url" ||
1238+
{
1239+
! test -d "$sm_path"/.git &&
1240+
! test -f "$sm_path"/.git
1241+
}
12341242
then
12351243
say "-$sha1 $displaypath"
12361244
continue;
@@ -1303,7 +1311,7 @@ cmd_sync()
13031311
./*|../*)
13041312
# rewrite foo/bar as ../.. to find path from
13051313
# submodule work tree to superproject work tree
1306-
up_path="$(echo "$sm_path" | sed "s/[^/][^/]*/../g")" &&
1314+
up_path="$(printf '%s\n' "$sm_path" | sed "s/[^/][^/]*/../g")" &&
13071315
# guarantee a trailing /
13081316
up_path=${up_path%/}/ &&
13091317
# path from submodule work tree to submodule origin repo
@@ -1399,7 +1407,7 @@ then
13991407
fi
14001408

14011409
# "--cached" is accepted only by "status" and "summary"
1402-
if test -n "$cached" && test "$command" != status -a "$command" != summary
1410+
if test -n "$cached" && test "$command" != status && test "$command" != summary
14031411
then
14041412
usage
14051413
fi

Diff for: t/lib-httpd.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ prepare_httpd() {
142142
HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST
143143
HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:pass%40host@$HTTPD_DEST
144144

145-
if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
145+
if test -n "$LIB_HTTPD_DAV" || test -n "$LIB_HTTPD_SVN"
146146
then
147147
HTTPD_PARA="$HTTPD_PARA -DDAV"
148148

Diff for: t/t0025-crlf-auto.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test_expect_success 'default settings cause no changes' '
3636
onediff=$(git diff one) &&
3737
twodiff=$(git diff two) &&
3838
threediff=$(git diff three) &&
39-
test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
39+
test -z "$onediff" && test -z "$twodiff" && test -z "$threediff"
4040
'
4141

4242
test_expect_success 'crlf=true causes a CRLF file to be normalized' '
@@ -111,7 +111,7 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '
111111
onediff=$(git diff one) &&
112112
twodiff=$(git diff two) &&
113113
threediff=$(git diff three) &&
114-
test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
114+
test -z "$onediff" && test -z "$twodiff" && test -z "$threediff"
115115
'
116116

117117
test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
@@ -126,7 +126,7 @@ test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
126126
onediff=$(git diff one) &&
127127
twodiff=$(git diff two) &&
128128
threediff=$(git diff three) &&
129-
test -z "$onediff" -a -n "$twodiff" -a -z "$threediff"
129+
test -z "$onediff" && test -n "$twodiff" && test -z "$threediff"
130130
'
131131

132132
test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '

Diff for: t/t0026-eol-config.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test_expect_success 'eol=lf puts LFs in normalized file' '
3636
! has_cr two &&
3737
onediff=$(git diff one) &&
3838
twodiff=$(git diff two) &&
39-
test -z "$onediff" -a -z "$twodiff"
39+
test -z "$onediff" && test -z "$twodiff"
4040
'
4141

4242
test_expect_success 'eol=crlf puts CRLFs in normalized file' '
@@ -49,7 +49,7 @@ test_expect_success 'eol=crlf puts CRLFs in normalized file' '
4949
! has_cr two &&
5050
onediff=$(git diff one) &&
5151
twodiff=$(git diff two) &&
52-
test -z "$onediff" -a -z "$twodiff"
52+
test -z "$onediff" && test -z "$twodiff"
5353
'
5454

5555
test_expect_success 'autocrlf=true overrides eol=lf' '
@@ -63,7 +63,7 @@ test_expect_success 'autocrlf=true overrides eol=lf' '
6363
has_cr two &&
6464
onediff=$(git diff one) &&
6565
twodiff=$(git diff two) &&
66-
test -z "$onediff" -a -z "$twodiff"
66+
test -z "$onediff" && test -z "$twodiff"
6767
'
6868

6969
test_expect_success 'autocrlf=true overrides unset eol' '
@@ -77,7 +77,7 @@ test_expect_success 'autocrlf=true overrides unset eol' '
7777
has_cr two &&
7878
onediff=$(git diff one) &&
7979
twodiff=$(git diff two) &&
80-
test -z "$onediff" -a -z "$twodiff"
80+
test -z "$onediff" && test -z "$twodiff"
8181
'
8282

8383
test_done

Diff for: t/t4102-apply-rename.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ EOF
5252

5353
test_expect_success 'apply copy' \
5454
'git apply --index --stat --summary --apply test-patch &&
55-
test "$(cat bar)" = "This is bar" -a "$(cat foo)" = "This is foo"'
55+
test "$(cat bar)" = "This is bar" && test "$(cat foo)" = "This is foo"'
5656

5757
test_done

Diff for: t/t5000-tar-tree.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ check_tar() {
7272
for header in *.paxheader
7373
do
7474
data=${header%.paxheader}.data &&
75-
if test -h $data -o -e $data
75+
if test -h $data || test -e $data
7676
then
7777
path=$(get_pax_header $header path) &&
7878
if test -n "$path"

Diff for: t/t5403-post-checkout-hook.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test_expect_success 'post-checkout receives the right arguments with HEAD unchan
3939
old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
4040
new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
4141
flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
42-
test $old = $new -a $flag = 1
42+
test $old = $new && test $flag = 1
4343
'
4444

4545
test_expect_success 'post-checkout runs as expected ' '
@@ -52,23 +52,23 @@ test_expect_success 'post-checkout args are correct with git checkout -b ' '
5252
old=$(awk "{print \$1}" clone1/.git/post-checkout.args) &&
5353
new=$(awk "{print \$2}" clone1/.git/post-checkout.args) &&
5454
flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) &&
55-
test $old = $new -a $flag = 1
55+
test $old = $new && test $flag = 1
5656
'
5757

5858
test_expect_success 'post-checkout receives the right args with HEAD changed ' '
5959
GIT_DIR=clone2/.git git checkout new2 &&
6060
old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
6161
new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
6262
flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
63-
test $old != $new -a $flag = 1
63+
test $old != $new && test $flag = 1
6464
'
6565

6666
test_expect_success 'post-checkout receives the right args when not switching branches ' '
6767
GIT_DIR=clone2/.git git checkout master b &&
6868
old=$(awk "{print \$1}" clone2/.git/post-checkout.args) &&
6969
new=$(awk "{print \$2}" clone2/.git/post-checkout.args) &&
7070
flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) &&
71-
test $old = $new -a $flag = 0
71+
test $old = $new && test $flag = 0
7272
'
7373

7474
if test "$(git config --bool core.filemode)" = true; then

0 commit comments

Comments
 (0)