-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy path_git-imerge
More file actions
207 lines (174 loc) · 6.76 KB
/
_git-imerge
File metadata and controls
207 lines (174 loc) · 6.76 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#compdef git-imerge
__git_imerge_branches () {
local -a branches;
branches=(
$(git for-each-ref --format='%(refname)' refs/heads/ refs/remotes/ 2>/dev/null |
sed -e 's!^refs/heads/!!' -e 's!^refs/remotes/!!')
)
_describe -t branches 'branches' branches
}
__git_imerge_names () {
local -a names;
names=(
$(git for-each-ref --format='%(refname)' refs/imerge/ 2>/dev/null |
sed -e 's/^refs\/imerge\/\(.*\)\/.*/\1/' -e '/manual/d' -e '/auto/d')
)
_describe -t names 'names' names
}
__git_imerge_commits () {
# complete commits sorted newest first
# if the commit is followed by a dot, complete a range of commits from that point onwards
# assumes that the commit to be completed is the last argument
local -a commits;
local word=$words[-1]
if [[ $word != *. ]]; then
commits=(
$(git rev-list --no-commit-header --format='%h:%s' HEAD 2>/dev/null)
)
fi
word="${word%%.*}.."
commits=(
$commits
$(git rev-list --reverse --no-commit-header --format="$word"'%h:%s' "$word" 2>/dev/null)
)
_describe -t commits 'commits' commits -o nosort
}
__git_imerge_goals=(
full
rebase
rebase-with-history
border
border-with-history
border-with-history2
merge
drop
revert
)
__git_imerge_commands () {
local -a commands
commands=(
'start:start a new incremental merge'
'merge:start a simple merge via incremental merge'
'rebase:start a simple rebase via incremental merge'
'drop:drop one or more commits via incremental merge'
'revert:revert one or more commits via incremental merge'
'continue:record the merge at branch imerge/NAME and autofill non-conflicting merges'
'finish:simplify then remove a completed incremental merge'
'diagram:display a diagram of the current state of a merge'
'list:list the names of incremental merges that are currently in progress.'
'init:initialize a new incremental merge'
'record:record the merge at branch imerge/NAME'
'autofill:autofill non-conflicting merges'
'simplify:simplify a completed incremental merge by discarding unneeded intermediate merges and cleaning up the ancestry of the commits that are retained'
'remove:irrevocably remove an incremental merge'
'reparent:change the parents of the specified commit and propagate the change to HEAD'
)
_describe -t commands 'git-imerge subcommand' commands "$@"
}
__git-imerge_start_completion() {
_arguments \
'1:branch:__git_imerge_branches' \
'(-h,--help)'{-h,--help}'[Show this help message and exit.]' \
'--name[name to use for this incremental merge]:NAME:' \
'--goal[the goal of the incremental merge]:GOAL:($__git_imerge_goals)' \
'--branch[the name of the branch to which the result will be stored]:BRANCH:' \
'--manual[ask the user to complete all merges manually, even when they appear conflict-free.]' \
'--first-parent[handle only the first parent commits]'
}
__git-imerge_init_completion() {
__git-imerge_start_completion $1
}
__git-imerge_continue_completion() {
_arguments \
'(-h,--help)'{-h,--help}'[Show this help message and exit.]' \
'--name[name to use for this incremental merge]:NAME:__git_imerge_names' \
'(-e,--edit)'{-e,--edit}'[commit staged changes with the --edit option]' \
'--no-edit[commit staged changes with the --no-edit option]'
}
__git-imerge_finish_completion() {
_arguments \
'(-h,--help)'{-h,--help}'[Show this help message and exit.]' \
'--name[name to use for this incremental merge]:NAME:__git_imerge_names' \
'--goal[the goal of the incremental merge]:GOAL:($__git_imerge_goals)' \
'--branch[the name of the branch to which to store the result (default is the value provided to "init" or "start" if any; otherwise the name of the merge).]:BRANCH:__git_imerge_branches' \
'--manual[ask the user to complete all merges manually, even when they appear conflict-free.]' \
'--force[allow the target branch to be updated in a non-fast-forward manner]'
}
__git-imerge_simplify_completion() {
__git-imerge_finish_completion $1
}
__git-imerge_merge_completion() {
_arguments \
'1:branch:__git_imerge_branches' \
'(-h,--help)'{-h,--help}'[Show this help message and exit.]' \
'--name[name to use for this incremental merge]:NAME:' \
'--goal[the goal of the incremental merge]:GOAL:($__git_imerge_goals)' \
'--branch[the name of the branch to which the result will be stored]:BRANCH:' \
'--manual[ask the user to complete all merges manually, even when they appear conflict-free.]'
}
__git-imerge_rebase_completion() {
__git-imerge_merge_completion $1
}
__git-imerge_drop_completion() {
_arguments \
'1:commit:__git_imerge_commits' \
'(-h,--help)'{-h,--help}'[Show this help message and exit.]' \
'--name[name to use for this incremental merge]:NAME:' \
'--branch[the name of the branch to which the result will be stored]:BRANCH:' \
'--manual[ask the user to complete all merges manually, even when they appear conflict-free.]' \
'--first-parent[handle only the first parent commits]'
}
__git-imerge_revert_completion() {
__git-imerge_drop_completion $1
}
__git-imerge_list_completion() {
_arguments \
'(-h,--help)'{-h,--help}'[show this help message and exit]'
}
__git-imerge_reparent_completion() {
__git-imerge_list_completion $1
}
__git-imerge_record_completion() {
_arguments \
'(-h,--help)'{-h,--help}'[show this help message and exit]' \
'--name[name of merge to which the merge should be added]:NAME:__git_imerge_names'
}
__git-imerge_autofill_completion() {
_arguments \
'(-h,--help)'{-h,--help}'[show this help message and exit]' \
'--name[name of incremental merge to autofill]:NAME:__git_imerge_names'
}
__git-imerge_remove_completion() {
__git-imerge_autofill_completion $1
}
__git-imerge_diagram_completion() {
_arguments \
'(-h,--help)'{-h,--help}'[show this help message and exit]' \
'--name[name of incremental merge to diagram]:NAME:__git_imerge_names' \
'--commits[show the merges that have been made so far]' \
'--frontier[show the current merge frontier]' \
'--html[generate HTML diagram showing the current merge frontier]:HTML:' \
'--color[draw diagram with colors]' \
'--no-color[draw diagram without colors]'
}
_git-imerge () {
local context curcontext="$curcontext" state line
local IFS=$'\n' ret=1
_arguments -C \
'1: :__git_imerge_commands' \
'(-h,--help)'{-h,--help}'[Show this help message and exit.]' \
'*::arg:->args' \
&& ret=0
case $state in
(args)
local subcmd=$line[1]
[[ -v functions[__git-imerge_${subcmd}_completion] ]] &&
__git-imerge_${subcmd}_completion $subcmd && ret=0
;;
esac
return $ret
}
# don't run the completion function when being source-ed or eval-ed
if [ "$funcstack[1]" = "_git-imerge" ]; then
_git-imerge "$@"
fi