Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham
	autolearn_force=no version=3.4.1
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH 3/3] _git: Invoke reflog completion from the 'complete commit objects' codepath.
Date: Fri, 18 Mar 2016 21:21:45 +0000
Message-Id: <1458336105-7348-3-git-send-email-danielsh@tarsus.local2>
X-Mailer: git-send-email 1.8.4.5
In-Reply-To: <1458336105-7348-1-git-send-email-danielsh@tarsus.local2>
References: <1458336105-7348-1-git-send-email-danielsh@tarsus.local2>
X-Seq: zsh-workers 38182

The reflog will only be used if the user has typed as "@" by hand.
---
 Completion/Unix/Command/_git | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 0eb8532..ee45576 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5474,7 +5474,9 @@ __git_reflog_entries () {
   local expl
   declare -a reflog_entries
 
-  reflog_entries=(${(f)"$(_call_program reflog-entries "git reflog -1000 --pretty='%gD:[%h] %gs'" 2>/dev/null)"})
+  # Repeat the %gD on the RHS due to uniquify the matches, to avoid bad
+  # completion list layout.  (Compare workers/34768)
+  reflog_entries=(${(f)"$(_call_program reflog-entries "git reflog -1000 --pretty='%gD:[%h] %gs (%gD)'" 2>/dev/null)"})
   reflog_entries=( ${reflog_entries/HEAD@$'\x7b'/@$'\x7b'} )
   __git_command_successful $pipestatus || return 1
 
@@ -5671,8 +5673,13 @@ __git_commit_objects () {
   local gitdir expl start
   declare -a commits
 
-  # Abort if the argument does not match a commit hash (including empty).
-  [[ "$PREFIX$SUFFIX" == [[:xdigit:]](#c1,40) ]] || return 1
+  if [[ -n $PREFIX[(r)@] ]] || [[ -n $SUFFIX[(r)@] ]]; then
+    # doesn't match a commit hash, but might be a reflog entry
+    __git_reflog_entries; return $?
+  elif ! [[ "$PREFIX$SUFFIX" == [[:xdigit:]](#c1,40) ]]; then
+    # Abort if the argument does not match a commit hash (including empty).
+    return 1
+  fi
 
   # Note: the after-the-colon part must be unique across the entire array;
   # see workers/34768

