zsh-workers
 help / color / Atom feed
From: WGH <wgh@torlan.ru>
To: zsh-workers@zsh.org
Subject: [PATCH] _git: Fix __git_recent_branches for case when commit has empty message
Date: Fri, 31 Jan 2020 19:57:32 +0300
Message-ID: <5391aaa5-73e7-266c-adb2-8c7d96373b8e@torlan.ru> (raw)

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



             reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31 16:57 WGH [this message]
2020-02-01  0:09 ` Daniel Shahaf
2020-02-01 23:50   ` WGH
2020-02-02  7:34     ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5391aaa5-73e7-266c-adb2-8c7d96373b8e@torlan.ru \
    --to=wgh@torlan.ru \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git