From c998913bc725f9cf840160958303b1756b5af474 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Mon, 4 Sep 2017 21:24:31 -0600 Subject: [PATCH 1/8] shellcheck cleanupsin git-delete-tag --- bin/git-delete-tag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-delete-tag b/bin/git-delete-tag index f1095e6c6..14c050779 100755 --- a/bin/git-delete-tag +++ b/bin/git-delete-tag @@ -2,4 +2,4 @@ # # Delete a tag, both locally and from the origin remote -git tag -d $1 && git push origin :refs/tags/$1 +exec git tag -d "$1" && git push origin ":refs/tags/$1" From 856625e5187d6de27456b4dd15d944e3d80d9605 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Mon, 4 Sep 2017 21:26:44 -0600 Subject: [PATCH 2/8] shellcheck fixes in git-find-dirty --- bin/git-find-dirty | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/git-find-dirty b/bin/git-find-dirty index 5f01c43dd..39e058ae2 100755 --- a/bin/git-find-dirty +++ b/bin/git-find-dirty @@ -4,9 +4,14 @@ IFS=$'\n' +fail() { + echo "$@" + exit 1 +} + for gitprojpath in $(find . -type d -name .git | sort | sed "s/\/\.git//"); do pushd . > /dev/null - cd "$gitprojpath" + cd "$gitprojpath" || fail "could not $gitprojpath" isdirty=$(git status -s | grep "^.*") if [ -n "$isdirty" ]; then echo "DIRTY:" "$gitprojpath" From 59370396caf7d2f27734c806c49acb007cd06442 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Mon, 4 Sep 2017 21:32:25 -0600 Subject: [PATCH 3/8] shellcheck fixes in git-github-open --- bin/git-github-open | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/git-github-open b/bin/git-github-open index 80d416701..eab26e227 100755 --- a/bin/git-github-open +++ b/bin/git-github-open @@ -21,26 +21,30 @@ LINE="$2" # usage and help test -z "$FILE" -o "$FILE" = '--help' && { - cat "$0" | grep '^##' | cut -c4- 1>&2 + grep '^##' "$0" | cut -c4- 1>&2 exit 1 } # bail out with message to stderr and exit status 1 die() { - echo "$(basename $0):" "$@" 1>&2 - exit 1 + # shellcheck disable=SC2086 + echo "$(basename $0):" "$@" 1>&2 + exit 1 } # figure out relative path to the file from the root # of the work tree +# shellcheck disable=SC2086 path="$(basename $FILE)" -cd $(dirname $FILE) +# shellcheck disable=SC2046 +cd $(dirname "$FILE") while test ! -d .git ; do test "$(pwd)" = / && { echo "error: git repository not found" 1>&2 exit 1 } + # shellcheck disable=SC2046 path="$(basename $(pwd))/$path" cd .. done @@ -70,6 +74,7 @@ die "you're not tracking a remote branch" # at this point we're in root of the work tree and $path is # the relative path to file. +# shellcheck disable=SC2086 remote_url=$(git config --get remote.$remote.url) repo=$(echo "$remote_url" | sed 's/^.*:\(.*\)\.git/\1/') url="http://github.com/$repo/blob/$branch/$path" @@ -81,4 +86,4 @@ url="http://github.com/$repo/blob/$branch/$path" # throw the line number on there if specified test -n "$LINE" && url="$url#L$LINE" -open "$url" \ No newline at end of file +open "$url" From 822b9115ee8f039fd81ef706083b21b99e649ef7 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Mon, 4 Sep 2017 21:33:44 -0600 Subject: [PATCH 4/8] Fix quoting in git-nuke --- bin/git-nuke | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/git-nuke b/bin/git-nuke index 38bf82217..45559afa1 100755 --- a/bin/git-nuke +++ b/bin/git-nuke @@ -7,7 +7,8 @@ # Examples # # git nuke add-git-nuke + set -o errexit -git branch -D $1 -git push origin :$1 +git branch -D "$1" +git push origin ":$1" From 438df8c2ac124659abde9636765366056488c11d Mon Sep 17 00:00:00 2001 From: Joe Block Date: Mon, 4 Sep 2017 21:46:38 -0600 Subject: [PATCH 5/8] Fix wording in failure message --- bin/git-find-dirty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-find-dirty b/bin/git-find-dirty index 39e058ae2..c5fcf253e 100755 --- a/bin/git-find-dirty +++ b/bin/git-find-dirty @@ -11,7 +11,7 @@ fail() { for gitprojpath in $(find . -type d -name .git | sort | sed "s/\/\.git//"); do pushd . > /dev/null - cd "$gitprojpath" || fail "could not $gitprojpath" + cd "$gitprojpath" || fail "could not cd to $gitprojpath" isdirty=$(git status -s | grep "^.*") if [ -n "$isdirty" ]; then echo "DIRTY:" "$gitprojpath" From d60ded72adefb7f44fdd86a4720e74ac411cd355 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Mon, 4 Sep 2017 22:00:22 -0600 Subject: [PATCH 6/8] Clean up git-prune-branches * Quote bare variables * Standardize on spaces for indentations * Update `` to $() --- bin/git-prune-branches | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/bin/git-prune-branches b/bin/git-prune-branches index eaca3b674..a56730b04 100755 --- a/bin/git-prune-branches +++ b/bin/git-prune-branches @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # git-prune-branches # @@ -14,40 +14,42 @@ # License: MIT # Original source: https://github.com/jut-io/git-scripts/blob/master/bin/git-prune-branches -merged=`git branch --no-color --merged master | grep -v master | sed 's/\*/ /'` +merged=$(git branch --no-color --merged master | grep -v master | sed 's/\*/ /') if [ ! -z "$merged" ] ; then echo "Deleting the following merged branches:" for branch in $merged ; do - echo " " $branch + echo " " "$branch" done all=n delete=n for branch in $merged ; do - if [ $all = 'n' ] ; then - delete=n - read -p "Delete $branch (y=yes, n=no, a=all)? " prompt - echo "all=$all delete=$delete prompt=$prompt" - if [ "$prompt" = 'a' ] ; then - delete=y - all=y - elif [ "$prompt" = 'y' ]; then - delete=y - fi - fi + if [ $all = 'n' ] ; then + delete=n + # shellcheck disable=SC2162 + read -p "Delete $branch (y=yes, n=no, a=all)? " prompt + echo "all=$all delete=$delete prompt=$prompt" + if [ "$prompt" = 'a' ] ; then + delete=y + all=y + elif [ "$prompt" = 'y' ]; then + delete=y + fi + fi - if [ "$delete" = 'y' ] ; then - git branch -d $branch - fi + if [ "$delete" = 'y' ] ; then + git branch -d "$branch" + fi done fi -remotes=`git remote` +remotes=$(git remote) for remote in $remotes ; do prompt=n + # shellcheck disable=SC2162 read -p "Prune deleted branches from remote '$remote' (y=yes n=no)? " prompt if [ "$prompt" = 'y' ] ; then - git remote prune $remote + git remote prune "$remote" fi done From c2af5d0545e1292c8f7ce8a38bc3610d61b4e096 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Mon, 4 Sep 2017 22:06:53 -0600 Subject: [PATCH 7/8] Stifle lint messages in git-pruneall --- bin/git-pruneall | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/git-pruneall b/bin/git-pruneall index 0266691e4..56b606af9 100755 --- a/bin/git-pruneall +++ b/bin/git-pruneall @@ -22,6 +22,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +# shellcheck disable=SC2124 REMOTES="$@" test -z "$REMOTES" && From 68ddd0b340b0d5f9eb2626b607876420bcb5ddb0 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Mon, 4 Sep 2017 22:10:51 -0600 Subject: [PATCH 8/8] Disable erroneous lint error in git-purge-from-history --- bin/git-purge-from-history | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/git-purge-from-history b/bin/git-purge-from-history index c23764acf..0b8f07f3c 100755 --- a/bin/git-purge-from-history +++ b/bin/git-purge-from-history @@ -21,6 +21,7 @@ if [[ ! -d .git ]]; then fi # remove all paths passed as arguments from the history of the repo +# shellcheck disable=SC2124 files=$@ git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD