-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitvb-status
executable file
·211 lines (179 loc) · 5.67 KB
/
gitvb-status
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
set -e
GITVB_HOME="./.git/.gitvb-v0"
MAIN_BRANCH="${MAIN_BRANCH:-main}"
if [ "$(git branch --show-current)" != "$MAIN_BRANCH" ]; then
echo "you are not on the main branch: $MAIN_BRANCH"
exit 1
fi
echo -n "fetching... "
git fetch --quiet
remoteBranches=$(gitvb-remote-ls-all)
echo "ok!"
nMainBehind=$(git rev-list --count $MAIN_BRANCH..origin/$MAIN_BRANCH)
pickedBranches="$(gitvb-ls)"
if [ -z "$pickedBranches" ]; then
nPicked=0
else
nPicked="$(echo "$pickedBranches" | wc -l | xargs)"
fi
echo ""
echo "on the main branch, $MAIN_BRANCH"
echo "you have $nPicked picked branches, they are $nMainBehind commits behind origin/$MAIN_BRANCH"
echo ""
echo "picked:"
echo ""
publishBranches=""
canPublish=false
needResync=false
nNeedPublish=0
if [ "$nMainBehind" != "0" ]; then
needResync=true
fi
if [ ! -z "$pickedBranches" ]; then
while IFS= read -r line; do
nAhead=$(git rev-list --count origin/$MAIN_BRANCH..$line)
nUnpushed=$(git rev-list --count origin/$line..$line)
nBehind=$(git rev-list --count $line..origin/$line)
nRemote=$(git rev-list --count "origin/$line" ^"$line")
nCommits=$(echo "$nAhead - $nRemote" | bc)
# -$nBehind :
if [ "$nUnpushed" != "0" ]; then
# 🔄
# ⚛️
# ✳️
# ❇️
echo -n " ✳️ "
else
echo -n " 🔄 "
fi
echo -n "[+$nAhead] $line"
if [ "$nAhead" != "0" ]; then
# echo -n " - !"
if [ -z "$(git show-ref --heads origin $line)" ]; then
echo -n " - remote gone!!!"
needResync=true
fi
fi
if [ "$nRemote" != "0" ]; then
echo -n " -- needs publish to rebase upstream!"
canPublish=true
nNeedPublish=$((nNeedPublish + 1))
publishBranches="$publishBranches
$line"
else
if [ "$nUnpushed" != "0" ]; then
if [ "$nAhead" == "0" ]; then
echo -n " -- needs publish to rebase upstream!!"
else
echo -n " ($nUnpushed to publish)"
fi
canPublish=true
nNeedPublish=$((nNeedPublish + 1))
publishBranches="$publishBranches
$line"
# echo -n " - $nUnpushed unpublished!"
# else
# printf "]"
fi
# printf "$nBehind from upstream]"
if [ "$nBehind" != "0" ]; then
canPublish=true
nNeedPublish=$((nNeedPublish + 1))
publishBranches="$publishBranches
$line"
fi
fi
# printf " nRemote=$nRemote nAhead=$nRemote"
echo ""
git diff --name-status $(git merge-base $MAIN_BRANCH origin/$MAIN_BRANCH)..$line | awk '
$1 == "D" {print "\033[31m" " - " $2 "\033[0m"}
$1 == "A" {print "\033[32m" " + " $2 "\033[0m"}
$1 == "M" {print "\033[36m" " ~ " $2 "\033[0m"}
'
done <<< "$pickedBranches"
fi
# > verify all of the applied hashes are applied still
# > if not, warn
# git branch --contains 3add3e57a113b1aba30053298ff7f2c6ad3122fa
echo ""
echo "unpicked:"
echo ""
# --no-merged HEAD
# branches="$(git branch -a --format='%(refname:short)' | grep -v "^$MAIN_BRANCH$" | head -n 250)"
branches="$(git branch --format='%(refname:short)')"
# branchesLocal=$(echo "$branches" | grep -v '^origin/' || echo)
# | sed 's/remotes\/origin\///g'
nGone=0
while IFS= read -r line; do
if [ -z "$line" ]; then
continue
fi
if [ "$line" == "$MAIN_BRANCH" ]; then
continue
fi
branchName=$(echo "$line" | grep -v '^origin/' || echo)
if [ -z "$branchName" ]; then
continue
fi
if echo "$pickedBranches" | grep -q "^$line$"; then
# echo "The pickedBranches contains '$line'"
continue
# else
# echo "The pickedBranches does not contain '$line'"
fi
nAhead=$(git rev-list --count origin/$MAIN_BRANCH..$line)
if gitvb-is-pickable "$branchName" &>/dev/null; then
# if [ "$needsPublishing" == "1" ]; then
echo -n " 🆗 "
else
if echo "$remoteBranches" | grep -q "^$branchName$"; then
echo -n " ☯️ "
else
echo -n " ❎ "
nGone=$((nGone + 1))
fi
fi
printf "[+%2d] %s\n" "$nAhead" "$branchName"
done <<< "$branches"
# echo
# echo " ✳️ ready to be picked ☯️ sync required"
# echo "$branchesLocal"
echo ""
gitvb-s
if [ "$needResync" == true ]; then
echo " ⚠️ A remote has gone or there are upstream changes, you must resync!"
echo " $ gitvb-resync"
echo ""
else
if [ ! -z "$(git diff --staged)" ]; then
echo "you have staged changes, commit with:"
echo " $ gitvb-commit"
echo ""
echo "or directly commit and send to the remote with:"
echo " $ gitvb-send"
echo
fi
if [ $nNeedPublish == $nPicked ]; then
echo "upstream your changes with:"
echo " $ gitvb-publish-all"
echo
else
if [ ! -z "$publishBranches" ]; then
echo "upstream your changes with:"
while IFS= read -r line; do
if [ -z "$line" ]; then
continue
fi
echo " $ gitvb-publish $line"
echo
done <<< "$publishBranches"
fi
fi
fi
if [ "$nGone" != "0" ]; then
echo " ❎ ℹ️ $nGone unpicked branches have been removed from the remote."
echo " They were probably merged. Consider whether to delete these locally,"
echo " and clean them up with $ gitvb-rm-unpicked <branch>"
echo ""
fi