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
X-Biglobe-Sender: <takimoto-j@kba.biglobe.ne.jp>
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\))
Subject: Re: _git-reset doesn't complete newly staged files
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
In-Reply-To: <0FD99C66-391B-4971-ABD2-3595A0EB21CB@kba.biglobe.ne.jp>
Date: Thu, 3 Mar 2016 14:07:12 +0900
Content-Transfer-Encoding: quoted-printable
Message-Id: <234B98BE-D775-4068-AE44-81715F430E15@kba.biglobe.ne.jp>
References: <0FD99C66-391B-4971-ABD2-3595A0EB21CB@kba.biglobe.ne.jp>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
X-Mailer: Apple Mail (2.1510)
X-Biglobe-Spnum: 63895
X-Seq: zsh-workers 38074

In the case of

% git reset HEAD <TAB>

the patch below tries to offer only staged files (including
newly staged files which have never been committed).
A new function __git_staged_files() ignores unmerged (conflicting)
files, but I'm not sure this is correct or not.

In the case of

% git reset commit <TAB>    # commit is not HEAD

I have no idea what to do, so I just added __git_ignore_line
to the original code.=20



diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index b7eaf2e..7a459f1 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1377,7 +1377,11 @@ _git-reset () {
       if [[ -n $line[1] ]] && __git_is_committish $line[1]; then
         commit=3D$line[1]
       fi
-      __git_tree_files ${PREFIX:-.} $commit && ret=3D0
+      if [[ $commit =3D=3D HEAD ]]; then
+	__git_ignore_line __git_staged_files && ret=3D0
+      else
+	__git_ignore_line __git_tree_files ${PREFIX:-.} $commit && ret=3D0=

+      fi
       ;;
   esac
=20
@@ -6131,6 +6135,29 @@ __git_tree_files () {
   _wanted files expl 'tree file' _multi_parts -f $compadd_opts -- / =
tree_files
 }
=20
+(( $+functions[__git_staged_files] )) ||
+__git_staged_files () {
+  local -a slist staged_files
+  local item expl i
+
+  slist=3D(${(0)"$(_call_program staged-files git status -z -uno =
2>/dev/null)"})
+  __git_command_successful $pipestatus || return 1
+
+  for (( i =3D 1; i <=3D $#slist; ++i )) do
+    item=3D$slist[i]
+    if [[ $item =3D=3D (DD|AA|U|?U)* ]]; then
+      continue	  #XXX skip unmerged files
+    elif [[ $item =3D=3D R* ]]; then
+      staged_files+=3D( $item[4,-1] $slist[++i] )
+    elif [[ $item =3D=3D [ACDM]* ]]; then
+      staged_files+=3D( $item[4,-1] )
+    fi
+  done
+  staged_files=3D( ${(0)"$(__git_files_relative =
${(pj:\0:)staged_files})"} )
+
+  _wanted staged-files expl 'staged file' compadd "$@" -a - =
staged_files
+}
+
 # Repository Argument Types
=20
 (( $+functions[__git_remote_repositories] )) ||




