Skip to content

Commit

Permalink
add auto-detect of checked out branch
Browse files Browse the repository at this point in the history
  • Loading branch information
joe128 committed Jan 5, 2022
1 parent b3dde4d commit 06f945b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [3.0.0] - 2022-01-05
### Added
- auto-detect of checked out branch
### Deleted
- AUTOUPDATE_BRANCH

## [2.0.0] - 2021-11-25
### Changed
- change ``disableAutoUpdate`` to ``.autoUpdateDisable``
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ template to auto-update a project over bash-script
* set AUTOUPDATE_DISABLE or add file ``.autoUpdateDisable`` to disable auto-update
* set AUTOUPDATE_NO_LOCAL_RESET or add file ``.autoUpdateDisableHardReset`` to skip a local git-hard-reset
* set AUTOUPDATE_CHECK_EVERY_TIME or add file ``.autoUpdateCheckEveryTime`` to check updates every call (default once per day)
* set AUTOUPDATE_BRANCH to use a different branch (default: main)
* set AUTOUPDATE_GIT_BIN if there is a problem detecting git-binary
6 changes: 4 additions & 2 deletions anyScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ fi
# run auto-update daily, not if file disableAutoUpdate exists or env AUTOUPDATE_DISABLE is set
if [ -n "${gitbin}" ] && [ ! -f "$(dirname "$0")/.autoUpdateDisable" ] && [ -z "$AUTOUPDATE_DISABLE" ] && [ -d "$(dirname "$0")/.git" ]; then
[ -z "${AUTOUPDATE_NO_LOCAL_RESET}" ] && [ ! -f "$(dirname "$0")/.autoUpdateDisableHardReset" ] && doHardReset=1 || doHardReset=0
gitBranch=${AUTOUPDATE_BRANCH:=main}
scriptName=$(basename "$0")
today=$(date +'%Y-%m-%d')
autoUpdateStatusFile="/tmp/.${scriptName}-autoUpdate"
Expand All @@ -27,7 +26,10 @@ if [ -n "${gitbin}" ] && [ ! -f "$(dirname "$0")/.autoUpdateDisable" ] && [ -z "
touch "$autoUpdateStatusFile"
cd "$(dirname "$0")" || exit 1
$gitbin fetch
commits=$(git rev-list HEAD...origin/"$gitBranch" --count)
gitBranch=$(${gitbin} rev-parse --abbrev-ref HEAD)
gitBranch=${gitBranch:=main}
origin=$(git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)")
[ -n "$origin" ] && commits=$(git rev-list HEAD...origin/"$gitBranch" --count) || commits=0
if [ $commits -gt 0 ]; then
echo "[autoUpdate] Found updates ($commits commits)..."
[ $doHardReset -gt 0 ] && $gitbin reset --hard
Expand Down

0 comments on commit 06f945b

Please sign in to comment.