-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit_and_push_to_bitbucket.sh
114 lines (93 loc) · 1.89 KB
/
commit_and_push_to_bitbucket.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
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
#!/bin/bash
# Colors for showing colored output
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
clear
echo
# Checking status of executed command. If unsuccessful then terminate.
check_status () {
if [[ $? -ne 0 ]];
then
echo
echo "$red>>> Something went wrong. Check above output for help. $reset"
exit 1
fi
}
# Adds new remote connection.
remote_add () {
echo
printf "$green>>> Enter remote address : $reset"
read address
git remote add origin $address
check_status
}
# Navigate to directory.
printf "$green>>> Do you want to navigate to directory? y/n: $reset"
read opt
if [ "$opt" == 'y' ]
then
echo
printf "$green>>> Enter directory path: $reset"
read path
cd "$path"
check_status
fi
echo
# Check if directory exist.
if ! [ -d .git ];
then
echo "$red>>> This directory is not git repository. $reset"
echo
printf "$green>>> Do you want to make repository? y/n: $reset"
read opt
if [ "$opt" == 'y' ];
then
git init
check_status
remote_add
else
echo
echo "$green>>> DONE $reset"
exit 0
fi
fi
echo
# Start SSH agent
echo "$green>>> STARTING SSH AGENT $reset"
eval `ssh-agent -s`
check_status
echo
# Add key to BitBucket
echo "$green>>> ADD SSH KEY FOR BITBUCKET$reset"
ssh-add ~/.ssh/id_rsa_bb
check_status
echo
# Add files to commit
git add .
echo "$green>>> FILES ADDED $reset"
check_status
echo
# commit to repository
printf "$green>>> COMMIT MESSAGE : $reset"
read message
git commit -am "$message"
check_status
echo
echo
printf "$green>>>Is it default remote: origin? y/n: $reset"
read opt
remote_name="origin"
if [ "$opt" == 'n' ];
then
printf "$green>>> Enter remote name: $reset"
read remote_name
fi
echo
echo "$green>>> PUSHING TO BITBUCKET $reset"
git push $remote_name master
check_status
echo
echo
echo "$green>>> DONE $reset"
exit 0