-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitvb-remote-rm
executable file
·59 lines (46 loc) · 1.22 KB
/
gitvb-remote-rm
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
#!/usr/bin/env bash
set -e
GITVB_HOME="./.git/.gitvb-v0"
MAIN_BRANCH="${MAIN_BRANCH:-main}"
USAGE="usage: gitvb-remote-rm <branch>"
if [ ! -z "$(git diff --staged)" ]; then
echo "there are staged changes. exiting."
exit 1
fi
if [ "$(git branch --show-current)" != "$MAIN_BRANCH" ]; then
echo "you are not on the main branch: $MAIN_BRANCH"
exit 1
fi
if [ "$1" == "" ]; then
echo $USAGE
exit 1
fi
oldBranch="$1"
vbFilePath="$GITVB_HOME/$oldBranch.gitvb"
if [ -f "$vbFilePath" ]; then
echo
echo "cannot remote delete '$oldBranch' since it's picked"
echo "unpick it first!"
echo
exit 2
fi
if [ -z "$(git ls-remote --heads origin $oldBranch)" ]; then
echo
echo "branch $oldBranch doesn't exist on the remote"
echo
exit 5
fi
nUnpushed=$(git rev-list --count origin/$oldBranch..$oldBranch)
if [ "$nUnpushed" != "0" ]; then
echo
echo "cannot remote delete '$oldBranch' since it has $nUnpushed unpushed changes"
echo
exit 3
fi
echo "remote-mv: delete old branch '$oldBranch' from local"
gitvb-rm-unpicked $oldBranch
echo "remote-mv: delete old branch '$oldBranch' from remote"
git push -d origin $oldBranch
echo
echo "successfully deleted $oldBranch forever!"
echo