forked from nvie/gitflow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-flow-support
153 lines (134 loc) · 3.35 KB
/
git-flow-support
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
#
# git-flow -- A collection of Git extensions to provide high-level
# repository operations for Vincent Driessen's branching model.
#
# Original blog post presenting this model is found at:
# http://nvie.com/archives/323
#
# Feel free to contribute to this project at:
# http://github.com/nvie/gitflow
#
# Copyright (c) 2010 by Vincent Driessen
# Copyright (c) 2010 by Benedikt Böhm
#
require_git_repo
require_gitflow_initialized
gitflow_load_settings
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
PREFIX=$(git config --get gitflow.prefix.support)
warn "note: The support subcommand is still very EXPERIMENTAL!"
warn "note: DO NOT use it in a production situation."
usage() {
echo "usage: git flow support [list] [-v]"
echo " git flow support start [-F] <version> <base>"
}
cmd_default() {
cmd_list "$@"
}
cmd_list() {
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
local support_branches
local current_branch
local short_names
support_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
if [ -z "$support_branches" ]; then
warn "No support branches exist."
exit 0
fi
current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
# determine column width first
local width=0
local branch
for branch in $short_names; do
local len=${#branch}
width=$(max $width $len)
done
width=$(($width+3))
local branch
for branch in $short_names; do
local fullname=$PREFIX$branch
local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
local master_sha=$(git rev-parse "$MASTER_BRANCH")
local branch_sha=$(git rev-parse "$fullname")
if [ "$fullname" = "$current_branch" ]; then
printf "* "
else
printf " "
fi
if flag verbose; then
printf "%-${width}s" "$branch"
if [ "$branch_sha" = "$master_sha" ]; then
printf "(no commits yet)"
else
local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
local nicename
if [ "$tagname" != "" ]; then
nicename=$tagname
else
nicename=$(git rev-parse --short "$base")
fi
printf "(based on $nicename)"
fi
else
printf "%s" "$branch"
fi
echo
done
}
cmd_help() {
usage
exit 0
}
parse_args() {
# parse options
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# read arguments into global variables
VERSION=$1
BASE=$2
BRANCH=$PREFIX$VERSION
}
require_version_arg() {
if [ "$VERSION" = "" ]; then
warn "Missing argument <version>"
usage
exit 1
fi
}
require_base_arg() {
if [ "$BASE" = "" ]; then
warn "Missing argument <base>"
usage
exit 1
fi
}
require_base_is_on_master() {
if ! git branch --contains "$BASE" 2>/dev/null \
| sed 's/[* ] //g' \
| grep -q "^$MASTER_BRANCH\$"; then
die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
fi
}
cmd_start() {
DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
parse_args "$@"
require_version_arg
require_base_arg
require_base_is_on_master
# sanity checks
require_clean_working_tree
# fetch remote changes
if flag fetch; then
git fetch -q "$ORIGIN" "$BASE"
fi
require_branch_absent "$BRANCH"
# create branch
git checkout -b "$BRANCH" "$BASE"
echo
echo "Summary of actions:"
echo "- A new branch '$BRANCH' was created, based on '$BASE'"
echo "- You are now on branch '$BRANCH'"
echo
}