diff --git a/bin/git-bulk b/bin/git-bulk index 3480bb4db..e3bdd66d6 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -22,27 +22,33 @@ usage() { echo 1>&2 " git bulk --listall" } +cdfail() { + echo 1>&2 "failed to change directory: $1" + exit 1 +} + # add another workspace to global git config function addworkspace { - git config --global bulkworkspaces."$wsname" "$wsdir"; - if [ -n "$source" ]; then + git config --global bulkworkspaces."$wsname" "$wsdir"; + if [ -n "$source" ]; then if [ ! -d "$wsdir" ]; then echo 1>&2 "Path of workspace doesn't exist, make it first."; exit 1; fi regex='http(s)?://|ssh://|(git@)?.*:.*/.*' if [[ "$source" =~ $regex ]]; then - pushd "$wsdir" > /dev/null + pushd "$wsdir" > /dev/null || cdfail "$wsdir" git clone "$source" - popd > /dev/null + popd > /dev/null || cdfail "$OLDPWD" else source=$(realpath "$source" 2>/dev/null) if [ -f "$source" ]; then - pushd "$wsdir" > /dev/null + pushd "$wsdir" > /dev/null || cdfail "$wsdir" while IFS= read -r line; do if [ -n "$line" ]; then # the git clone command to take the complete line in the repository.txt as separate argument. This facilitated the cloning of the repository with a custom folder name. + # shellcheck disable=SC2086 git clone $line; fi done < "$source" - popd > /dev/null + popd > /dev/null || cdfail "$OLDPWD" else echo 1>&2 "format of URL or file unknown" fi diff --git a/bin/git-changelog b/bin/git-changelog index 82b480200..986461642 100755 --- a/bin/git-changelog +++ b/bin/git-changelog @@ -146,6 +146,8 @@ _fetchCommitRange() { local start_tag="$2" local final_tag="$3" + # This shellcheck disable is applied to the whole if-body + # shellcheck disable=SC2086 if [[ "$list_all" == true ]]; then git log $GIT_LOG_OPTS --pretty=format:"${CUR_GIT_LOG_FORMAT}" elif [[ -n "$final_tag" && "$start_tag" == "null" ]]; then diff --git a/bin/git-force-clone b/bin/git-force-clone index a4c4d3225..72f1dcee7 100755 --- a/bin/git-force-clone +++ b/bin/git-force-clone @@ -91,7 +91,8 @@ main() { git reset --hard "origin/${branch}" # Delete all other branches - branches=$(git branch | grep -v \* | xargs) + # shellcheck disable=SC2063 + branches=$(git branch | grep -v '*' | xargs) if [ -n "${branches}" ]; then git branch -D "${branches}" fi diff --git a/bin/git-psykorebase b/bin/git-psykorebase index 5c9a3dad7..b3e1a7ca9 100755 --- a/bin/git-psykorebase +++ b/bin/git-psykorebase @@ -71,10 +71,9 @@ else git checkout "${PRIMARY_BRANCH}" || exit 41 git checkout -b "${TARGET_BRANCH}" || exit 42 - git merge "${SECONDARY_BRANCH}" ${FF} \ - -m "Psycho-rebased branch ${SECONDARY_BRANCH} on top of ${PRIMARY_BRANCH}" - if [[ $? == 0 ]]; then + if git merge "${SECONDARY_BRANCH}" ${FF} \ + -m "Psycho-rebased branch ${SECONDARY_BRANCH} on top of ${PRIMARY_BRANCH}"; then git branch -d "${SECONDARY_BRANCH}" || exit 43 git branch -m "${TARGET_BRANCH}" "${SECONDARY_BRANCH}" || exit 44 else diff --git a/bin/git-utimes b/bin/git-utimes index 2b76372ea..7d99a5987 100755 --- a/bin/git-utimes +++ b/bin/git-utimes @@ -17,9 +17,11 @@ if [ "$1" = "--touch" ]; then fi for f; do git_s=$(git --no-pager log --no-renames --pretty=format:%ct -1 @ -- "$f" 2>/dev/null) + # shellcheck disable=SC2086 mod_s=$(stat $stat_flags "$f" 2>/dev/null) if [ -n "$git_s" ] && [ -n "$mod_s" ] && [ "$mod_s" -ne "$git_s" ]; then if [ "$mod_s" -gt "$git_s" ] || [ -z "$newer_flag" ]; then + # shellcheck disable=SC2086 t=$(date $date_flags$git_s '+%Y%m%d%H%M.%S') echo "+ touch -h -t $t $f" >&2 touch -h -t "$t" "$f" @@ -35,6 +37,7 @@ else # don't touch files that have been modified in the worktree or index # bsd doesn't have `-z` option for `comm` and `cut`, so use `tr` as work around prefix="$(git rev-parse --show-prefix) " + # shellcheck disable=SC2086 comm -23 <(git ls-tree -z -r --name-only --full-name @ | tr '\0' '\n' | sort) \ <(git status -z --porcelain | tr '\0' '\n' | cut -c 4- | sort) \ | cut -c ${#prefix}- \ diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index a5942a4f7..c2be086a3 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -67,6 +67,7 @@ _git_effort(){ case "$cur" in --*) + # shellcheck disable=SC2154 __gitcomp " --above $__git_log_common_options @@ -82,7 +83,7 @@ _git_extras(){ } __git_extras_workflow(){ - __gitcomp "$(__git_heads | grep -- ^$1/ | sed s/^$1\\///g) finish" + __gitcomp "$(__git_heads | grep -- "^$1/" | sed s/^"$1"\\///g) finish" } _git_feature(){