Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tools: Enable strict shell mode for various scripts.

Yash Raj Talreja5690c2791ea4
diff --git a/tools/backport-pull-request b/tools/backport-pull-request
index 462627b3fdc..afd087d035b 100755
--- a/tools/backport-pull-request
+++ b/tools/backport-pull-request
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
-
-set -e
+set -euo pipefail
usage() {
cat >&2 <<EOF
@@ -19,7 +18,7 @@ EOF
exit 1
}
-pr_id="$1"
+pr_id="${1-}"
if [ -z "$pr_id" ]; then
usage
diff --git a/tools/clean-branches b/tools/clean-branches
index d0e5f766850..77e65dfcbe4 100755
--- a/tools/clean-branches
+++ b/tools/clean-branches
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-set -e
+set -euo pipefail
# usage: clean-branches
# Deletes any local branches which are ancestors of origin/main,
@@ -65,6 +65,6 @@ git fetch --prune origin
eval "$(git for-each-ref --shell --format='clean_ref %(refname);')"
-if [ "${#push_args}" -ne 0 ]; then
+if [ "${#push_args[@]}" -ne 0 ]; then
git push origin "${push_args[@]}"
fi
diff --git a/tools/deploy-branch b/tools/deploy-branch
index 120d917dfd9..580e932363f 100755
--- a/tools/deploy-branch
+++ b/tools/deploy-branch
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
+set -euo pipefail
function error_out() {
echo -en '\e[0;31m'
@@ -7,11 +8,12 @@ function error_out() {
exit 1
}
-status=$(git status --porcelain | grep -v '^??')
-[ -n "$status" ] && error_out "Working directory or index not clean"
+[ -z "$(git status --porcelain --untracked-files=no)" ] || error_out "Working directory or index not clean"
old_ref=$(git rev-list --max-count=1 HEAD)
-branch=$1
+branch=${1-}
+[ -z "$branch" ] && error_out "You must specify a branch name to deploy"
+
branch_ref=$(git rev-list --max-count=1 "$branch") || error_out "Unknown branch: $branch"
if [ "$old_ref" == "$branch_ref" ]; then
@@ -24,8 +26,6 @@ else
fi
fi
-[ -z "$branch" ] && error_out "You must specify a branch name to deploy"
-
git fetch -p
git rebase origin/main "$branch" || error_out "Rebase onto origin/main failed"
diff --git a/tools/fetch-pull-request b/tools/fetch-pull-request
index 0d6c4c961e8..62a9f4d68aa 100755
--- a/tools/fetch-pull-request
+++ b/tools/fetch-pull-request
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-set -e
+set -euo pipefail
this_dir=${BASH_SOURCE[0]%/*}
# shellcheck source=lib/git-tools.bash
@@ -7,7 +7,11 @@ this_dir=${BASH_SOURCE[0]%/*}
require_clean_work_tree 'check out PR as branch'
-request_id="$1"
+request_id="${1-}"
+if [ -z "$request_id" ]; then
+ echo "Usage: $0 pr_id" >&2
+ exit 1
+fi
remote=${2:-"upstream"}
set -x