Skip to content

Instantly share code, notes, and snippets.

@rkaneko
Last active January 4, 2021 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkaneko/817ef030dcb710266fdce2da327e00ec to your computer and use it in GitHub Desktop.
Save rkaneko/817ef030dcb710266fdce2da327e00ec to your computer and use it in GitHub Desktop.

Usage

$ curl -X GET https://gist.githubusercontent.com/rkaneko/817ef030dcb710266fdce2da327e00ec/raw/98f03e0c71777a99613581ff95eca9ff1228fc65/
changelog_between_git_tags.sh -s | bash -s -- -p 1.0.0 -c 1.1.0
#!/bin/bash
PROGNAME=$(basename $0)
VERSION="1.0"
usage() {
echo "Usage: $PROGNAME [OPTIONS] FILE"
echo " This script is ~."
echo
echo "Options:"
echo " -h, --help"
echo " --version"
echo " -p, --prev-tag ARG"
echo " -c, --current-tag ARG"
echo
exit 1
}
get_tag_commit() {
local TAG=$1
# echo "tag: ${TAG}"
local SHORT_COMMIT_HASH=`git rev-parse --short $TAG`
echo $SHORT_COMMIT_HASH
}
show_commits_between_tags() {
local FROM_COMMIT=$1
local TO_COMMIT=$2
git log --oneline $FROM_COMMIT..$TO_COMMIT | grep -v "Merge branch"
}
for OPT in "$@"
do
case $OPT in
-h | --help)
usage
exit 1
;;
--version)
echo $VERSION
exit 1
;;
-p | --prev-tag)
if [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then
echo "$PROGNAME: option requires an argument -- $1" 1>&2
exit 1
fi
ARG_P=$2
shift 2
;;
-c | --current-tag)
if [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then
echo "$PROGNAME: option requires an argument -- $1" 1>&2
exit 1
fi
ARG_C=$2
shift 2
;;
-- | -)
shift 1
param+=( "$@" )
break
;;
-*)
echo "$PROGNAME: illegal option -- '$(echo $1 | sed 's/^-*//')'" 1>&2
exit 1
;;
*)
if [[ ! -z "$1" ]] && [[ ! "$1" =~ ^-+ ]]; then
#param=( ${param[@]} "$1" )
param+=( "$1" )
shift 1
fi
;;
esac
done
if [ -z "$ARG_P" ]; then
echo "$PROGNAME: Option prev-tag is necessary"
usage
exit 1
fi
if [ -z "$ARG_C" ]; then
echo "$PROGNAME: Option current-tag is necessary"
usage
exit 1
fi
PREV_TAG_COMMIT=`get_tag_commit $ARG_P`
CURRENT_TAG_COMMIT=`get_tag_commit $ARG_C`
show_commits_between_tags "$PREV_TAG_COMMIT" "$CURRENT_TAG_COMMIT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment