mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-24 04:50:27 +02:00
32396: _git: fix __git_committish_range_{first,last} and __git_is_committish_range
- Ranges with 3 dots would always fail, because the non-greedy
expansion %..(.|)* in __git_committish_range_first would only
remove '..' and never three dots. 'a...b' would end up in 'a.'.
Use ${${1%..*}%.} instead.
- Use a similar approach for __git_committish_range_last.
- Wrap them in another expansion to replace empty results with 'HEAD'.
Git man-page states omitted range ending are being replaced with
HEAD. This rule has to be followed to make completions like
'git log foo.. -- <tab>' work properly.
- Add an additional check to make sure none of the extracted first/last
parts contain additional '..' in invalied ranges such as 'a..b..c'.
This gets rid of the 'TODO:' and ideally saves a few unneded
calls to git rev-parse.
This commit is contained in:
parent
76ab661df3
commit
946a99a0b3
2 changed files with 13 additions and 8 deletions
|
|
@ -4798,12 +4798,12 @@ __git_command_successful () {
|
|||
|
||||
(( $+functions[__git_committish_range_first] )) ||
|
||||
__git_committish_range_first () {
|
||||
print -r -- ${1%..(.|)*}
|
||||
print -r -- ${${${1%..*}%.}:-HEAD}
|
||||
}
|
||||
|
||||
(( $+functions[__git_committish_range_last] )) ||
|
||||
__git_committish_range_last () {
|
||||
print -r -- ${1##*..(.|)}
|
||||
print -r -- ${${${1#*..}#.}:-HEAD}
|
||||
}
|
||||
|
||||
(( $+functions[__git_pattern_escape] )) ||
|
||||
|
|
@ -4832,12 +4832,12 @@ __git_is_treeish () {
|
|||
|
||||
(( $+functions[__git_is_committish_range] )) ||
|
||||
__git_is_committish_range () {
|
||||
# TODO: This isn't quite right. We would like to do parts=${(~s:..(.|))},
|
||||
# but that doesn't work. (This would allow us to make sure that parts only
|
||||
# contains two elements and then apply __git_is_committish on them.
|
||||
[[ $1 == *..(.|)* ]] &&
|
||||
__git_is_committish $(__git_committish_range_first $1) &&
|
||||
__git_is_committish $(__git_committish_range_last $1)
|
||||
[[ $1 == *..(.|)* ]] || return 1
|
||||
local first=$(__git_committish_range_first $1)
|
||||
local last=$(__git_committish_range_last $1)
|
||||
[[ $first != *..* && $last != *..* ]] && \
|
||||
__git_is_committish $first && \
|
||||
__git_is_committish $last
|
||||
}
|
||||
|
||||
(( $+functions[__git_is_initial_commit] )) ||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue