-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpush
executable file
·134 lines (109 loc) · 3.89 KB
/
push
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
## Once LGTM has been attained in CR, this script pushes to
## GitHub and provides easy clickable steps to the remaining
## non-automatable tasks. Must be called within the Git repo
## you wish to push. Supports force-pushing if requested.
############################################################
## YOUR VALUES ##
#################
## Your github username:
GITUSER=your_git_user
## Your docs workspace (i.e. where to git clone to)
## If you use a ~ in the path, don't quote the value:
WORKSPACE=~/doc_workspace
## Directory to store workflow-specific status:
WORKFLOW_STATUS_DIR=$WORKSPACE/workflow
############################################################
## BEGIN SCRIPT ##
##################
TMPFILE=/tmp/push$$.tmp
FORCE=""
## Check for FORCE override: for force pushing if you know
## what you're doing:
while getopts ":f" opt; do
case ${opt} in
f )
FORCE=1
;;
\? )
echo -e "\nERROR: Invalid option: $OPTARG" 1>&2
echo " push only supports the optional -f flag"
echo -e " for force pushing\n"
exit
;;
esac
done
# Must be in a git repo:
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ `echo $BRANCH | grep -c '^fatal: not a git repository'` -gt 0 ]; then
echo -e "\nERROR: Not in a git repo!"
echo -e " Aborting...\n"
exit;
fi
## Get exiting GIT_EDITOR, to restore later:
OLD_GIT_EDITOR=`echo $GIT_EDITOR`
## Set custom giteditor_autoamend as GIT_EDITOR:
export GIT_EDITOR=giteditor_autoamend
# Show user current status, before taking any action:
git status
## Have we committed yet on this branch?
COMMITTED_YET=`git status -uno | grep upstream`
## If this is our first commit, prompt for a commit message,
## otherwise silently amend the existing commit:
if [ `echo $COMMITTED_YET | grep -c 'up to date'` -gt 0 ]; then
echo -e "\nINPUT REQUIRED: You have not committed anything yet!"
read -p ' COMMIT MESSAGE: ' COMMIT_MESSAGE
git add .
git commit -m "$COMMIT_MESSAGE"
elif [ `echo $COMMITTED_YET | grep -c 'is ahead of'` -gt 0 ]; then
git add .
git commit --amend
else
echo -e "\nERROR: Unable to determine git commit status!"
echo -e " You must manually commit or otherwise correct"
echo -e " the situation!"
echo -e " Aborting...\n"
exit;
fi
# Collect info:
CR_ID=`grep CR_ID $WORKFLOW_STATUS_DIR/$BRANCH 2>/dev/null | cut -d"=" -f2`
JIRA=`echo $BRANCH | awk -F\- '{print $1"-"$2}'`
# Rebase
git pull --rebase 2>&1 | tee $TMPFILE
# If conflicts are detected, present them and exit,
# if no conflicts, push the changes:
if [ `grep -ic 'Merge conflict' $TMPFILE` -gt 0 ]; then
CONFLICTING_FILES=`grep 'Merge conflict' $TMPFILE | awk -F'in ' '{print $2}'`
echo -e "\nERROR: Merge conflicts detected in rebase! You can:\n"
echo -e " - Manually resolve them and then:"
echo -e " git add ."
echo -e " git rebase --continue"
echo -e " push"
echo -e " - Or cancel this operation with"
echo -e " git rebase --abort\n"
echo -e "CONFLICTING FILES:\n"
echo $CONFLICTING_FILES
echo ""
rm -f $TMPFILE
exit;
elif [ ! $FORCE ]; then
git push origin $BRANCH
else
git push -f origin $BRANCH
fi
# Provide links (clickable in VS Code and iTerm2):
echo -e "\n############################## PUBLISH READY! ##############################"
GITHUB_URL="https://github.com/$GITUSER/docs/pull/new/$BRANCH"
echo -e "\n 1. PULL REQUEST: $GITHUB_URL"
if [ `echo $BRANCH | egrep -c '(^DOCS-|^DOCSP-)'` -gt 0 ]; then
JIRA_URL="https://jira.mongodb.org/browse/$JIRA"
echo -e "\n 2. CLOSE TICKET: $JIRA_URL"
fi
if [ ! -z $CR_ID ]; then
CR_URL=https://mongodbcr.appspot.com/$CR_ID
echo -e "\n 3. CLOSE THE CR: $CR_URL"
fi
echo -e "\n##############################################################################\n"
# Replace GIT_EDITOR with original value:
GIT_EDITOR=`echo $OLD_GIT_EDITOR`
rm -f $TMPFILE