bonfire-app/git-publish.sh

57 lines
1.3 KiB
Bash
Raw Normal View History

2021-04-20 13:07:54 +00:00
#!/bin/bash
DIR="${1:-$PWD}"
2022-01-05 21:09:34 +00:00
function fail {
printf '%s\n' "$1" >&2 ## Send message to stderr.
exit "${2-1}" ## Return a code specified by $2, or 1 by default.
}
2021-04-20 13:07:54 +00:00
echo Checking for changes in $DIR
cd $DIR
2021-09-21 01:42:21 +00:00
git config core.fileMode false
2021-05-11 09:42:52 +00:00
# add all changes (including untracked files)
git add --all .
2021-04-30 11:21:25 +00:00
2021-04-20 13:07:54 +00:00
set +e # Grep succeeds with nonzero exit codes to show results.
2021-04-30 11:35:06 +00:00
2021-05-20 21:08:19 +00:00
if git status | grep -q -E 'Changes|modified|ahead'
2021-04-20 13:07:54 +00:00
then
set -e
2021-04-23 06:59:06 +00:00
2021-05-11 09:42:52 +00:00
# if there are changes, commit them (needed before being able to rebase)
2021-06-08 14:21:51 +00:00
git diff-index --quiet HEAD || git commit --verbose --all || echo Skipped...
2021-04-23 06:59:06 +00:00
2022-01-17 07:15:26 +00:00
# if [[ $2 == 'pull' ]]
# then
# git fetch
# fi
2021-04-23 06:59:06 +00:00
2022-01-05 21:09:34 +00:00
# merge/rebase local changes
2022-01-17 07:15:26 +00:00
# git rebase origin
git pull --rebase && echo "Publishing changes!" || fail "Please resolve conflicts before continuing."
if [[ $2 != 'pull' && $2 == 'maybe-pull' ]]
then
git push
fi
2021-04-23 06:59:06 +00:00
2021-04-20 13:07:54 +00:00
else
set -e
2021-04-23 06:59:06 +00:00
#echo No local changes since last run
2022-01-05 21:09:34 +00:00
if [[ $2 == 'pull' ]]
then
git pull --rebase || fail "Please resolve conflicts before continuing."
fi
if [[ $2 == 'maybe-pull' ]]
2021-06-08 14:11:02 +00:00
then
2022-01-05 21:09:34 +00:00
# if jungle is available and we assume fetches were already done
2022-01-17 07:15:26 +00:00
# command -v jungle ||
git pull --rebase || fail "Please resolve conflicts before continuing."
2021-06-08 14:11:02 +00:00
fi
2021-04-20 13:07:54 +00:00
fi