From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 945 invoked by alias); 17 Feb 2014 04:01:52 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32395 Received: (qmail 3847 invoked from network); 17 Feb 2014 04:01:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yGHYbJE609mlMHDI6nyq8ryS6uFSB61gXiUrlZzG5fs=; b=JMfIYg9KZyD3aoL4b0VeYG/NzozQk1LyY2A16FrinabT7JTKBY4+fkiBuj/2Pgd0Di RBW6/qPzHVZiHnAw6cVPfB9o7bsoDsY7sJ+MpMK4GFiDHODrhP3wPxAt81TTE9oS0116 6NowWnzyVUCAoDdpgXrGT750NcTsz5GBISYkmBbpCmlYL8Q8+voRwmgohCDDNH0uQTaz dWdPssERgIls1wTKtWpWXOovaHFKYRmjqu1hhoeITZStygkCAlEu9GN4HEdSMia69yeE twYwqLiLQ/t6og1CMULEGXwYRDKpxPdb0nhthU6URzunQwe6sSShOuGYn3WzgE9mZ7F0 ikhg== X-Received: by 10.14.1.68 with SMTP id 44mr25168969eec.0.1392609694214; Sun, 16 Feb 2014 20:01:34 -0800 (PST) From: m0viefreak To: zsh-workers@zsh.org Cc: m0viefreak Subject: [PATCH 2/4] _git: diff: refactor and fix wrong completions Date: Mon, 17 Feb 2014 05:00:37 +0100 Message-Id: <1392609639-2916-3-git-send-email-m0viefreak.cm@googlemail.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1392609639-2916-1-git-send-email-m0viefreak.cm@googlemail.com> References: <1392609639-2916-1-git-send-email-m0viefreak.cm@googlemail.com> Before this, there were several cases where the completion would offer the wrong things: $ git diff branch -- would try to complete "changed in workdir files", but needs to complete all "tree files in HEAD". $ git diff --cached -- file1 file2 would try to complete "changed in workdir files" but needs to complete "changed in index files". ... After this change all possible combinations are taken into account and completion should work properly. --- Completion/Unix/Command/_git | 75 +++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 8562ab2..8105501 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -722,63 +722,72 @@ _git-diff () { case $state in (from-to-file) + # If "--" is part of $opt_args, this means it was specified before any $words arguments. This means that no heads are specified in front, so we need to complete *changed* files only. + if [[ -n ${opt_args[(I)--]} ]]; then + if [[ -n ${opt_args[(I)--cached|--staged]} ]]; then + __git_changed-in-index_files && ret=0 + else + __git_changed-in-working-tree_files && ret=0 + fi + return ret + fi + + # Otherwise, more complex conditions need to be checked. case $CURRENT in (1) - if [[ -n ${opt_args[(I)--]} ]]; then - if [[ -n ${opt_args[(I)--cached|--staged]} ]]; then - __git_changed-in-index_files && ret=0 - else - __git_changed-in-working-tree_files && ret=0 - fi - else - 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 + 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 + # Example: git diff branch1..branch2 __git_tree_files ${PREFIX:-.} $(__git_committish_range_last $line[1]) && ret=0 elif __git_is_committish $line[1] || __git_is_treeish $line[1]; then - if [[ -n ${opt_args[(I)--]} ]]; then - __git_changed-in-working-tree_files && ret=0 - else - _alternative \ - 'commits::__git_commits' \ - 'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \ - 'files::__git_changed-in-working-tree_files' && ret=0 - fi + # Example: git diff branch1 + _alternative \ + 'commits::__git_commits' \ + 'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \ + 'files::__git_tree_files ${PREFIX:-.} HEAD' && ret=0 elif __git_is_blob $line[1]; then - if [[ -n ${opt_args[(I)--]} ]]; then - __git_cached_files && ret=0 - else - _alternative \ - 'files::__git_cached_files' \ - 'blobs::__git_blobs' && ret=0 - fi + _alternative \ + 'files::__git_cached_files' \ + 'blobs::__git_blobs' && ret=0 elif [[ -n ${opt_args[(I)--cached|--staged]} ]]; then + # Example: git diff --cached file1 __git_changed-in-index_files && ret=0 else + # Example: git diff file1 __git_changed-in-working-tree_files && ret=0 fi ;; (*) if __git_is_committish_range $line[1]; then + # Example: git diff branch1..branch2 file1 __git_tree_files ${PREFIX:-.} $(__git_committish_range_last $line[1]) && ret=0 elif { __git_is_committish $line[1] && __git_is_committish $line[2] } || __git_is_treeish $line[2]; then + # Example: git diff branch1 branch2 __git_tree_files ${PREFIX:-.} $line[2] && ret=0 + elif __git_is_committish $line[1] || __git_is_treeish $line[1]; then + # Example: git diff branch file1 + # Example: git diff branch -- f + __git_tree_files ${PREFIX:-.} HEAD && ret=0 elif __git_is_blob $line[1] && __git_is_blob $line[2]; then _nothing + elif [[ -n ${opt_args[(I)--cached|--staged]} ]]; then + # Example: git diff --cached file1 file2 + __git_changed-in-index_files && ret=0 else + # Example: git diff file1 file2 __git_changed-in-working-tree_files && ret=0 fi ;; -- 1.9.0.1.g7244ca4