Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
vr8ce committed Jun 19, 2020
1 parent 9dca93e commit 6ccd2fa
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions bin/git-undo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash

back="^"
cstr="commits"
ccnt=$(git rev-list --count HEAD)
if [ $ccnt -eq 1 ]; then cstr="commit"; fi
Expand All @@ -11,12 +10,12 @@ function _undo()
type=${1:-soft}
undo_cnt=${2:-1}
reset=${3:-""}
echo "type=$type, cnt=$undo_cnt, reset=$reset"

if [ $undo_cnt -gt $ccnt ]; then
echo "Only $ccnt $cstr, cannot undo $undo_cnt"
elif [ "$type" = "hard" -a $ccnt -eq $undo_cnt ]; then
elif [ "$type" = "hard" ] && [ $ccnt -eq $undo_cnt ]; then
echo "Cannot hard undo all commits"
elif [ "$type" = "soft" -a $ccnt -eq 1 ]; then
elif [ "$type" = "soft" ] && [ $ccnt -eq 1 ]; then
git update-ref -d HEAD
else
git reset --$type HEAD~$undo_cnt
Expand Down Expand Up @@ -65,7 +64,7 @@ EOL
;;
esac

if [[ ! $parm2 =~ [0-9]*([0-9]) ]]; then
if [[ ! $parm2 =~ [1-9]*([0-9]) ]]; then
echo "Invalid undo count: $parm2"
exit 1
fi
Expand Down

0 comments on commit 6ccd2fa

Please sign in to comment.