Skip to content

Commit

Permalink
completion: find out supported merge strategies correctly
Browse files Browse the repository at this point in the history
"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>
  • Loading branch information
Junio C Hamano committed Aug 20, 2008
1 parent 54988bd commit 25b3d4d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,17 @@ __git_merge_strategies ()
echo "$__git_merge_strategylist"
return
fi
sed -n "/^all_strategies='/{
s/^all_strategies='//
s/'//
git merge -s help 2>&1 |
sed -n -e '/[Aa]vailable strategies are: /,/^$/{
s/\.$//
s/.*://
s/^[ ]*//
s/[ ]*$//
p
q
}" "$(git --exec-path)/git-merge"
}'
}
__git_merge_strategylist=
__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)

__git_complete_file ()
{
Expand Down

0 comments on commit 25b3d4d

Please sign in to comment.