From patchwork Tue Jan 1 14:05:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chayoung You X-Patchwork-Id: 10745949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0444E1399 for ; Tue, 1 Jan 2019 14:06:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA66828746 for ; Tue, 1 Jan 2019 14:06:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEE5C28750; Tue, 1 Jan 2019 14:06:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B7A728746 for ; Tue, 1 Jan 2019 14:06:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728891AbfAAOGA (ORCPT ); Tue, 1 Jan 2019 09:06:00 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34030 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbfAAOGA (ORCPT ); Tue, 1 Jan 2019 09:06:00 -0500 Received: by mail-pf1-f194.google.com with SMTP id h3so14140677pfg.1 for ; Tue, 01 Jan 2019 06:05:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F5JDI78X2qf36ZQ9ireAqEU6JVwz17fAS60XT5JBQnw=; b=cqi1wa3unLerLtlsUoqlwNGvGvJNeWI/dzzfcb25dKOJsbumyg3EV8yoieOdRGhgy9 OWlFEKrUvX705YIbmkb9oXeqaQcXwYWvdyW+piWBqaxipgsO1YgN7C7bw3Q3YPzKMmwp YPi/H6f5+ze3/CbgYY9qTQqd6BXtDtE1LH5Ahhzk16ybMrZJXE58pSx9b5GGENTuFIIL se7DvrPtFS2YbMwAsdkfT5hJ878SM5aI+qeHb8Hh+l4+kJdu4DbTaBEEkteWLD4rBd/R jR2Qp7wIjVqWUrj79FP66qW0gMPeMgMbtGq6vGfWky9HwpF+p1Q9yK26kFHCCYwAtnkJ 6R6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F5JDI78X2qf36ZQ9ireAqEU6JVwz17fAS60XT5JBQnw=; b=ghmN0KDsJQSRuGCd0jr7vHFCX9BSkWuV9a4x9AQXdCPBUKPk1eihH+elVPNkYNF2mN 3Jh6BzvIyycyjNEZXe5xxL3rUZ7TWIz/1kjTBAkCJ/jb5MpuW+58m9epyh4meykicsjg hlqW5Gv7V8MKpnC7zyq3M3/sr54ZK5JetxH7ewzVkVfI2jhQcvUOMJwmejxSTXnYYEy4 ZCKITVK0f2LLNS/46mrkAB8qDZ2ggsf4DqN92uCSlgF7vKXPi/dbbMDmrTOMalFAlRw4 4RvpmVG3ZqNLxVdcSYmrrqO3mNLkmshnhESsnf6LPuYrTNCEiSFlYXm9aUKdH6t7e2yt s7mQ== X-Gm-Message-State: AJcUukfvXD2MmlWwkUAJXICZTqPwtuykxoF9T6Z5abf898TC3cXYVt+u XpqfcJfOn1d6E1H0cv6JoOQJE9BK X-Google-Smtp-Source: ALg8bN5WD033fqh0Jtc7hc0ZjkUG2TkIbhWnCvslfBPwt2qwLN4F2PnSZ7Fv1XqEy5yggxc4on9iVA== X-Received: by 2002:a63:f1f:: with SMTP id e31mr10541449pgl.274.1546351557951; Tue, 01 Jan 2019 06:05:57 -0800 (PST) Received: from localhost.localdomain ([39.119.71.29]) by smtp.gmail.com with ESMTPSA id o13sm75551257pfk.57.2019.01.01.06.05.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Jan 2019 06:05:57 -0800 (PST) From: Chayoung You To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v3 1/2] zsh: complete unquoted paths with spaces correctly Date: Tue, 1 Jan 2019 23:05:08 +0900 Message-Id: <20190101140509.1857-2-yousbe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190101140509.1857-1-yousbe@gmail.com> References: <20181230053125.55896-1-yousbe@gmail.com> <20190101140509.1857-1-yousbe@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The following is the description of -Q flag of zsh compadd [1]: This flag instructs the completion code not to quote any metacharacters in the words when inserting them into the command line. Let's say there is a file named 'foo bar.txt' in repository, but it's not yet added to the repository. Then the following command triggers a completion: git add fo git add 'fo git add "fo The completion results in bash: git add foo\ bar.txt git add 'foo bar.txt' git add "foo bar.txt" While them in zsh: git add foo bar.txt git add 'foo bar.txt' git add "foo bar.txt" The first one, where the pathname is not enclosed in quotes, should escape the space with a backslash, just like bash completion does. Otherwise, this leads git to think there are two files; foo, and bar.txt. The main cause of this behavior is __gitcomp_file_direct(). The both implementions of bash and zsh are called with an argument 'foo bar.txt', but only bash adds a backslash before a space on command line. [1]: http://zsh.sourceforge.net/Doc/Release/Completion-Widgets.html Signed-off-by: Chayoung You Reviewed-by: Junio C Hamano --- contrib/completion/git-completion.bash | 4 ++-- contrib/completion/git-completion.zsh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 9e8ec95c3..816ee3280 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2993,7 +2993,7 @@ if [[ -n ${ZSH_VERSION-} ]] && local IFS=$'\n' compset -P '*[=:]' - compadd -Q -f -- ${=1} && _ret=0 + compadd -f -- ${=1} && _ret=0 } __gitcomp_file () @@ -3002,7 +3002,7 @@ if [[ -n ${ZSH_VERSION-} ]] && local IFS=$'\n' compset -P '*[=:]' - compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 + compadd -p "${2-}" -f -- ${=1} && _ret=0 } _git () diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 049d6b80f..886bf95d1 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -99,7 +99,7 @@ __gitcomp_file_direct () local IFS=$'\n' compset -P '*[=:]' - compadd -Q -f -- ${=1} && _ret=0 + compadd -f -- ${=1} && _ret=0 } __gitcomp_file () @@ -108,7 +108,7 @@ __gitcomp_file () local IFS=$'\n' compset -P '*[=:]' - compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 + compadd -p "${2-}" -f -- ${=1} && _ret=0 } __git_zsh_bash_func () From patchwork Tue Jan 1 14:05:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chayoung You X-Patchwork-Id: 10745951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8757E14E2 for ; Tue, 1 Jan 2019 14:06:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77A6628746 for ; Tue, 1 Jan 2019 14:06:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A33C28750; Tue, 1 Jan 2019 14:06:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF72E28746 for ; Tue, 1 Jan 2019 14:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728894AbfAAOGC (ORCPT ); Tue, 1 Jan 2019 09:06:02 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41404 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbfAAOGC (ORCPT ); Tue, 1 Jan 2019 09:06:02 -0500 Received: by mail-pg1-f193.google.com with SMTP id m1so13583569pgq.8 for ; Tue, 01 Jan 2019 06:06:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=r3iLstf2ltplYP10myhKA4afWacnEI19MLWKot94Glk=; b=b5f9Mxj3yzONNBOXa2gdNQ30LFggB0yFX/KXvgI2ab2wcUG8+MEXFjUZK32HFzhv7H wisDBQtGeos3BG38re2LTDwWwroXuxiKcqs1vob+9PTL+6I76bceCExi+xOiqhdUq7BJ 0N9083ZO1A2V6D9Nw3AZWFl+fOSY1CVuDFi/Jvph47pTDg4y1PaVEdycjpI+MY6eh8wN 7mRH7mGp8eF6ym6mDd8tpuSzM/9AD0bBTdfsZhYWIpNX2a99H4RHpkyMq7NJtMZfT39H wJQVVAyL3ij9FnczgQLQR6Qppp4iKEDQKKPV8BiXNbrEQlbI/6l8ZsiD/S8AL4MKxbNV 0/yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=r3iLstf2ltplYP10myhKA4afWacnEI19MLWKot94Glk=; b=PJWDmRXiN1Fm/k/SSi/Mg8cySwTxfKohWrGhMGCnYXFwKcAN9KBEt1c0n21ClKhzBG NoFnIpRSPqDiPmau8E0lkmdHoHCZJGfv8VcDXV1yAccIGURgyceAEJkPCLGL+0tOq+c/ IjTebkOnS+wkOW7p2/p5tPS0GsfLkyTwXzBNu/e2OqfflcA101l00fO3WwqF4vyTS4Ik M+LyE+OOxJErAU4DDpWDC0x0lhDor09FCogvWjk1YVW9zEex99Mylq9YdvPwha0AAc+A +ATRDPog7u9CjlJEAkUAJNaB5saqepscw6AP9kZQT8OrlTNwCJFHQEXWbUHuT4BToLWG AeVQ== X-Gm-Message-State: AJcUukcPkuIVeic8z/wMOUZXCoSo6yTsNNHKTJA6ubhQ19Iv6FBGeFbL pQ0GuLNc12Pxr9DlT7/H/FFKDxCc X-Google-Smtp-Source: ALg8bN7ix77Ie/ne/mH4kSn86Eq7TvRzZJ3oeqUepFInDSvplw44eZDmv887c7ZXB6KU3LZiZoQW1Q== X-Received: by 2002:a63:ee4c:: with SMTP id n12mr37553212pgk.21.1546351561178; Tue, 01 Jan 2019 06:06:01 -0800 (PST) Received: from localhost.localdomain ([39.119.71.29]) by smtp.gmail.com with ESMTPSA id o13sm75551257pfk.57.2019.01.01.06.05.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Jan 2019 06:06:00 -0800 (PST) From: Chayoung You To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v3 2/2] completion: treat results of git ls-tree as file paths Date: Tue, 1 Jan 2019 23:05:09 +0900 Message-Id: <20190101140509.1857-3-yousbe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190101140509.1857-1-yousbe@gmail.com> References: <20181230053125.55896-1-yousbe@gmail.com> <20190101140509.1857-1-yousbe@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Let's say there are files named 'foo bar.txt', and 'abc def/test.txt' in repository. When following commands trigger a completion: git show HEAD:fo git show HEAD:ab The completion results in bash/zsh: git show HEAD:foo bar.txt git show HEAD:abc def/ Where the both of them have an unescaped space in paths, so they'll be misread by git. All entries of git ls-tree either a filename or a directory, so __gitcomp_file() is proper rather than __gitcomp_nl(). Note the commit f12785a3, which handles quoted paths properly. Like this case, we should dequote $cur_ for ?*:* case. For example, let's say there is untracked directory 'abc deg', then trigger a completion: git show HEAD:abc\ de git show HEAD:'abc de git show HEAD:"abc de should uniquely complete 'abc def', but bash completes 'abc def' and 'abc deg' instead. In zsh, triggering a completion: git show HEAD:abc\ def/ should complete 'test.txt', but nothing comes. The both problems will be resolved by dequoting paths. __git_complete_revlist_file() passes arguments to __gitcomp_nl() where the first one is a list something like: abc def/Z foo bar.txt Z where Z is the mark of the EOL. - The trailing space of blob in __git ls-tree | sed. It makes the completion results become: git show HEAD:foo\ bar.txt\ So git will try to find a file named 'foo bar.txt ' instead. - The trailing slash of tree in __git ls-tree | sed. It makes the completion results on zsh become: git show HEAD:abc\ def/ So that the last space on command like should be removed on zsh to complete filenames under 'abc def/'. Signed-off-by: Chayoung You --- contrib/completion/git-completion.bash | 31 ++++++++++---------------- t/t9902-completion.sh | 10 ++++----- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 816ee3280..26ea310fd 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -855,7 +855,7 @@ __git_compute_merge_strategies () __git_complete_revlist_file () { - local pfx ls ref cur_="$cur" + local dequoted_word pfx ls ref cur_="$cur" case "$cur_" in *..?*:*) return @@ -863,14 +863,18 @@ __git_complete_revlist_file () ?*:*) ref="${cur_%%:*}" cur_="${cur_#*:}" - case "$cur_" in + + __git_dequote "$cur_" + + case "$dequoted_word" in ?*/*) - pfx="${cur_%/*}" - cur_="${cur_##*/}" + pfx="${dequoted_word%/*}" + cur_="${dequoted_word##*/}" ls="$ref:$pfx" pfx="$pfx/" ;; *) + cur_="$dequoted_word" ls="$ref" ;; esac @@ -880,21 +884,10 @@ __git_complete_revlist_file () *) pfx="$ref:$pfx" ;; esac - __gitcomp_nl "$(__git ls-tree "$ls" \ - | sed '/^100... blob /{ - s,^.* ,, - s,$, , - } - /^120000 blob /{ - s,^.* ,, - s,$, , - } - /^040000 tree /{ - s,^.* ,, - s,$,/, - } - s/^.* //')" \ - "$pfx" "$cur_" "" + __gitcomp_file "$(__git ls-tree "$ls" \ + | sed 's/^.* // + s/$//')" \ + "$pfx" "$cur_" ;; *...*) pfx="${cur_%...*}..." diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 137fdc9bd..94157e587 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1515,8 +1515,8 @@ test_expect_success 'show completes all refs' ' test_expect_success ': completes paths' ' test_completion "git show mytag:f" <<-\EOF - file1 Z - file2 Z + file1Z + file2Z EOF ' @@ -1525,7 +1525,7 @@ test_expect_success 'complete tree filename with spaces' ' git add "name with spaces" && git commit -m spaces && test_completion "git show HEAD:nam" <<-\EOF - name with spaces Z + name with spacesZ EOF ' @@ -1534,8 +1534,8 @@ test_expect_success 'complete tree filename with metacharacters' ' git add "name with \${meta}" && git commit -m meta && test_completion "git show HEAD:nam" <<-\EOF - name with ${meta} Z - name with spaces Z + name with ${meta}Z + name with spacesZ EOF '