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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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' \

0 commit comments

Comments
 (0)