Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
markchalloner committed Jul 22, 2015
2 parents 2844399 + 0cb3cb2 commit 9ec7b81
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ This file uses change log convention from [Keep a CHANGELOG](http://keepachangel

## [Unreleased][unreleased]

## [1.1.2] - 2015-07-22
### Fixed
- Moved disown to git-semver.sh
- Pull down tags on update check
- Optimise get version in setting
- Check if commit is on a branch befire outputting help on amending commits

## [1.1.1] - 2015-07-22
### Fixed
- Update now runs installer
- Workaround when writing stub to avoid permission errors

## [1.1.0] - 2015-07-07
### Added
- Update checks
Expand Down Expand Up @@ -42,7 +54,9 @@ This file uses change log convention from [Keep a CHANGELOG](http://keepachangel
[LICENCE.md]: LICENCE.md
[README.md]: README.md

[unreleased]: https://github.com/markchalloner/git-semver/compare/1.1.0...HEAD
[unreleased]: https://github.com/markchalloner/git-semver/compare/1.1.2...HEAD
[1.1.2]: https://github.com/markchalloner/git-semver/compare/1.1.1...1.1.2
[1.1.1]: https://github.com/markchalloner/git-semver/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/markchalloner/git-semver/compare/1.0.2...1.1.0
[1.0.2]: https://github.com/markchalloner/git-semver/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/markchalloner/git-semver/compare/1.0.0...1.0.1
40 changes: 23 additions & 17 deletions git-semver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

usage() {
cat <<-EOF
Usage: $(basename $0 | tr '-' ' ' | sed 's/.sh$//g') [command]
Usage: $(basename-git "$0") [command]
This script automates semantic versioning. Requires a valid change log at CHANGELOG.md.
Expand Down Expand Up @@ -121,6 +121,10 @@ resolve-path() {
echo "$path"
}

function basename-git() {
echo $(basename "$1" | tr '-' ' ' | sed 's/.sh$//g')
}

########################################
# Update functions
########################################
Expand All @@ -134,7 +138,7 @@ update-check() {
local dir="$1"
if [ -d "${dir}/.git" ]
then
(cd ${dir} && git fetch)
(cd ${dir} && git fetch && git fetch --tags) > /dev/null 2>&1
local version=$(git tag | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1)
if update-force-enabled || [ $(git rev-list --left-right HEAD...${version} | grep "^>" | wc -l | sed 's/ //g') -gt 0 ]
then
Expand All @@ -155,8 +159,8 @@ update-silent() {
update() {
silent=$1
local status=1

local date_curr=$(date "+%Y-%m-%d")

mkdir -p ${DIR_DATA}
echo ${date_curr} > "${FILE_UPDATE}"

Expand Down Expand Up @@ -213,21 +217,16 @@ update() {
return 0
fi

get_input "New version ${version} found. Upgrade (y/n)?" "y"
do_upgrade="${RETVAL}"
if [ "${do_upgrade}" == "y" ]
then
(cd ${dir} && git checkout ${version})
status=$?
fi

if [ -n "$silent" ] && [ ${status} -eq 0 ]
get_input "New version ${version} found. Update (y/n)?" "y"
do_update="$(echo ${RETVAL} | tr '[:upper:]' '[:lower:]')"
if [ "${do_update}" == "y" ] || [ "${do_update}" == "yes" ]
then
"$0" ${ARGS} ${ARG_NOUPDATE}
echo -e "Updating. Rerun your command with this new version:\n\n$(basename-git $0) ${ARGS}"
# Disown this subshell to allow this script to close and avoid permission denied errors due to file locking
( sleep 1 && cd ${dir} && git checkout ${version} && ./install.sh ) &
disown
exit
fi

return ${status}
}

########################################
Expand Down Expand Up @@ -255,7 +254,7 @@ changelog-check() {
local tag_grep="\[${tag}\]"
local tag_actual="[${tag}]"
local tag_prev=
if [ "" == "$($0 get)" ]
if [ "" == "$(version-get)" ]
then
require_link=0
tag_grep="${tag}"
Expand Down Expand Up @@ -309,7 +308,7 @@ changelog-check() {
echo -e "Error: no changelog ${links} for ${update_links_descs}. Please add the ${update_links_descs} ${links} at the bottom of the changelog: \n\n${update_links_lines}\n"
status=1
fi
if [ ${status} -eq 1 ] && [ $(git rev-list --left-right @{u}... | grep "^>" | wc -l | sed 's/ //g') -gt 0 ]
if [ ${status} -eq 1 ] && git rev-list @{u}... > /dev/null 2>&1 && [ $(git rev-list --left-right @{u}... | grep "^>" | wc -l | sed 's/ //g') -gt 0 ]
then
echo -e "After making these changes, you can add your change log to your latest unpublished commit by running:\n\ngit add ${changelog}\ngit commit --amend -m '$(git log -1 --pretty=%B)'\n"
fi
Expand Down Expand Up @@ -491,20 +490,27 @@ for ARG_LAST; do true; done

case "$1" in
get)
update-silent ${ARG_LAST}
version-get
;;
major)
update-silent ${ARG_LAST}
version-major
;;
minor)
update-silent ${ARG_LAST}
version-minor
;;
patch|next)
update-silent ${ARG_LAST}
version-patch
;;
debug)
plugin-run
;;
update)
update
;;
help)
usage
;;
Expand Down
13 changes: 5 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@ FILE_DEST="${DIR_BIN}/git-semver"
FILE_CONF_SRC="${DIR_SELF}/config.example"
FILE_CONF_DEST="${DIR_DATA}/config"

# Windows MinGW uses a stub
if [ -L "${FILE_DEST}" ] || ( [ ${OS_MINGW} -eq 0 ] && [ -f "${FILE_DEST}" ] )
then
rm "${FILE_DEST}"
fi


# If MinGW
if [ ${OS_MINGW} -eq 0 ]
then
# Create a stub (tabs are important here)
# Create a stub, tabs are important for the heredoc
cat <<-EOF > "${FILE_DEST}"
#!/bin/bash
Expand All @@ -55,6 +48,10 @@ then
EOF
# Otherwise
else
if [ -L "${FILE_DEST}" ]
then
rm "${FILE_DEST}"
fi
# Symlink
ln -s "${FILE_SRC}" "${FILE_DEST}"
fi
Expand Down

0 comments on commit 9ec7b81

Please sign in to comment.