-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_current_and_merge.sh
49 lines (42 loc) · 1.46 KB
/
push_current_and_merge.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
# Specify your master branch name that you want to merge to your branch
mergeBranchName=$1
# The commit message
commitMess=$2
# Push current working dir to remote to make sure your branch is cleaned
git add .
git commit -am "$commitMess"
git push
# Wait for the github action to trigger
echo "Waiting for github action to trigger..."
sleep 3
# Get new code from master branch
git fetch origin $mergeBranchName:$mergeBranchName
git pull origin $mergeBranchName
# Merge and check if there is merge conflict
git merge --no-edit --no-ff $mergeBranchName
exitcode=$?
# Wait for the github action to trigger
echo "Waiting to merge $mergeBranchName to current branch..."
sleep 2
if [ $exitcode -eq 0 ]; then
git add .
git commit -am "Merge $mergeBranchName successfully without conflict, $commitMess"
echo "Merge $mergeBranchName successfully without conflict, $commitMess"
git push
else
# Promp for user input
echo "Merge conflicts, solved? If yes, type 'y' to continue or anything else to abort: "
while read input; do
# Check for user input if they already fixed conflicts
if [ "$input" == "y" ]; then
git add .
git commit -am"Merge branch $mergeBranchName after fixing conflict, $commitMess"
git push
echo "Merge branch $mergeBranchName after fixing conflict, $commitMess"
exit 0
fi
echo "Conflicts have not been resolved, abort"
git merge --abort
exit 1
done
fi