Skip to content

Commit a2eb2b7

Browse files
committed
Modernize git-move-commits
* Replace `` with $() * Put bare variables in "" * Disable bad shellcheck warnings
1 parent f601f0f commit a2eb2b7

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

bin/git-move-commits

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,45 @@
88
# if correct-branch does exist, it merges the commits
99
set -e
1010

11-
if [ $1 ]
11+
if [ "$1" ]
1212
then
13+
# shellcheck disable=SC2046,SC2143
1314
if [ ! $(echo "$1" | grep -E "^[0-9]+$") ]
1415
then
1516
echo "$1 is not a number."
1617
echo "Usage: git move-commits <num-commits> <correct-branch>";
1718
exit 1;
1819
else
1920
# The count is 0 based, so to move the last 1 commit, we need HEAD~0
20-
NUM_COMMITS=$1
21+
NUM_COMMITS="$1"
2122
((NUM_COMMITS--))
2223
echo "num commits $NUM_COMMITS"
2324
fi
2425
else
2526
echo "Usage: git move-commits <num-commits> <correct-branch>";
2627
exit 1;
2728
fi
28-
if [ -z $2 ]
29+
if [ -z "$2" ]
2930
then
3031
echo "Usage: git move-commits <num-commits> <correct-branch>";
3132
exit 1;
3233
else
33-
BRANCH=$2
34+
BRANCH="$2"
3435
fi
3536

36-
CURRENT_BRANCH=`git branch | grep '*' | perl -e '<STDIN> =~ /^..(.+)$/;print $1'`
37+
# shellcheck disable=SC2063
38+
CURRENT_BRANCH=$(git branch | grep '*' | perl -e '<STDIN> =~ /^..(.+)$/;print $1')
3739

3840
# If the branch already exists, we have to merge it with the current branch
39-
if ! [ -z `git branch -a | grep $BRANCH` ]
41+
# shellcheck disable=SC2143,SC2046
42+
if ! [ -z $(git branch -a | grep "$BRANCH") ]
4043
then
4144
echo "$BRANCH already exists. Switching to it and merging $CURRENT_BRANCH"
42-
git checkout $BRANCH
43-
git merge $CURRENT_BRANCH
45+
git checkout "$BRANCH"
46+
git merge "$CURRENT_BRANCH"
4447
else
4548
echo "Creating $BRANCH"
46-
git branch $BRANCH
49+
git branch "$BRANCH"
4750
fi
48-
git reset --hard $CURRENT_BRANCH~$NUM_COMMITS
49-
git checkout $BRANCH
51+
git reset --hard "$CURRENT_BRANCH~$NUM_COMMITS"
52+
git checkout "$BRANCH"

0 commit comments

Comments
 (0)