forked from bonfire-networks/bonfire-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-publish.sh
executable file
·58 lines (43 loc) · 1.29 KB
/
git-publish.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
DIR="${1:-$PWD}"
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."
}
function fail {
printf '%s\n' "$1" >&2 ## Send message to stderr.
exit "${2-1}" ## Return a code specified by $2, or 1 by default.
}
echo "Checking for changes in $DIR"
cd $DIR
git config core.fileMode false
# add all changes (including untracked files)
git add --all .
set +e # Grep succeeds with nonzero exit codes to show results.
if LC_ALL=en_GB git status | grep -q -E 'Changes|modified|ahead'
then
set -e
# if there are changes, commit them (needed before being able to rebase)
git diff-index --quiet HEAD || git commit --verbose --all || echo Skipped...
# if [[ $2 == 'pull' ]]
# then
# git fetch
# fi
# merge/rebase local changes
rebase && echo "Published changes!"
if [[ $3 != 'only' ]]
then
git push
fi
else
set -e
echo "No local changes to push"
if [[ $2 == 'pull' ]]
then
git pull --rebase || fail "Please resolve conflicts before continuing."
fi
if [[ $2 == 'rebase' ]]
then
rebase
fi
fi