-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-publish
executable file
·51 lines (43 loc) · 1.15 KB
/
git-publish
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
#!/bin/sh
# Created by Michael Baltaks
# Don't allow using unset vars (-u)
set -o nounset
# Exit on error (-e)
#set -o errexit (not used here because if git pull fails we need to clean up)
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || branch_name="(unnamed branch)" # detached HEAD
branch_name="${branch_name##refs/heads/}"
if [ "${branch_name}" = "(unnamed branch)" ]
then
echo "This will not run if you're not on a normal branch."
exit 0
fi
# stop if there is already something stashed.
stash_list=`git stash list`
if [[ ${stash_list} == *stash* ]]
then
echo "There are already stashed changes, please empty your stash before using this script"
exit 0
fi
git stash && git checkout master && git pull
if [ 0 = $? ]
then
git rebase master "${branch_name}"
else
echo "git pull failed"
git checkout "${branch_name}" && git stash pop
fi
if [ 0 = $? ]
then
git checkout master && git merge "${branch_name}" && git push
else
echo "git rebase failed, you need to solve the conflicts"
exit 1;
fi
if [ 0 = $? ]
then
git rebase master "${branch_name}" && git stash pop
exit 0;
else
echo "git push failed"
git checkout "${branch_name}" && git stash pop
fi