zsh-workers
 help / color / mirror / code / Atom feed
* Git auto completion does not work for comparing 2 files from 2 different branches
@ 2022-09-30  3:44 한현빈
  2022-10-01  0:54 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: 한현빈 @ 2022-09-30  3:44 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 803 bytes --]

I compare 2 different files from git remote like this:
git diff origin/branch1:file.txt origin/branch2:file.txt
However, auto completion only works until this point: git diff origin/branch1:file.txt, pressing tab afterward does not bring me list of usable remotes, branches in the said remote, and files in the said branch, unlike first one in branch1, which auto completion works fine.
 
Steps to reproduce

Clone any repository with 2 or more branches
Try to get difference of 2 files using git diff origin/branch1:path/to/file origin/branch2:path/to/file
Observe that auto completion doesn't work for second one

OS is KDE Neon, 20.04
Terminal I used is Yakuake and Konsole
ZSH version is 5.8

I have attached video of me reproducing the issue.

From Hyun Bin, and thank you for your effort on this.

[-- Attachment #1.2: Type: text/html, Size: 1968 bytes --]

[-- Attachment #2: 192280070-55a2f509-b33f-4f84-ad3b-8fe63fb2e401.mp4 --]
[-- Type: video/mp4, Size: 2506086 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git auto completion does not work for comparing 2 files from 2 different branches
  2022-09-30  3:44 Git auto completion does not work for comparing 2 files from 2 different branches 한현빈
@ 2022-10-01  0:54 ` Bart Schaefer
  2022-10-01  3:54   ` [PATCH] " Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2022-10-01  0:54 UTC (permalink / raw)
  To: 한현빈; +Cc: zsh-workers

On Thu, Sep 29, 2022 at 9:17 PM 한현빈 <ironman466@naver.com> wrote:
>
> However, auto completion only works until this point: git diff origin/branch1:file.txt, pressing tab afterward does not bring me list of usable remotes, branches in the said remote, and files in the said branch, unlike first one in branch1, which auto completion works fine.

Confirmed this is still the case in 5.9 -- git diff completion always
assumes you're comparing a branch to the current checkout.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] Re: Git auto completion does not work for comparing 2 files from 2 different branches
  2022-10-01  0:54 ` Bart Schaefer
@ 2022-10-01  3:54   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2022-10-01  3:54 UTC (permalink / raw)
  To: 한현빈; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 254 bytes --]

On Fri, Sep 30, 2022 at 5:54 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Confirmed this is still the case in 5.9 -- git diff completion always
> assumes you're comparing a branch to the current checkout.

Any reason not to rearrange like so?

[-- Attachment #2: git-diff.txt --]
[-- Type: text/plain, Size: 1869 bytes --]

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index cecb80ac3..6a1c4158a 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -808,18 +808,6 @@ _git-diff () {
 
       # Otherwise, more complex conditions need to be checked.
       case $CURRENT in
-        (1)
-          local files_alt='files::__git_changed-in-working-tree_files'
-          if [[ -n ${opt_args[(I)--cached|--staged]} ]]; then
-            files_alt='files::__git_changed-in-index_files'
-          fi
-
-          _alternative \
-            'commit-ranges::__git_commit_ranges' \
-            'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \
-            $files_alt \
-            'blobs::__git_blobs ' && ret=0
-          ;;
         (2)
           # Check if first argument is something special. In case of committish ranges and committishs offer a full list compatible completions.
           if __git_is_committish_range $line[1]; then
@@ -841,10 +829,19 @@ _git-diff () {
           elif [[ -n ${opt_args[(I)--cached|--staged]} ]]; then
             # Example: git diff --cached file1 <tab>
             __git_changed-in-index_files && ret=0
-          else
-            # Example: git diff file1 <tab>
-            __git_changed-in-working-tree_files && ret=0
           fi
+          ;&
+        (1)
+          local files_alt='files::__git_changed-in-working-tree_files'
+          if [[ -n ${opt_args[(I)--cached|--staged]} ]]; then
+            files_alt='files::__git_changed-in-index_files'
+          fi
+
+          _alternative \
+            'commit-ranges::__git_commit_ranges' \
+            'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \
+            $files_alt \
+            'blobs::__git_blobs ' && ret=0
           ;;
         (*)
           if __git_is_committish_range $line[1]; then

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-01  3:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30  3:44 Git auto completion does not work for comparing 2 files from 2 different branches 한현빈
2022-10-01  0:54 ` Bart Schaefer
2022-10-01  3:54   ` [PATCH] " Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).