Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Re: Git auto completion does not work for comparing 2 files from 2 different branches
- X-seq: zsh-workers 50714
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: 한현빈 <ironman466@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] Re: Git auto completion does not work for comparing 2 files from 2 different branches
- Date: Fri, 30 Sep 2022 20:54:05 -0700
- Archived-at: <https://zsh.org/workers/50714>
- In-reply-to: <CAH+w=7ZeXumotN=48bDWdrbfZT4qOufNNGts5+jAM6iO_wyvUQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <e1a89ecd7e40d2b418bff14c468b54db@cweb002.nm.nfra.io> <CAH+w=7ZeXumotN=48bDWdrbfZT4qOufNNGts5+jAM6iO_wyvUQ@mail.gmail.com>
On Fri, Sep 30, 2022 at 5:54 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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?
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author