completion: list variable names reliably with 'git config --name-only'

Recenty I created a multi-line branch description with '.' and '=' characters on one of the lines, and noticed that fragments of that line show up when completing set variable names for 'git config', e.g.: $ git config --get branch.b.description Branch description to fool the completion script with a second line containing dot . and equals = characters. $ git config --unset <TAB> ... second line containing dot . and equals ... The completion script runs 'git config --list' and processes its output to strip the values and keep only the variable names. It does so by looking for lines containing '.' and '=' and outputting everything before the '=', which was fooled by my multi-line branch description. A similar issue exists with aliases and pretty format aliases with multi-line values, but in that case 'git config --get-regexp' is run and lines in its output are simply stripped after the first space, so subsequent lines don't even have to contain '.' and '=' to fool the completion script. Use the new '--name-only' option added in the previous commit to list config variable names reliably in both cases, without error-prone post processing. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Aug 10, 2015 at 11:46 UTC 905f2036d0975a828f764947384e732c2908d6eb
1 file changed +3 -12
contrib/completion/git-completion.bash
+3 -12
@@ -744,9 +744,8 @@ __git_compute_porcelain_commands ()
744 __git_get_config_variables ()
745 {
746 local section="$1" i IFS=$'\n'
747 - for i in $(git --git-dir="$(__gitdir)" config --get-regexp "^$section\..*" 2>/dev/null); do
748 - i="${i#$section.}"
749 - echo "${i/ */}"
747 + for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
748 + echo "${i#$section.}"
749 done
750 }
751
@@ -1774,15 +1773,7 @@ __git_config_get_set_variables ()
1773 c=$((--c))
1774 done
1775
1777 - git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1778 - while read -r line
1779 - do
1780 - case "$line" in
1781 - *.*=*)
1782 - echo "${line/=*/}"
1783 - ;;
1784 - esac
1785 - done
1776 + git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null
1777 }
1778
1779 _git_config ()