@matheusbsbs / matheus-bagliano / commits / 25b3d4d6f3
Fork 0

completion: find out supported merge strategies correctly

"git-merge" is a binary executable these days, and looking for assignment to $all_strategies variable with grep/sed does not work well. When asked for an unknown strategy, pre-1.6.0 and post-1.6.0 "git merge" commands respectively say: $ $HOME/git-snap-v1.5.6.5/bin/git merge -s help available strategies are: recur recursive octopus resolve stupid ours subtree $ $HOME/git-snap-v1.6.0/bin/git merge -s help Could not find merge strategy 'help'. Available strategies are: recursive octopus resolve ours subtree. both on their standard error stream. We can use this to learn what strategies are supported. The sed script is written in such a way that it catches both old and new message styles ("Available" vs "available", and the full stop at the end). It also allows future versions of "git merge" to line-wrap the list of strategies, and add extra comments, like this: $ $HOME/git-snap-v1.6.1/bin/git merge -s help Could not find merge strategy 'help'. Available strategies are: blame recursive octopus resolve ours subtree. Also you have custom strategies: theirs Make sure you spell strategy names correctly. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 20, 2008 at 14:13 UTC 25b3d4d6f39d70c4d46dee48570ae7aeeb4a6b58
1 file changed +8 -6
contrib/completion/git-completion.bash
+8 -6
@@ -271,15 +271,17 @@ __git_merge_strategies ()
271 echo "$__git_merge_strategylist"
272 return
273 fi
274 - sed -n "/^all_strategies='/{
275 - s/^all_strategies='//
276 - s/'//
274 + git merge -s help 2>&1 |
275 + sed -n -e '/[Aa]vailable strategies are: /,/^$/{
276 + s/\.$//
277 + s/.*://
278 + s/^[ ]*//
279 + s/[ ]*$//
280 p
278 - q
279 - }" "$(git --exec-path)/git-merge"
281 + }'
282 }
283 __git_merge_strategylist=
282 -__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
284 +__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
285
286 __git_complete_file ()
287 {