From 75d0dbff6ddebb9da85b6f900b2040123466460a Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Thu, 2 Feb 2023 17:41:36 -0800 Subject: [PATCH] chore: Various Bash improvements (#1029) --- bin/git-archive-file | 4 ++-- bin/git-bulk | 4 ++-- bin/git-clear-soft | 4 ++-- bin/git-delete-submodule | 2 +- bin/git-feature | 8 ++++---- bin/git-fresh-branch | 10 +++++----- bin/git-graft | 10 +++++----- bin/git-guilt | 12 ++++++------ bin/git-ignore-io | 2 +- bin/git-info | 4 ++-- bin/git-local-commits | 2 +- bin/git-magic | 16 ++++++++-------- bin/git-psykorebase | 16 ++++++++-------- bin/git-rebase-patch | 20 ++++++++++---------- bin/git-rename-branch | 4 ++-- bin/git-rename-remote | 8 ++++---- bin/git-reset-file | 6 +++--- bin/git-scp | 28 ++++++++++++++-------------- bin/git-show-merged-branches | 2 +- bin/git-show-unmerged-branches | 2 +- bin/git-stamp | 6 +++--- bin/git-standup | 4 ++-- bin/git-summary | 2 +- bin/git-sync | 2 +- bin/git-undo | 12 ++++++------ 25 files changed, 95 insertions(+), 95 deletions(-) diff --git a/bin/git-archive-file b/bin/git-archive-file index bfe41fe..92c2338 100755 --- a/bin/git-archive-file +++ b/bin/git-archive-file @@ -5,7 +5,7 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) # get name of the most top folder of current directory, used for the # output filename -ARCHIVE_NAME=$(basename "$(pwd)") +ARCHIVE_NAME=$(basename "$PWD") if [[ $BRANCH = tags* ]]; then BRANCH=$(git describe) @@ -28,7 +28,7 @@ fi FILENAME=${FILENAME//\//-} FILENAME=${FILENAME//\\/-} # combine path and filename -OUTPUT=$(pwd)/$FILENAME +OUTPUT=$PWD/$FILENAME # building archive git archive --format zip --output "$OUTPUT" "$BRANCH" diff --git a/bin/git-bulk b/bin/git-bulk index f6899fc..0a1da3d 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -132,7 +132,7 @@ function executBulkOp () { parseWsName "$workspacespec" if [[ -n $wsname ]] && [[ $rwsname != "$wsname" ]]; then continue; fi eval cd "\"$rwsdir\"" - local actual=$(pwd) + local actual=$PWD [ "${quiet?}" != "true" ] && echo 1>&2 "Executing bulk operation in workspace ${inverse}$actual${reset}" allGitFolders=( $(eval find -L . -name ".git") ) @@ -140,7 +140,7 @@ function executBulkOp () { for line in ${allGitFolders[@]}; do local gitrepodir=${line::${#line}-5} # cut the .git part of find results to have the root git directory of that repository eval cd "\"$gitrepodir\"" # into git repo location - local curdir=$(pwd) + local curdir=$PWD local leadingpath=${curdir#${actual}} guardedExecution "$@" eval cd "\"$rwsdir\"" # back to origin location of last find command diff --git a/bin/git-clear-soft b/bin/git-clear-soft index 9813659..9cc70fa 100755 --- a/bin/git-clear-soft +++ b/bin/git-clear-soft @@ -1,7 +1,7 @@ #!/usr/bin/env bash echo -n "Sure? - This command may delete files that cannot be recovered. Files and directories in .gitignore will be preserved [y/N]: " -read ans -if [ "$ans" == "y" ] +read -r ans +if [ "$ans" == "y" ] then git clean -d -f && git reset --hard fi diff --git a/bin/git-delete-submodule b/bin/git-delete-submodule index c3ef38b..e5983e5 100755 --- a/bin/git-delete-submodule +++ b/bin/git-delete-submodule @@ -15,7 +15,7 @@ test ! -f '.gitmodules' && abort 2 '.gitmodules file not found' NAME="${1%/}" test -z "$(git config --file='.gitmodules' "submodule.$NAME.url")" \ - && abort 3 'Submodule not found' + && abort 3 'Submodule not found' # 1. Handle the .git directory # 1.a. Delete the relevant section from .git/config diff --git a/bin/git-feature b/bin/git-feature index 3a5e0ce..6b23e89 100755 --- a/bin/git-feature +++ b/bin/git-feature @@ -62,21 +62,21 @@ else if [[ -n $remote ]] && [[ -z $start_point ]] then - git create-branch -r $remote $branch + git create-branch -r "$remote" "$branch" fi if [[ -z $remote ]] && [[ -z $start_point ]] then - git create-branch $branch + git create-branch "$branch" fi if [[ -n $remote ]] && [[ -n $start_point ]] then - git create-branch -r $remote --from $start_point $branch + git create-branch -r "$remote" --from "$start_point" "$branch" fi if [[ -z $remote ]] && [[ -n $start_point ]] then - git create-branch --from $start_point $branch + git create-branch --from "$start_point" "$branch" fi fi diff --git a/bin/git-fresh-branch b/bin/git-fresh-branch index 461bd6c..e68362f 100755 --- a/bin/git-fresh-branch +++ b/bin/git-fresh-branch @@ -2,19 +2,19 @@ branch=$1 -test -z $branch && echo "branch required." 1>&2 && exit 1 +test -z "$branch" && echo "branch required." 1>&2 && exit 1 -changes=`git status --porcelain` +changes=$(git status --porcelain) clean() { - git symbolic-ref HEAD refs/heads/$branch + git symbolic-ref HEAD "refs/heads/$branch" rm .git/index git clean -fdx } -if [ ! -z "$changes" ]; then - read -p "All untracked changes will be lost. Continue [y/N]? " res +if [ -n "$changes" ]; then + read -rp "All untracked changes will be lost. Continue [y/N]? " res case $res in [Yy]* ) ;; * ) exit 0;; diff --git a/bin/git-graft b/bin/git-graft index 4e005ee..0309ef6 100755 --- a/bin/git-graft +++ b/bin/git-graft @@ -3,9 +3,9 @@ src=$1 dst=$2 -test -z $src && echo "source branch required." 1>&2 && exit 1 -test -z $dst && echo "destination branch required." 1>&2 && exit 1 +test -z "$src" && echo "source branch required." 1>&2 && exit 1 +test -z "$dst" && echo "destination branch required." 1>&2 && exit 1 -git checkout $dst \ - && git merge --no-ff $src \ - && git branch -d $src +git checkout "$dst" \ + && git merge --no-ff "$src" \ + && git branch -d "$src" diff --git a/bin/git-guilt b/bin/git-guilt index 4a394e7..e63f71a 100755 --- a/bin/git-guilt +++ b/bin/git-guilt @@ -1,6 +1,6 @@ #!/usr/bin/env bash -for param in $* +for param in "$@" do case $param in -h) @@ -44,11 +44,11 @@ for file in $(git diff --name-only "$@") do test -n "$DEBUG" && echo "git blame $file" # $1 - since $2 - until - git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null | - LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/- \1/' >> $MERGED_LOG + git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null | + LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/- \1/' >> "$MERGED_LOG" # if $2 not given, use current commit as "until" git blame $NOT_WHITESPACE --line-porcelain "${2-@}" -- "$file" 2> /dev/null | - LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/+ \1/' >> $MERGED_LOG + LC_ALL=C sed -n "$PATTERN" | sort | uniq -c | LC_ALL=C sed 's/^\(.\)/+ \1/' >> "$MERGED_LOG" done DEBUG="$DEBUG" awk ' @@ -71,8 +71,8 @@ END { printf("%d %s\n", contributors[people], people) } } -}' $MERGED_LOG | sort -nr | # only gawk supports built-in sort function -while read line +}' $MERGED_LOG | sort -nr | # only gawk supports built-in sort function +while read -r line do people=${line#* } num=${line%% *} diff --git a/bin/git-ignore-io b/bin/git-ignore-io index 53a930c..fa5e40c 100755 --- a/bin/git-ignore-io +++ b/bin/git-ignore-io @@ -17,7 +17,7 @@ print_in_alphabetical_order() { for ignorable in $(echo "$gi_list" | sort); do first_character=${ignorable:0:1} - if [[ $first_character = $previous_first_character ]]; then + if [[ $first_character = "$previous_first_character" ]]; then printf " %s" "$ignorable" elif [[ $first = true ]]; then previous_first_character=$first_character diff --git a/bin/git-info b/bin/git-info index d2ff844..f36f70a 100755 --- a/bin/git-info +++ b/bin/git-info @@ -65,7 +65,7 @@ echon "${COLOR_TITLE}## Local Branches:${NORMAL}" echon "$(local_branches)" SUBMODULES_LOG=$(submodules) -if [ ! -z "$SUBMODULES_LOG" ]; then +if [ -n "$SUBMODULES_LOG" ]; then echon "${COLOR_TITLE}## Submodule(s):${NORMAL}" echon "$SUBMODULES_LOG" fi @@ -73,7 +73,7 @@ fi echon "${COLOR_TITLE}## Most Recent Commit:${NORMAL}" echon "$(most_recent_commit)" -if [ ! -z "$HIDE_CONFIG" ]; then +if [ -n "$HIDE_CONFIG" ]; then echon "${COLOR_TITLE}## Configuration (.git/config):${NORMAL}" echon "$(get_config)" fi diff --git a/bin/git-local-commits b/bin/git-local-commits index eee5a2f..4f4c128 100755 --- a/bin/git-local-commits +++ b/bin/git-local-commits @@ -1,3 +1,3 @@ #!/usr/bin/env bash -git log @{upstream}..@ $* +git log "@{upstream}..@" "$@" diff --git a/bin/git-magic b/bin/git-magic index f020c74..8bc159a 100755 --- a/bin/git-magic +++ b/bin/git-magic @@ -33,7 +33,7 @@ while getopts "m:eapfh" arg; do FORCE='-f' ;; h) - echo $USAGE + echo "$USAGE" exit 0 ;; ?) @@ -46,7 +46,7 @@ done shift $((OPTIND-1)) if [[ $# != 0 ]]; then - echo "Unknown arguments: $@" + echo "Unknown arguments: $*" echo "${USAGE}" exit 1 fi @@ -54,19 +54,19 @@ fi set -- "${ARGS[@]}" # restore positional parameters if [[ $ALL == true ]]; then - + # Check if there is no changes to stage if [[ -z $(git status --porcelain) ]]; then echo "No changes to commit" exit 0 fi - + # Get confirmation from user git status echo "Everything will be added" - read -p "Press enter to continue" - - # Restore staging area so that, for example, + read -rp "Press enter to continue" + + # Restore staging area so that, for example, # add and modify will not be separate entries in status git restore --staged . || true git add . @@ -79,7 +79,7 @@ if [[ $PUSH == true ]]; then git push $FORCE fi -# --no-edit by default. use option -e to override this +# --no-edit by default. use option -e to override this # Arguments are passed with quoted "$@" to avoid misparsing diff --git a/bin/git-psykorebase b/bin/git-psykorebase index 50a7ef9..2194714 100755 --- a/bin/git-psykorebase +++ b/bin/git-psykorebase @@ -22,7 +22,7 @@ function usage() while [[ $# -gt 0 ]] do key="$1" - + case $key in --no-ff) FF="--no-ff" @@ -61,8 +61,8 @@ if [[ "$CONTINUE" == "yes" ]]; then echo "Continuing rebasing of $SECONDARY_BRANCH on top of $PRIMARY_BRANCH" git commit || exit 51 - git branch -d ${SECONDARY_BRANCH} || exit 52 - git branch -m ${TARGET_BRANCH} ${SECONDARY_BRANCH} || exit 53 + git branch -d "${SECONDARY_BRANCH}" || exit 52 + git branch -m "${TARGET_BRANCH}" "${SECONDARY_BRANCH}" || exit 53 elif [[ "$PRIMARY_BRANCH" == "" ]]; then usage @@ -71,14 +71,14 @@ else echo "Rebasing $SECONDARY_BRANCH on top of $PRIMARY_BRANCH" TARGET_BRANCH="${SECONDARY_BRANCH}-rebased-on-top-of-${PRIMARY_BRANCH}" - git checkout ${PRIMARY_BRANCH} || exit 41 - git checkout -b ${TARGET_BRANCH} || exit 42 - git merge ${SECONDARY_BRANCH} ${FF} \ + 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 - git branch -d ${SECONDARY_BRANCH} || exit 43 - git branch -m ${TARGET_BRANCH} ${SECONDARY_BRANCH} || exit 44 + git branch -d "${SECONDARY_BRANCH}" || exit 43 + git branch -m "${TARGET_BRANCH}" "${SECONDARY_BRANCH}" || exit 44 else echo "Resolve the conflict and run ``${PROGRAM} --continue``." exit 1 diff --git a/bin/git-rebase-patch b/bin/git-rebase-patch index 0835052..f5cf510 100755 --- a/bin/git-rebase-patch +++ b/bin/git-rebase-patch @@ -17,7 +17,7 @@ fi # Use a temporary index. index=$(git_extra_mktemp) cleanup() { - rm $index + rm "$index" exit 2 } trap cleanup 2 @@ -27,16 +27,16 @@ echo "Trying to find a commit the patch applies to..." rev=$(git rev-parse HEAD) while [ $? = 0 ] do - GIT_INDEX_FILE=$index git read-tree $rev + GIT_INDEX_FILE=$index git read-tree "$rev" # Try to apply the patch. - GIT_INDEX_FILE=$index git apply --cached $1 >/dev/null 2>&1 + GIT_INDEX_FILE=$index git apply --cached "$1" >/dev/null 2>&1 patch_failed=$? # Do it again, but show the error, if the problem is the patch itself. if [ $patch_failed = 128 ] then - GIT_INDEX_FILE=$index git apply --index --check $1 + GIT_INDEX_FILE=$index git apply --index --check "$1" exit $patch_failed fi @@ -45,19 +45,19 @@ do then # Manufacture a commit. tree=$(GIT_INDEX_FILE=$index git write-tree) - commit=$(git commit-tree $tree -p $rev -m "$1") - rm $index + commit=$(git commit-tree "$tree" -p "$rev" -m "$1") + rm "$index" - echo "Patch applied to $(git rev-parse --short $rev) as $(git rev-parse --short $commit)" + echo "Patch applied to $(git rev-parse --short "$rev") as $(git rev-parse --short "$commit")" - git cherry-pick $commit + git cherry-pick "$commit" exit $? fi - rev=$(git rev-parse --verify -q $rev^) + rev=$(git rev-parse --verify -q "$rev^") done # No compatible commit found. Restore. echo "Failed to find a commit the patch applies to." -rm $index +rm "$index" exit 1 diff --git a/bin/git-rename-branch b/bin/git-rename-branch index 93c8dbf..fded623 100755 --- a/bin/git-rename-branch +++ b/bin/git-rename-branch @@ -2,9 +2,9 @@ set -e # Assert there is at least one branch provided -test -z $1 && echo "new branch name required." 1>&2 && exit 1 +test -z "$1" && echo "new branch name required." 1>&2 && exit 1 -if [ -z $2 ]; then +if [ -z "$2" ]; then new_branch="$1" old_branch="$(git symbolic-ref --short -q HEAD)" else diff --git a/bin/git-rename-remote b/bin/git-rename-remote index c2629a6..999e7f6 100755 --- a/bin/git-rename-remote +++ b/bin/git-rename-remote @@ -5,8 +5,8 @@ set -euo pipefail old=$1 new=$2 -test -z $old && echo "old remote name required." 1>&2 && exit 1 -test -z $new && echo "new remote name required." 1>&2 && exit 1 +test -z "$old" && echo "old remote name required." 1>&2 && exit 1 +test -z "$new" && echo "new remote name required." 1>&2 && exit 1 if ! git config --get "remote.$old.fetch" > /dev/null; then echo "remote $old doesn't exist" @@ -14,7 +14,7 @@ if ! git config --get "remote.$old.fetch" > /dev/null; then fi if git config --get "remote.$new.fetch" > /dev/null; then - git remote remove $new + git remote remove "$new" fi -git remote rename $old $new +git remote rename "$old $new" git remote -v diff --git a/bin/git-reset-file b/bin/git-reset-file index a69e7c9..389ed2c 100755 --- a/bin/git-reset-file +++ b/bin/git-reset-file @@ -5,13 +5,13 @@ commit="$2" if [[ -f $file ]]; then git rm --cached -q -f -- "$file" - if [[ -z $commit ]]; then + if [[ -z $commit ]]; then git checkout HEAD -- "$file" echo "Reset '$1' to HEAD" else git checkout "$commit" -- "$file" echo "Reset '$1' to $commit" fi -else - echo "File '$1' not found in $(pwd)" +else + echo "File '$1' not found in $PWD" fi diff --git a/bin/git-scp b/bin/git-scp index 0c410a0..668b82d 100755 --- a/bin/git-scp +++ b/bin/git-scp @@ -64,7 +64,7 @@ function _dos2unix() function _sanitize() { - git config --get-all extras.scp.sanitize | while read i + git config --get-all extras.scp.sanitize | while read -r i do case $i in php_lint) php_lint $@;; # git config --global --add extras.scp.sanitize php_lint @@ -76,10 +76,10 @@ function _sanitize() function scp_and_stage { - set_remote $1 + set_remote "$1" shift - local refhead="$(git rev-parse --quiet --verify $1)" + local refhead="$(git rev-parse --quiet --verify "$1")" if [ -n "$refhead" ] then shift @@ -92,8 +92,8 @@ function scp_and_stage list=$(git ls-files "$@")" "$(git ls-files -o "$@") elif [ -n "$refhead" ] then - git diff --stat $refhead - list=$(git diff $refhead --name-only) + git diff --stat "$refhead" + list=$(git diff "$refhead" --name-only) else git diff list=$(git diff --name-only) @@ -105,12 +105,12 @@ function scp_and_stage if [ -n "$list" ] then local _TMP=${0///} - echo "$list" > $_TMP && + echo "$list" > "$_TMP" && _sanitize $list && - _info Pushing to $remote \($(git config remote.$remote.url)\) && - rsync -rlDv --files-from=$_TMP ./ "$(git config remote.$remote.url)/" && + _info "Pushing to $remote ($(git config "remote.$remote.url"))" && + rsync -rlDv --files-from="$_TMP" ./ "$(git config "remote.$remote.url")/" && git add --force $list && - rm $_TMP + rm "$_TMP" fi deleted=$(for i in $deleted; do echo $(git config remote.$remote.url | cut -d: -f2)/$i; done) @@ -125,13 +125,13 @@ function scp_and_stage function reverse_scp() { - set_remote $1 + set_remote "$1" shift local _TMP=${0///} - echo $@ > $_TMP && - rsync -rlDv --files-from=$_TMP "$(git config remote.$remote.url)/" ./ && - rm $_TMP + echo $@ > "$_TMP" && + rsync -rlDv --files-from="$_TMP" "$(git config "remote.$remote.url")/" ./ && + rm "$_TMP" } function _info() @@ -151,7 +151,7 @@ function _usage() " case $1 in - -v|verbose|--verbose) grep -A100 '^#* OPTIONS #*$' $0;; + -v|verbose|--verbose) grep -A100 '^#* OPTIONS #*$' "$0" ;; esac exit } diff --git a/bin/git-show-merged-branches b/bin/git-show-merged-branches index 6d60ca5..6b18c78 100755 --- a/bin/git-show-merged-branches +++ b/bin/git-show-merged-branches @@ -1,3 +1,3 @@ #!/usr/bin/env bash -git branch --no-color --merged | grep -v "\*" | grep -v $(git_extra_default_branch) | tr -d ' ' +git branch --no-color --merged | grep -v "\*" | grep -v "$(git_extra_default_branch)" | tr -d ' ' diff --git a/bin/git-show-unmerged-branches b/bin/git-show-unmerged-branches index c882a5b..5c4e1ec 100755 --- a/bin/git-show-unmerged-branches +++ b/bin/git-show-unmerged-branches @@ -1,3 +1,3 @@ #!/usr/bin/env bash -git branch --no-color --no-merged | grep -v "\*" | grep -v $(git_extra_default_branch) | tr -d ' ' +git branch --no-color --no-merged | grep -v "\*" | grep -v "$(git_extra_default_branch)" | tr -d ' ' diff --git a/bin/git-stamp b/bin/git-stamp index baac260..12c8a00 100755 --- a/bin/git-stamp +++ b/bin/git-stamp @@ -33,7 +33,7 @@ stamp() { local commit_msg=$( git log -1 --pretty=%B ) local stamp_msg [[ -n "${MSG}" ]] && stamp_msg="${ID} ${MSG}" || stamp_msg="${ID}" - + if ${REPLACE}; then # remove previous stamps with same ID from the commit message commit_msg=$( @@ -70,9 +70,9 @@ parse_options() { ;; esac done - + ID="$1" - MSG="${@:2}" + MSG="${*:2}" } diff --git a/bin/git-standup b/bin/git-standup index d34a0f0..871c74d 100755 --- a/bin/git-standup +++ b/bin/git-standup @@ -269,7 +269,7 @@ if [[ $in_git_repo != 0 ]]; then if [[ -d ".git" || -f ".git" ]] ; then if GITOUT=$(git_output); then ## Only output if there is some activities - if [[ ! -z "$GITOUT" ]] ; then + if [[ -n "$GITOUT" ]] ; then echo "${BOLD}${UNDERLINE}${YELLOW}$(basename "$DIR")${NORMAL}" echo "$GITOUT" echo "" @@ -287,7 +287,7 @@ else fi if GITOUT=$(git_output); then - if [[ ! -z "$GITOUT" ]] ; then + if [[ -n "$GITOUT" ]] ; then echo "$GITOUT" else if [[ $AUTHOR = '.*' ]] ; then diff --git a/bin/git-summary b/bin/git-summary index 86b0109..27cc2f5 100755 --- a/bin/git-summary +++ b/bin/git-summary @@ -199,7 +199,7 @@ elif [ -n "$SUMMARY_BY_LINE" ]; then echo " authors :" lines "${paths[@]}" | sort | uniq -c | sort -rn | format_authors elif [ -n "$SUMMARY_ONELINE" ]; then - echo "$project / age: $(repository_age) / last active: $(last_active) / active on $(active_days $commit) days / commits: $(commit_count $commit) / uncommitted: $(uncommitted_changes_count)" + echo "$project / age: $(repository_age) / last active: $(last_active) / active on $(active_days "$commit") days / commits: $(commit_count "$commit") / uncommitted: $(uncommitted_changes_count)" else echo echo " project : $project" diff --git a/bin/git-sync b/bin/git-sync index ca2bdc2..a4b85a6 100755 --- a/bin/git-sync +++ b/bin/git-sync @@ -60,7 +60,7 @@ function main() local remote_branch if [ -z "${remote}" ]; then - if ! remote_branch="$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null)"; then + if ! remote_branch="$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null)"; then echo "There is no upstream information of local branch." exit 1 fi diff --git a/bin/git-undo b/bin/git-undo index bd561a8..47f8d49 100755 --- a/bin/git-undo +++ b/bin/git-undo @@ -2,7 +2,7 @@ cstr="commits" ccnt=$(git rev-list --count HEAD) -if [ $ccnt -eq 1 ]; then cstr="commit"; fi +if [ "$ccnt" -eq 1 ]; then cstr="commit"; fi parm3="" function _undo() @@ -11,14 +11,14 @@ function _undo() undo_cnt=${2:-1} reset=${3:-""} - if [ $undo_cnt -gt $ccnt ]; then + if [ "$undo_cnt" -gt "$ccnt" ]; then echo "Only $ccnt $cstr, cannot undo $undo_cnt" - elif [ "$type" = "hard" ] && [ $ccnt -eq $undo_cnt ]; then + elif [ "$type" = "hard" ] && [ "$ccnt" -eq "$undo_cnt" ]; then echo "Cannot hard undo all commits" - elif [ "$type" = "soft" ] && [ $ccnt -eq 1 ]; then + elif [ "$type" = "soft" ] && [ "$ccnt" -eq 1 ]; then git update-ref -d HEAD else - git reset --$type HEAD~$undo_cnt + git reset "--$type" "HEAD~$undo_cnt" fi if [ "$reset" != "" ]; then git reset; fi } @@ -69,4 +69,4 @@ if [[ ! $parm2 =~ ^[1-9][0-9]*$ ]]; then exit 1 fi -_undo $parm1 $parm2 $parm3 \ No newline at end of file +_undo $parm1 $parm2 $parm3