Skip to content

Commit b84e297

Browse files
committed
Merge branch 'cy/zsh-completion-SP-in-path'
With zsh, "git cmd path<TAB>" was completed to "git cmd path name" when the completed path has a special character like SP in it, without any attempt to keep "path name" a single filename. This has been fixed to complete it to "git cmd path\ name" just like Bash completion does. * cy/zsh-completion-SP-in-path: completion: treat results of git ls-tree as file paths zsh: complete unquoted paths with spaces correctly
2 parents c433857 + 6d54f52 commit b84e297

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

contrib/completion/git-completion.bash

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -855,22 +855,26 @@ __git_compute_merge_strategies ()
855855

856856
__git_complete_revlist_file ()
857857
{
858-
local pfx ls ref cur_="$cur"
858+
local dequoted_word pfx ls ref cur_="$cur"
859859
case "$cur_" in
860860
*..?*:*)
861861
return
862862
;;
863863
?*:*)
864864
ref="${cur_%%:*}"
865865
cur_="${cur_#*:}"
866-
case "$cur_" in
866+
867+
__git_dequote "$cur_"
868+
869+
case "$dequoted_word" in
867870
?*/*)
868-
pfx="${cur_%/*}"
869-
cur_="${cur_##*/}"
871+
pfx="${dequoted_word%/*}"
872+
cur_="${dequoted_word##*/}"
870873
ls="$ref:$pfx"
871874
pfx="$pfx/"
872875
;;
873876
*)
877+
cur_="$dequoted_word"
874878
ls="$ref"
875879
;;
876880
esac
@@ -880,21 +884,10 @@ __git_complete_revlist_file ()
880884
*) pfx="$ref:$pfx" ;;
881885
esac
882886

883-
__gitcomp_nl "$(__git ls-tree "$ls" \
884-
| sed '/^100... blob /{
885-
s,^.* ,,
886-
s,$, ,
887-
}
888-
/^120000 blob /{
889-
s,^.* ,,
890-
s,$, ,
891-
}
892-
/^040000 tree /{
893-
s,^.* ,,
894-
s,$,/,
895-
}
896-
s/^.* //')" \
897-
"$pfx" "$cur_" ""
887+
__gitcomp_file "$(__git ls-tree "$ls" \
888+
| sed 's/^.* //
889+
s/$//')" \
890+
"$pfx" "$cur_"
898891
;;
899892
*...*)
900893
pfx="${cur_%...*}..."
@@ -2993,7 +2986,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
29932986

29942987
local IFS=$'\n'
29952988
compset -P '*[=:]'
2996-
compadd -Q -f -- ${=1} && _ret=0
2989+
compadd -f -- ${=1} && _ret=0
29972990
}
29982991

29992992
__gitcomp_file ()
@@ -3002,7 +2995,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
30022995

30032996
local IFS=$'\n'
30042997
compset -P '*[=:]'
3005-
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2998+
compadd -p "${2-}" -f -- ${=1} && _ret=0
30062999
}
30073000

30083001
_git ()

contrib/completion/git-completion.zsh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ __gitcomp_file_direct ()
9999

100100
local IFS=$'\n'
101101
compset -P '*[=:]'
102-
compadd -Q -f -- ${=1} && _ret=0
102+
compadd -f -- ${=1} && _ret=0
103103
}
104104

105105
__gitcomp_file ()
@@ -108,7 +108,7 @@ __gitcomp_file ()
108108

109109
local IFS=$'\n'
110110
compset -P '*[=:]'
111-
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
111+
compadd -p "${2-}" -f -- ${=1} && _ret=0
112112
}
113113

114114
__git_zsh_bash_func ()

t/t9902-completion.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,8 +1516,8 @@ test_expect_success 'show completes all refs' '
15161516

15171517
test_expect_success '<ref>: completes paths' '
15181518
test_completion "git show mytag:f" <<-\EOF
1519-
file1 Z
1520-
file2 Z
1519+
file1Z
1520+
file2Z
15211521
EOF
15221522
'
15231523

@@ -1526,7 +1526,7 @@ test_expect_success 'complete tree filename with spaces' '
15261526
git add "name with spaces" &&
15271527
git commit -m spaces &&
15281528
test_completion "git show HEAD:nam" <<-\EOF
1529-
name with spaces Z
1529+
name with spacesZ
15301530
EOF
15311531
'
15321532

@@ -1535,8 +1535,8 @@ test_expect_success 'complete tree filename with metacharacters' '
15351535
git add "name with \${meta}" &&
15361536
git commit -m meta &&
15371537
test_completion "git show HEAD:nam" <<-\EOF
1538-
name with ${meta} Z
1539-
name with spaces Z
1538+
name with ${meta}Z
1539+
name with spacesZ
15401540
EOF
15411541
'
15421542

0 commit comments

Comments
 (0)