Skip to content

Commit 4f27e5a

Browse files
committed
Use POSIX strict mode
Fixes #303 Signed-off-by: Richard Hartmann <[email protected]>
1 parent 4f013c3 commit 4f27e5a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

vcsh.in

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
# which is admittedly extremely unlikely to the point of being impossible,
1313
# this software will most likely follow suit.
1414

15+
# POSIX strict mode; set -eu would be the other way to write this
16+
set -o errexit
17+
set -o nounset
18+
IFS=$(printf '\n\t')
19+
1520
# This should always be the first line of code to facilitate debugging
21+
VCSH_DEBUG=''; export VCSH_DEBUG
1622
[ -n "$VCSH_DEBUG" ] && set -vx
1723

1824

@@ -36,6 +42,7 @@ fatal() {
3642
# options that will modify our behaviour.
3743
# Commands are handled at the end of this script.
3844
# shellcheck disable=SC2220
45+
VCSH_OPTION_CONFIG=''; export VCSH_OPTION_CONFIG
3946
while getopts c:dv flag; do
4047
case "$flag" in
4148
d)
@@ -593,7 +600,7 @@ if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ] &&
593600
fatal "'\$VCSH_GITIGNORE' must equal 'exact', 'none', or 'recursive'" 1
594601
fi
595602

596-
VCSH_COMMAND=$1; export VCSH_COMMAND
603+
VCSH_COMMAND=${1-}; export VCSH_COMMAND
597604

598605
case $VCSH_COMMAND in
599606
clon|clo|cl) VCSH_COMMAND=clone;;
@@ -682,7 +689,7 @@ elif [ x"$VCSH_COMMAND" = x'status' ]; then
682689
shift
683690
fi
684691
VCSH_REPO_NAME=$2; export VCSH_REPO_NAME
685-
elif [ -n "$2" ]; then
692+
elif [ -n "${2-}" ]; then
686693
VCSH_COMMAND='run'; export VCSH_COMMAND
687694
VCSH_REPO_NAME=$1; export VCSH_REPO_NAME
688695
GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
@@ -695,7 +702,8 @@ elif [ -n "$VCSH_COMMAND" ]; then
695702
GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
696703
[ -d "$GIT_DIR" ] || { help; exit 1; }
697704
else
698-
# $1 is empty
705+
# $1 is empty. We exit 1 to discern from `vcsh help` and to help catch
706+
# scripts which erroueously don't provide options
699707
help && exit 1
700708
fi
701709

0 commit comments

Comments
 (0)