2021-04-20 13:07:54 +00:00
|
|
|
#!/bin/bash
|
|
|
|
DIR="${1:-$PWD}"
|
|
|
|
|
2024-02-24 19:13:02 +00:00
|
|
|
function maybe_rebase {
|
2023-07-18 08:41:53 +00:00
|
|
|
if [[ $1 == 'pull' ]]
|
2023-07-18 08:31:52 +00:00
|
|
|
then
|
|
|
|
git pull --rebase || fail "Please resolve conflicts before continuing."
|
|
|
|
fi
|
|
|
|
|
2023-07-18 08:41:53 +00:00
|
|
|
if [[ $1 == 'rebase' ]]
|
2023-07-18 08:31:52 +00:00
|
|
|
then
|
|
|
|
rebase
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-07-29 00:47:21 +00:00
|
|
|
function rebase {
|
|
|
|
# if jungle is available and we can assume fetches were already done by just and so we rebase, otherwise we rebase pull
|
|
|
|
command -v jungle && git rebase || git pull --rebase || fail "Please resolve conflicts before continuing."
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
2023-07-18 08:31:52 +00:00
|
|
|
|
2023-07-18 08:40:26 +00:00
|
|
|
echo "Checking ($2) for changes in $DIR"
|
2021-04-20 13:07:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-07-26 08:18:29 +00:00
|
|
|
if LC_ALL=en_GB 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
|
2024-02-24 19:13:02 +00:00
|
|
|
maybe_rebase $2
|
2022-01-17 07:15:26 +00:00
|
|
|
|
2022-01-17 09:27:11 +00:00
|
|
|
if [[ $3 != 'only' ]]
|
2022-01-17 07:15:26 +00:00
|
|
|
then
|
2023-07-18 08:31:52 +00:00
|
|
|
git push && echo "Published changes!"
|
2022-01-17 07:15:26 +00:00
|
|
|
fi
|
2021-04-23 06:59:06 +00:00
|
|
|
|
2021-04-20 13:07:54 +00:00
|
|
|
else
|
|
|
|
set -e
|
2022-07-29 00:47:21 +00:00
|
|
|
echo "No local changes to push"
|
2022-01-05 21:09:34 +00:00
|
|
|
|
2024-02-24 19:13:02 +00:00
|
|
|
maybe_rebase $2
|
2021-04-20 13:07:54 +00:00
|
|
|
fi
|