-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzzgit.sh
executable file
·152 lines (102 loc) · 2.77 KB
/
zzgit.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
source /usr/local/turbolab.it/bash-fx/bash-fx.sh
fxTitle "zzgit"
echo "$(pwd)"
fxTitle "Checking if the current folder is a Git repo"
if [ ! -f ".git/config" ]; then
fxCatasgrophicError "##$(pwd)## is NOT a git dir"
fi
fxOK "OK! It's a repo!"
cat ".git/config" | grep 'url = '
fxTitle "Acquiring owner"
GITUSER=$(stat -c '%U' ".git/config")
echo $GITUSER
fxTitle "Checking current user matching"
CURRENTUSER=$(whoami)
if [ "$CURRENTUSER" == "$GITUSER" ]; then
echo "Current user match! No sudo necessary"
function zzgitcmd
{
git "$@"
}
else
echo "Current user DOESN'T match! Will sudo commands as $GITUSER"
function zzgitcmd
{
sudo -u $GITUSER -H git "$@"
}
fi
zzgitcmd config --global --add safe.directory "$(pwd)"
if [ "$1" == "superpush" ]; then
fxTitle "Display current status"
zzgitcmd status
read -p "Proceed with add,commit,push? " -n 1 -r
echo
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
fxTitle "KO, aborting."
echo
exit
fi
fxTitle "Git add"
zzgitcmd add .
fxTitle "Git commit"
zzgitcmd commit --allow-empty-message -m "${2}"
fxTitle "Git pull"
zzgitcmd pull --no-rebase --no-edit
fxTitle "Git push"
zzgitcmd push
elif [ "$1" == "flow" ]; then
fxTitle "🤓 Fetching..."
zzgitcmd fetch --all
fxTitle "🤓 Pulling and pushing from the current branch..."
zzgitcmd pull --no-rebase --no-edit
zzgitcmd push
if [ "`git branch --list staging`" ]; then
fxTitle "🧪 Switching to staging..."
zzgitcmd checkout staging
zzgitcmd pull --no-rebase --no-edit
fxTitle "🧪 Merging dev into staging..."
zzgitcmd merge origin/dev --no-edit
zzgitcmd push
BRANCH_TO_MERGE_INTO_MASTER=origin/staging
else
read -p "☠️ Branch staging doesn't exists! Proceed anyway?" -n 1 -r
echo
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
fxTitle "☠️ OK, quitting!"
echo ""
exit
else
BRANCH_TO_MERGE_INTO_MASTER=$(zzgitcmd rev-parse --abbrev-ref --symbolic-full-name @{u})
fi
fi
echo
if [ -z "$2" ]; then
read -p "🤠 Merge to master? " -n 1 -r
echo
echo
elif [ "$2" = "y" ]; then
REPLY=Y
fi
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "🐇 Skipping master, you pussy..."
else
echo "🤠 Yippee-ki-yay, switching to master..."
zzgitcmd checkout master
zzgitcmd pull --no-rebase --no-edit
echo "🤠 Merging $BRANCH_TO_MERGE_INTO_MASTER into master..."
zzgitcmd merge $BRANCH_TO_MERGE_INTO_MASTER --no-edit
zzgitcmd push
fi
echo "🤓 Switching back to dev..."
zzgitcmd checkout dev
zzgitcmd branch
elif [ "$1" == "clean" ]; then
zzgitcmd repack -a -d --depth=250 --window=250
else
zzgitcmd "$@"
fi
fxTitle "Operation completed"
echo ""