-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-lava-diverge
61 lines (48 loc) · 1.18 KB
/
git-lava-diverge
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
#!/bin/bash
cmd_default() {
local NEW_BRANCH
local USE_REMOTE=0
local OLD_BRANCH="master"
while getopts br OPTION
do
case $OPTION in
b)
OLD_BRANCH=$(current_branch)
;;
r)
USE_REMOTE=1
;;
esac
done
# Reset $@
shift $((OPTIND-1))
if [ $USE_REMOTE -eq 1 ]; then
require_remote_branch "$1"
echo "Checking out '$1'"
git checkout -t "$1"
NEW_BRANCH="$(current_branch)-dev"
OLD_BRANCH=$(current_branch)
else
NEW_BRANCH=$1
if [ "$2" ]; then
OLD_BRANCH=$2
fi
if [ -z "$NEW_BRANCH" ]; then
die "fatal: please specify a new branch name"
fi
fi
echo "Diverging from '$OLD_BRANCH'"
git checkout -b $NEW_BRANCH $OLD_BRANCH
local_merge_target $NEW_BRANCH $OLD_BRANCH
}
cmd_help() {
echo "git lava diverge [-b]<name> [<base>]"
echo "git lava diverge -r <remote>"
echo
echo "Create a new branch that knows which branch it diverged from. The base"
echo "branch should be a remote tracking branch and defaults to master."
echo "Use the optional -b flag to use current branch as the base branch."
echo ""
echo "The second form will checkout the provided remote branch and diverge"
echo "from that, appending -dev to the new branch name."
}