-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitvb-remote-rename
executable file
·79 lines (58 loc) · 1.63 KB
/
gitvb-remote-rename
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
#!/usr/bin/env bash
set -e
GITVB_HOME="./.git/.gitvb-v0"
MAIN_BRANCH="${MAIN_BRANCH:-main}"
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: gitvb-remote-rename <old branch> <new branch>"
exit 1
fi
if [ "$2" == "" ]; then
echo "usage: gitvb-remote-rename <old branch> <new branch>"
exit 1
fi
oldBranch="$1"
newBranch="$2"
vbFilePath="$GITVB_HOME/$oldBranch.gitvb"
if [ -f "$vbFilePath" ]; then
echo
echo "cannot remote move '$oldBranch' since it's picked"
echo "unpick it first!"
echo
exit 2
fi
nUnpushed=$(git rev-list --count origin/$oldBranch..$oldBranch)
if [ "$nUnpushed" != "0" ]; then
echo
echo "cannot remote move '$oldBranch' since it has $nUnpushed unpushed changes"
echo
exit 3
fi
echo "remote-mv: wip"
gitvb-wip remote-mv
echo "remote-mv: checking out '$oldBranch'"
git checkout origin/$oldBranch
echo "remote-mv: creating new branch '$newBranch'"
git branch $newBranch
echo "remote-mv: pushing"
git push -u origin $newBranch
echo "remote-mv: delete old branch '$oldBranch' from local"
git branch -D $oldBranch
echo "remote-mv: delete old branch '$oldBranch' from remote"
git push -d origin $oldBranch
echo "remote-mv: checkout out master"
git checkout "$MAIN_BRANCH"
echo "remote-mv: wip undo"
gitvb-wip-undo remote-mv
echo
echo "succesfully renamed $oldBranch to $newBranch on origin!"
echo " you can pick it by running"
echo " $ gitvb-pick $newBranch"
echo