summaryrefslogtreecommitdiff
path: root/t/t3000-ls-files-others.sh
diff options
context:
space:
mode:
authorLibravatar Marc Khouzam <marc.khouzam@gmail.com>2012-11-23 09:02:22 -0500
committerLibravatar Junio C Hamano <gitster@pobox.com>2012-11-24 22:35:48 -0800
commit4db42b38231b350138dd6b9c67af34e028006380 (patch)
treea1318705d5a1b2163e333df93a08f93dd2242f92 /t/t3000-ls-files-others.sh
parentFurther preparation for 1.8.0.1 (diff)
downloadtgif-4db42b38231b350138dd6b9c67af34e028006380.tar.xz
Completion must sort before using uniq
The user can be presented with invalid completion results when trying to complete a 'git checkout' command. This can happen when using a branch name prefix that matches multiple remote branches. For example, if available branches are: master remotes/GitHub/maint remotes/GitHub/master remotes/origin/maint remotes/origin/master When performing completion on 'git checkout ma' the user will be given the choices: maint master However, 'git checkout maint' will fail in this case, although completion previously said 'maint' was valid. Furthermore, when performing completion on 'git checkout mai', no choices will be suggested. So, the user is first told that the branch name 'maint' is valid, but when trying to complete 'mai' into 'maint', that completion is no longer valid. The completion results should never propose 'maint' as a valid branch name, since 'git checkout' will refuse it. The reason for this bug is that the uniq program only works with sorted input. The man page states "uniq prints the unique lines in a sorted file". When __git_refs uses the guess heuristic employed by checkout for tracking branches it wants to consider remote branches but only if the branch name is unique. To do that, it calls 'uniq -u'. However the input given to 'uniq -u' is not sorted. Therefore, in the above example, when dealing with 'git checkout ma', "__git_refs '' 1" will find the following list: master maint master maint master which, when passed to 'uniq -u' will remain the same. Therefore 'maint' will be wrongly suggested as a valid option. When dealing with 'git checkout mai', the list will be: maint maint which happens to be sorted and will be emptied by 'uniq -u', properly ignoring 'maint'. A solution for preventing the completion script from suggesting such invalid branch names is to first call 'sort' and then 'uniq -u'. Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com> Reviewed-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t3000-ls-files-others.sh')
0 files changed, 0 insertions, 0 deletions