-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-flux-team
183 lines (150 loc) · 4.5 KB
/
git-flux-team
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
#!/usr/bin/env bash
cmd_usage_default() {
printf "%s" "create|destroy|sync|review|switch <name> [-h]"
}
cmd_usage_create() {
printf "%s" "create <name> [-h]"
}
cmd_usage_destroy() {
printf "%s" "destroy <name> [-h]"
}
cmd_usage_sync() {
printf "%s" "sync <name> [-h]"
}
cmd_usage_review() {
printf "%s" "review <name> [-h]"
}
cmd_usage_switch() {
printf "%s" "switch <name> [-h]"
}
cmd_long_usage_default() {
printf "%s" "\
$(f_heading "team" | f_fg_yellow)
handle integration across team members and their features.
$(f_subheading "available actions")
$(cmd_long_usage_create)
$(cmd_long_usage_destroy)
$(cmd_long_usage_sync)
$(cmd_long_usage_review)
$(cmd_long_usage_switch)
"
}
cmd_long_usage_create() {
printf "%s" "\
$(f_code_definition \
"$(cmd_usage_create)" \
"start a new team; create a local branch and push it to the remote.
the branch name will be composed of the pre-configured team prefix and the passed $(f_code "name").
aliases: $(f_code "assemble"), $(f_code "gather"), $(f_code "huddle").")
"
}
cmd_long_usage_destroy() {
printf "%s" "\
$(f_code_definition \
"$(cmd_usage_destroy)" \
"destroy an existing team; delete its local and remote branches, for good.
aliases: $(f_code "disassemble"), $(f_code "scatter"), $(f_code "break").")
"
}
cmd_long_usage_sync() {
printf "%s" "\
$(f_code_definition \
"$(cmd_usage_sync)" \
"sync an existing team with its base branch, i.e. the integration branch.")
"
}
cmd_long_usage_review() {
printf "%s" "\
$(f_code_definition \
"$(cmd_usage_review)" \
"open a pull request from the team branch to its base branch, i.e. the integration branch, for review in github.")
"
}
cmd_long_usage_switch() {
printf "%s" "\
$(f_code_definition \
"$(cmd_usage_switch)" \
"switch teams to another team, or join a team for the first time.
after this, all new features will be based on the new team.
aliases: $(f_code "switch").")
"
}
# aliases
cmd_assemble() { cmd_create "$@"; }
cmd_gather() { cmd_create "$@"; }
cmd_huddle() { cmd_create "$@"; }
cmd_disassemble() { cmd_destroy "$@"; }
cmd_scatter() { cmd_destroy "$@"; }
cmd_break() { cmd_destroy "$@"; }
cmd_join() { cmd_switch "$@"; }
cmd_create() {
local name
local branch
require_args "$1"
name="$1"
branch="$(git_config_get "prefix.team")$name"
io_log; create_branch_from_base "$branch" "$(git_config_get "branch.integration")"
git_config_set "branch.team" "$branch"
io_log; io_log_ok "team '$name' is created. congrats!"; io_log
}
cmd_destroy() {
local name
local branch
require_args "$1"
name="$1"
branch="$(git_config_get "prefix.team")$name"
io_log; destroy_branch_from_base "$branch"
git_config_unset "branch.team" "$branch"
io_log; io_log_ok "team '$name' is gone. so long!"; io_log
}
cmd_sync() {
local name
require_args "$1"
name="$1"
io_log; sync_branch_with_base "$(git_config_get "prefix.team")$name"
io_log; io_log_ok "team '$name' is in sync with the base."; io_log
}
cmd_review() {
local name
require_args "$1"
name="$1"
io_log; review_branch_from_base "$(git_config_get "prefix.team")$name"
io_log; io_log_ok "team '$name' is ready for review."; io_log
}
cmd_switch() {
local prefix
local new_team_branch
local old_team_branch
local new_team_name
local old_team_name
local old_team_feature_branches
local n
require_args "$1"
new_team_name="$1"
prefix="$(git_config_get "prefix.team")"
new_team_branch="$prefix$new_team_name"
old_team_branch="$(git_config_get "branch.team")"
validate_git_local_and_remote_branches_exist "$new_team_branch"
if [[ $new_team_branch = "$old_team_branch" ]]; then
io_log; io_status_fatal "'$new_team_name' is the current team, nothing to do."
fi
# todo - should this block be used in the 'destroy' action as well?
# relevant when switching teams, not when joining a team for the first time
if [[ -n $old_team_branch ]]; then
validate_git_local_and_remote_branches_exist "$old_team_branch"
old_team_feature_branches=( $(git_config_get_subsections_by_value 'base' "$old_team_branch" 'branch:') )
if (( ${#old_team_feature_branches[@]} > 0 )); then
# strip prefix to get the team name
old_team_name="${old_team_branch#$prefix}"
io_log; io_log_info "feature branches of the '$old_team_name' team were found:"
for (( n=0; n<${#old_team_feature_branches[@]}; n++ )); do
io_log "${old_team_feature_branches[$n]}" 1
done
io_confirm "ignore them and continue?" "aborting, see ya later."
fi
fi
io_log
git_v_checkout "$new_team_branch"
git_config_set "branch.team" "$new_team_branch"
io_log; io_log_ok "team switched. welcome aboard!"; io_log
}