-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_pr
68 lines (60 loc) · 1.69 KB
/
start_pr
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
#!/usr/bin/env bash
## This script assumes that you have an upstream and origin branch set up.
# Establish variables
branch="$1"
up_branch="$2"
FATAL="\033[31m"
INFO="\033[34m"
WARNING="\033[33m"
RESET="\033[0m"
# Perform rebase against upstream
rebase_repo ()
{
echo -e "$INFO Checking out $up_branch... $RESET"
echo -e "$INFO ---------------------- $RESET"
git checkout $up_branch
printf "\n"
echo -e "$INFO Performing rebase on upstream and $up_branch"
echo -e "$INFO ---------------------------------------- $RESET"
git pull --rebase upstream $up_branch
printf "\n"
echo -e "$INFO Fetching... $RESET"
echo -e "$INFO ----------- $RESET"
git fetch --all
printf "\n"
git status
printf "\n"
git push
printf "\n"
echo -e "$INFO Pushing to origin $up_branch $RESET"
echo -e "$INFO ------------------------ $RESET"
git status
}
# Checks out a branch
start_pr ()
{
git checkout -b ${branch}
}
# Prompt the user for a branch to create a branch if no command line argument given
# if [[ $# -eq 0 ]]; then
if [[ -z $branch || -z $up_branch ]]; then
read -p "What is your branch number? " branch
read -p "What is your upstream branch? " up_branch
rebase_repo
fi
# Test against if the branch exists
if grep ${branch} <(git branch | xargs) >/dev/null; then
echo -e "$FATAL fatal: A branch named '${branch}' already exists, you must checkout a new branch $RESET"
exit 1
else
rebase_repo
fi
printf "\n"
# Asks if the user would like to start the PR
read -p "Would you like to start a PR? y/n " answer
if [[ "${answer}" = "yes" || "${answer}" = "y" ]]; then
start_pr
else
echo -e "$INFO PR has not been created. Rerun the script if you change your mind. $RESET"
exit 1
fi