Skip to content

Commit

Permalink
Fixes for updater
Browse files Browse the repository at this point in the history
  • Loading branch information
markchalloner committed Jul 22, 2015
1 parent ad16b61 commit 0cb3cb2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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
Expand Down Expand Up @@ -47,7 +54,8 @@ 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.1...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
Expand Down
27 changes: 13 additions & 14 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 @@ -217,17 +221,12 @@ update() {
do_update="$(echo ${RETVAL} | tr '[:upper:]' '[:lower:]')"
if [ "${do_update}" == "y" ] || [ "${do_update}" == "yes" ]
then
(cd ${dir} && git checkout ${version} && ./install.sh)
status=$?
fi

if [ -n "$silent" ] && [ ${status} -eq 0 ]
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 @@ -310,7 +309,7 @@ changelog-check() {
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
43 changes: 16 additions & 27 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,23 @@ FILE_CONF_DEST="${DIR_DATA}/config"
# If MinGW
if [ ${OS_MINGW} -eq 0 ]
then
# Disown this subshell to allow this script to close and avoid permission denied errors
(
sleep 1
if [ -f "${FILE_DEST}" ]
then
rm "${FILE_DEST}"
fi
# Tabs are important for the heredoc
cat <<-EOF > "${FILE_DEST}"
#!/bin/bash
# Tabs are important for the heredoc
cat <<-EOF > "${FILE_DEST}"
#!/bin/bash
FILE_SRC="${FILE_SRC}"
FILE_PREFIX=""
if uname -s | grep -q 'MINGW[^_]\+_NT'
then
"\${FILE_SRC}" \$@
else
if uname -s | grep -q 'CYGWIN_NT'
then
FILE_PREFIX="/cygdrive"
fi
echo -e "Error: This file is a stub designed to run under MinGW, please reinstall \$(basename "\$0") by running:\n\n \${FILE_PREFIX}\$(dirname \${FILE_SRC})/install.sh"
fi
EOF

) &
disown
FILE_SRC="${FILE_SRC}"
FILE_PREFIX=""
if uname -s | grep -q 'MINGW[^_]\+_NT'
then
"\${FILE_SRC}" \$@
else
if uname -s | grep -q 'CYGWIN_NT'
then
FILE_PREFIX="/cygdrive"
fi
echo -e "Error: This file is a stub designed to run under MinGW, please reinstall \$(basename "\$0") by running:\n\n \${FILE_PREFIX}\$(dirname \${FILE_SRC})/install.sh"
fi
EOF
# Otherwise
else
if [ -L "${FILE_DEST}" ]
Expand Down

0 comments on commit 0cb3cb2

Please sign in to comment.