Skip to content

Commit 4611b24

Browse files
authored
chore: Fix more Bash inconsistencies (#1021)
1 parent 04eb5c0 commit 4611b24

20 files changed

+63
-64
lines changed

bin/git-archive-file

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ ARCHIVE_NAME=$(basename "$(pwd)")
99

1010
if [[ $BRANCH = tags* ]]; then
1111
BRANCH=$(git describe)
12-
echo Building for tag \"$BRANCH\"
12+
echo Building for tag "\"$BRANCH\""
1313
FILENAME=$ARCHIVE_NAME.$BRANCH.zip
1414
else
15-
echo Building archive on branch \"$BRANCH\"
15+
echo Building archive on branch "\"$BRANCH\""
1616
# get a version string, so archives will not be overwritten when creating
1717
# many of them
1818
VERSION=$(git describe --always --long)
1919
# if not on master append branch name into the filename
20-
if [ "$BRANCH" = $(git_extra_default_branch) ]; then
20+
if [ "$BRANCH" = "$(git_extra_default_branch)" ]; then
2121
FILENAME=$ARCHIVE_NAME.$VERSION.zip
2222
else
2323
FILENAME=$ARCHIVE_NAME.$VERSION.$BRANCH.zip
@@ -31,7 +31,7 @@ FILENAME=${FILENAME//\\/-}
3131
OUTPUT=$(pwd)/$FILENAME
3232

3333
# building archive
34-
git archive --format zip --output "$OUTPUT" $BRANCH
34+
git archive --format zip --output "$OUTPUT" "$BRANCH"
3535

3636
# also display size of the resulting file
3737
echo Saved to \""$FILENAME"\" \("$(du -h "$OUTPUT" | cut -f1)"\)

bin/git-browse

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [[ $remote == "" ]]; then
1818
fi
1919

2020
# get remote url
21-
remote_url=$(git remote get-url $remote)
21+
remote_url=$(git remote get-url "$remote")
2222

2323
if [[ $? -ne 0 ]]; then
2424
exit $?

bin/git-browse-ci

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else
99
remote=$1
1010
fi
1111

12-
if [[ $remote == "" ]]
12+
if [[ -z $remote ]]
1313
then
1414
echo "Remote not found"
1515
exit 1

bin/git-bulk

+5-5
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ function checkGitCommand () {
8989

9090
# check if workspace name is registered
9191
function checkWSName () {
92-
while read workspace; do
92+
while read -r workspace; do
9393
parseWsName "$workspace"
9494
if [[ $rwsname == "$wsname" ]]; then return; fi
95-
done <<< "$(echo "$(listall)")"
95+
done <<< "$(listall)"
9696
# when here the ws name was not found
9797
usage && echo 1>&2 "error: unknown workspace name: $wsname" && exit 1
9898
}
@@ -106,14 +106,14 @@ function parseWsName () {
106106

107107
# detects the wsname of the current directory
108108
function wsnameToCurrent () {
109-
while read workspace; do
109+
while read -r workspace; do
110110
if [ -z "$workspace" ]; then continue; fi
111111
parseWsName "$workspace"
112112
if echo "$PWD" | grep -o -q "$rwsdir"; then wsname="$rwsname" && return; fi
113-
done <<< "$(echo "$(listall)")"
113+
done <<< "$(listall)"
114114
# when here then not in workspace dir
115115
echo 1>&2 "error: you are not in a workspace directory. your registered workspaces are:" && \
116-
wslist="$(echo "$(listall)")" && echo 1>&2 "${wslist:-'<no workspaces defined yet>'}" && exit 1
116+
wslist="$(listall)" && echo 1>&2 "${wslist:-'<no workspaces defined yet>'}" && exit 1
117117
}
118118

119119
# helper to check number of arguments.

bin/git-create-branch

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ test -z $BRANCH && echo "branch argument required." 1>&2 && exit 1
4444
if [[ -n $REMOTE ]]
4545
then
4646
stderr=$(git_extra_mktemp)
47-
git ls-remote --exit-code $REMOTE 1>/dev/null 2>"$stderr"
47+
git ls-remote --exit-code "$REMOTE" 1>/dev/null 2>"$stderr"
4848
REMOTE_EXIT=$?
4949
REMOTE_ERROR=$(<"$stderr")
5050
rm -f "$stderr"
5151
if [ $REMOTE_EXIT -eq 0 ]
5252
then
5353
if [[ -n $START_POINT ]]; then
54-
git fetch $REMOTE
55-
git checkout --track -b $BRANCH $START_POINT
56-
git push $REMOTE HEAD:refs/heads/$BRANCH
54+
git fetch "$REMOTE"
55+
git checkout --track -b "$BRANCH" "$START_POINT"
56+
git push "$REMOTE" "HEAD:refs/heads/$BRANCH"
5757
else
58-
git push $REMOTE HEAD:refs/heads/$BRANCH
59-
git fetch $REMOTE
60-
git checkout --track -b $BRANCH $REMOTE/$BRANCH
58+
git push "$REMOTE" "HEAD:refs/heads/$BRANCH"
59+
git fetch "$REMOTE"
60+
git checkout --track -b "$BRANCH" "$REMOTE/$BRANCH"
6161
fi
6262
exit $?
6363
else
@@ -70,7 +70,7 @@ fi
7070

7171
if [[ -n $START_POINT ]]
7272
then
73-
git checkout -b $BRANCH "$START_POINT"
73+
git checkout -b "$BRANCH" "$START_POINT"
7474
else
75-
git checkout -b $BRANCH
75+
git checkout -b "$BRANCH"
7676
fi

bin/git-delete-branch

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
set -e
33

44
# Assert there is at least one branch provided
5-
test -z $1 && echo "branch required." 1>&2 && exit 1
5+
test -z "$1" && echo "branch required." 1>&2 && exit 1
66

77
for branch in "$@"
88
do
9-
remote=$(git config branch.$branch.remote || echo "origin")
10-
ref=$(git config branch.$branch.merge || echo "refs/heads/$branch")
9+
remote=$(git config "branch.$branch.remote" || echo "origin")
10+
ref=$(git config "branch.$branch.merge" || echo "refs/heads/$branch")
1111

12-
git branch -D $branch || true
12+
git branch -D "$branch" || true
1313
# Avoid deleting local upstream
14-
[ "$remote" == "." ] && continue
15-
git branch -d -r $remote/$branch || continue
16-
git push $remote :$ref
14+
[ "$remote" = "." ] && continue
15+
git branch -d -r "$remote/$branch" || continue
16+
git push "$remote" ":$ref"
1717
done

bin/git-delete-squashed-branches

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fi
1212
git for-each-ref refs/heads/ "--format=%(refname:short)" | while read -r branch; do
1313
mergeBase=$(git merge-base "$targetBranch" "$branch")
1414

15-
if [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]]; then
15+
if [[ $(git cherry "$targetBranch" $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]]; then
1616
git branch -D "$branch"
1717
fi
1818
done

bin/git-delete-tag

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ do
2222
done
2323

2424
# Delete all the tags
25-
git tag -d $local_tags
26-
git push $origin $origin_refs
25+
git tag -d "$local_tags"
26+
git push "$origin" "$origin_refs"

bin/git-delta

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ else
1212
fi
1313
fi
1414

15-
git diff --name-only --diff-filter=$filter $branch
15+
git diff --name-only --diff-filter="$filter" "$branch"

bin/git-gh-pages

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ echo 'setting up gh-pages'
44
echo '-------------------'
55

66
echo 'Tell me your github account username: '
7-
read username
7+
read -r username
88

99
echo 'Now, tell me your repository name: '
10-
read repository
10+
read -r repository
1111

1212
git stash \
1313
&& git checkout -b 'gh-pages' \

bin/git-merge-repo

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ branch=$2
55
prefix=$3
66
flat=0
77

8-
if test $prefix = "."; then
8+
if test "$prefix" = "."; then
99
prefix=$(mktemp -u 'git-merge-repo.XXXXXXX')
1010
flat=1
1111
fi
@@ -16,10 +16,10 @@ message=$(git log -1 --pretty=%B)
1616

1717
if test $flat -eq 1; then
1818
git stash -u
19-
mv -i $prefix/* ./
19+
mv -i "$prefix"/* ./
2020
git undo
2121
git add .
2222
git commit -am "$message"
2323
git stash apply
24-
rm -drf $prefix
24+
rm -drf "$prefix"
2525
fi

bin/git-mr

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ if [ -z "${1-}" ] ; then
88
fi
99

1010
if test "$1" = "clean"; then
11-
git for-each-ref refs/heads/mr/* --format='%(refname)' | while read ref; do
12-
git branch -D ${ref#refs/heads/}
11+
git for-each-ref refs/heads/mr/* --format='%(refname)' | while read -r ref; do
12+
git branch -D "${ref#refs/heads/}"
1313
done
1414
exit 0
1515
elif [[ $1 =~ ^(https?://[^/]+/(.+))/merge_requests/([0-9]+).*$ ]]; then
@@ -22,7 +22,7 @@ fi
2222

2323
branch=mr/$id
2424
remote_ref=refs/merge-requests/$id/head
25-
git fetch -fu $remote $remote_ref:$branch
26-
git checkout $branch
27-
git config --local --replace branch.$branch.merge $remote_ref
28-
git config --local --replace branch.$branch.remote $remote
25+
git fetch -fu "$remote" "$remote_ref:$branch"
26+
git checkout "$branch"
27+
git config --local --replace "branch.$branch.merge" "$remote_ref"
28+
git config --local --replace "branch.$branch.remote" "$remote"

bin/git-psykorebase

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function usage()
1919
echo " -c|--continue: Continue after the user updates conflicts."
2020
}
2121

22-
while [[ $# > 0 ]]
22+
while [[ $# -gt 0 ]]
2323
do
2424
key="$1"
2525

bin/git-release

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ set -e
44
hook() {
55
local hook=.git/hooks/$1.sh
66
# compat without extname
7-
if test ! -f $hook; then
7+
if test ! -f "$hook"; then
88
hook=.git/hooks/$1
99
fi
1010

11-
if test -f $hook; then
11+
if test -f "$hook"; then
1212
echo "... $1"
1313
shift
14-
if test -x $hook; then
14+
if test -x "$hook"; then
1515
$hook "$@"
1616
else
17-
. $hook "$@"
17+
. "$hook" "$@"
1818
fi
1919
fi
2020
}

bin/git-rename-tag

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
old=$1
44
new=$2
55

6-
test -z $old && echo "old tag name required." 1>&2 && exit 1
7-
test -z $new && echo "new tag name required." 1>&2 && exit 1
6+
test -z "$old" && echo "old tag name required." 1>&2 && exit 1
7+
test -z "$new" && echo "new tag name required." 1>&2 && exit 1
88

9-
git tag $new $old
10-
git tag -d $old
11-
git push origin $new
12-
git push origin :refs/tags/$old
9+
git tag "$new" "$old"
10+
git tag -d "$old"
11+
git push origin "$new"
12+
git push origin ":refs/tags/$old"

bin/git-repl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ echo "type 'ls' to ls files below current directory, '!command' to execute any c
66

77
while true; do
88
# Current branch
9-
cur=`git symbolic-ref HEAD 2> /dev/null | cut -d/ -f3-`
9+
cur=$(git symbolic-ref HEAD 2> /dev/null | cut -d/ -f3-)
1010

1111
# Prompt
1212
if test -n "$cur"; then

bin/git-reset-file

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ file="$1"
44
commit="$2"
55

66
if [[ -f $file ]]; then
7-
git rm --cached -q -f -- $file
7+
git rm --cached -q -f -- "$file"
88
if [[ -z $commit ]]; then
9-
git checkout HEAD -- $file
9+
git checkout HEAD -- "$file"
1010
echo "Reset '$1' to HEAD"
1111
else
12-
git checkout $commit -- $file
12+
git checkout "$commit" -- "$file"
1313
echo "Reset '$1' to $commit"
1414
fi
1515
else
16-
echo "File '$1' not found in `pwd`"
16+
echo "File '$1' not found in $(pwd)"
1717
fi

bin/git-scp

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ function _error()
161161
[ $# -eq 0 ] && _usage && exit 0
162162

163163
echo
164-
echo ERROR: "$@"
164+
echo "ERROR: $*"
165165
echo
166166
exit 1
167167
}
168168

169169
### OPTIONS ###
170-
case $(basename $0) in
170+
case $(basename "$0") in
171171
git-scp)
172172
case $1 in
173-
''|-h|'?'|help|--help) shift; _test_git_scp; _usage $@;;
173+
''|-h|'?'|help|--help) shift; _test_git_scp; _usage "$@";;
174174
*) scp_and_stage $@;;
175175
esac
176176
;;

bin/git-stamp

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ EOF
2222

2323
error() {
2424
if [[ -n "$1" ]]; then
25-
local msg=$( echo "error: $1" )
26-
echo -e "${msg}" >&2
25+
echo "error: $1" >&2
2726
fi
2827
usage
2928
exit 1

bin/git-touch

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ USAGE(){
77

88
test $# -lt 1 && USAGE
99

10-
for filename in $@; do
10+
for filename in "$@"; do
1111
touch "$filename" \
1212
&& git add "$filename"
1313
done

0 commit comments

Comments
 (0)