From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,SUBJ_OBFU_PUNCT_FEW autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 4d1343eb for ; Fri, 31 Jan 2020 16:58:43 +0000 (UTC) Received: (qmail 24509 invoked by alias); 31 Jan 2020 16:58:33 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45365 Received: (qmail 4851 invoked by uid 1010); 31 Jan 2020 16:58:33 -0000 X-Qmail-Scanner-Diagnostics: from forward105o.mail.yandex.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25703. spamassassin: 3.4.2. Clear:RC:0(37.140.190.183):SA:0(-2.6/5.0):. Processed in 4.575359 secs); 31 Jan 2020 16:58:33 -0000 X-Envelope-From: wgh@torlan.ru X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf-ipv4.yandex.ru designates 37.140.190.183 as permitted sender) To: zsh-workers@zsh.org From: WGH Subject: [PATCH] _git: Fix __git_recent_branches for case when commit has empty message Message-ID: <5391aaa5-73e7-266c-adb2-8c7d96373b8e@torlan.ru> Date: Fri, 31 Jan 2020 19:57:32 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Although I don't think anyone sane would ever do that, but I happened to create one on in my local repo, and, curiously, zsh git completion broke. Pressing "Tab" after entering "git checkout " will cause the completion script to crash with the following error:     __git_recent_branches:21: bad set of key/value pairs for associative array This error happens when an associative array is assigned odd number of elements. Unless the variable being split is inside double quotes, empty elements are removed (which is what causes the problem). This commit fixes it. Since --format=%(refname)%00%(subject)%00 appends null byte to every line, using this format would cause an extra empty element appear, breaking the assigment again. In order to fix this, I removed the trailing null byte from the format string, and replaced newlines separating entries with null byte (they were previously removed). Since neither refname nor subject appears to be capable of containing newlines, this change should be safe. ---  Completion/Unix/Command/_git | 4 ++--  1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index ba1852699..97ab26512 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -6662,8 +6662,8 @@ __git_recent_branches() {      # 4. Obtain log messages for all of them in one shot.    # TODO: we'd really like --sort=none here...  but git doesn't support such a thing. -  # The \n removal is because for-each-ref prints a \n after each entry. -  descriptions=( ${(0)"$(_call_program all-descriptions "git --no-pager for-each-ref --format='%(refname)%00%(subject)%00'" refs/heads/${(q)^branches} "--")"//$'\n'} ) +  local z=$'\0' +  descriptions=( "${(0)"$(_call_program all-descriptions "git --no-pager for-each-ref --format='%(refname)%00%(subject)'" refs/heads/${(q)^branches} "--")"//$'\n'/$z}" )      # 5. Synthesize the data structure _describe wants.    local -a branches_colon_descriptions -- 2.24.1