From 81b60c133aaadee4564dc7d6190348fe350489cb Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 11 Apr 2018 23:28:36 +0200 Subject: [PATCH] [git] shellcheck, minor changes --- git/git-changelog | 8 ++++---- git/git-cherry-move | 17 ++++++++++------- git/git-merge-ff-only | 15 +++++++++++---- git/git-tag-update | 15 ++++++++++----- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/git/git-changelog b/git/git-changelog index 41cca6c..d5ff07b 100755 --- a/git/git-changelog +++ b/git/git-changelog @@ -43,21 +43,21 @@ if [ "$HEADER" != "" ] ; then fi for TAG in $(git tag -l | sort -r) ; do - if echo $TAG | egrep '^v[0-9]+(\.[0-9]+)+$' >/dev/null ; then + if echo "$TAG" | grep -Eq '^v[0-9]+(\.[0-9]+)+$' ; then # Display current tag's name - echo $TAG >&2 + echo "$TAG" >&2 # Print empty lines if needed if [ $PRINTNL -eq 1 ] ; then i=0 while [ $i -lt $NEWLINES ] ; do echo - i=`expr $i + 1` + i=$((i + 1)) done fi # Print the tag message - git tag -l $TAG -n$NBLINES | sed 's/ \+$//' + git tag -l "$TAG" -n$NBLINES | sed 's/ \+$//' PRINTNL=1 else diff --git a/git/git-cherry-move b/git/git-cherry-move index 11dc3fd..b65a2aa 100755 --- a/git/git-cherry-move +++ b/git/git-cherry-move @@ -11,9 +11,16 @@ # This script moves a commit from a branch head to another. It is # the equivalent of git cherry-pick followed by git reset. - set -e +USAGE=$(cat < [ reset-arg ] + +'reset-arg' is passed to the final reset (can be --hard for example). +EOF +) + assert_branch_exists() { if ! git for-each-ref refs/heads | grep "/${1}$" >/dev/null ; then @@ -23,14 +30,10 @@ assert_branch_exists() } if [ $# -lt 2 ] ; then - echo "Usage:" - echo " $0 [ reset-arg ]" - echo -n "'reset-arg' is passed to the final reset" - echo " (can be --hard for example)." + printf '%s\n' "$USAGE" >&2 exit 1 fi - assert_branch_exists "$1" SRC="$1" shift @@ -43,4 +46,4 @@ shift git checkout "$DST" git cherry-pick "$SRC" git checkout "$SRC" -git reset $1 HEAD^ +git reset "$1" HEAD^ diff --git a/git/git-merge-ff-only b/git/git-merge-ff-only index 55fe8da..0e462d5 100755 --- a/git/git-merge-ff-only +++ b/git/git-merge-ff-only @@ -16,9 +16,16 @@ set -e +USAGE=$(cat < " + + will be fast-forwarded to if possible." +EOF +) + if [ $# -ne 2 ] ; then - echo "Usage: $0 " - echo " will be fast-forwarded to if possible." + printf '%s\n' "$USAGE" >&2 exit 1 fi @@ -29,10 +36,10 @@ echo "Trying to merge $TOPIC_BRANCH into $MAIN_BRANCH..." DIFF="$(git rev-list "$TOPIC_BRANCH".."$MAIN_BRANCH")" if [ -z "$DIFF" ] ; then - echo "$TOPIC_BRANCH contains all the commits of $MAIN_BRANCH." + echo -- "$TOPIC_BRANCH contains all the commits of $MAIN_BRANCH." echo "Fast-forwarding $MAIN_BRANCH to $TOPIC_BRANCH." git branch -f "$MAIN_BRANCH" "$TOPIC_BRANCH" else - echo "$TOPIC_BRANCH does not contain all the commits of $MAIN_BRANCH." + echo -- "$TOPIC_BRANCH does not contain all the commits of $MAIN_BRANCH." echo "Fast-forward impossible, aborting." fi diff --git a/git/git-tag-update b/git/git-tag-update index 838b16a..b8259f3 100755 --- a/git/git-tag-update +++ b/git/git-tag-update @@ -17,16 +17,21 @@ set -e #set -x if [ $# -ne 1 ] ; then - echo "Usage: $0 " + echo "Usage: $0 " >&2 exit 1 fi -TAG=$1 +commiter_date() +{ + git tag -v "$TAG" 2>/dev/null | grep ^tagger | cut -f5- -d' ' +} -GIT_COMMITTER_DATE="$(git tag -v $TAG 2>/dev/null|grep ^tagger | cut -f5- -d' ')" +TAG="$1" + +GIT_COMMITTER_DATE="$(commiter_date)" export GIT_COMMITTER_DATE -git tag -sf $TAG $TAG +git tag -sf "$TAG" "$TAG" echo "Old tag commiter date: $GIT_COMMITTER_DATE" -GIT_COMMITTER_DATE="$(git tag -v $TAG 2>/dev/null|grep ^tagger | cut -f5- -d' ')" +GIT_COMMITTER_DATE="$(commiter_date)" echo "New tag commiter date: $GIT_COMMITTER_DATE"