From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 13665 invoked from network); 9 Mar 2023 03:05:25 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Mar 2023 03:05:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:From:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=bFt2SwHspaBiuGC7uRDzQwSy1MgbnywzbynOnJETKmM=; b=bSkY/e3lClPxoW8YbLR7mLSgg9 hRJsJSDDF1BbHi1TkX/RZyRJNAw4+L6zsxNUMhxb1P29dvUJQvEipdlyFDNHPPa2C+xGKIcZRUcHo L6M/vYGdq2HFWeE79RNUYaO+zKooYj0SI6BZLZk1pm5yKEGoUVAPBTkUy9Exbso+FUiRTeGKCa+JH CM3aMTDPEdsuzGj51/RTSGl9HD0hA2Co2NRA4p2xuFSH762SWRgSViEMSxJqMLLDpnWob/QJMSSl7 kqGkUTi6s8cJYgNrHYt0FJtTpPZhcgtgjIpxF997VrK3gmt0c4WQBkYgcyr9EbakQ7fjTTxQFQ5RY EnsmKGfw==; Received: by zero.zsh.org with local id 1pa6ap-000B2N-LG; Thu, 09 Mar 2023 03:05:23 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pa6aB-000AiT-Ps; Thu, 09 Mar 2023 03:04:44 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1pa6aA-000JgW-WD for zsh-workers@zsh.org; Thu, 09 Mar 2023 04:04:43 +0100 From: Oliver Kiddle To: Zsh workers Subject: PATCH: don't complete diff options to git blame MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <75670.1678331082.1@hydra> Date: Thu, 09 Mar 2023 04:04:42 +0100 Message-ID: <75671-1678331082.979519@npxu.ngb4.0BpR> X-Seq: 51539 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: For git, many options are shared across commands such as the options associated with selecting revisions and for showing diffs. I've long been aware that the git completion can be somewhat over-zealous when it comes to including these. I've even seen it list the same option twice with different descriptions. Anyway it was bothering me that all the diff options were included for git blame. Are these perhaps actually needed in combination with some git blame option I'm unaware of? The cause of this is the inclusion of diff options with the revision options. With this patch, __git_setup_revision_options takes a -d option to make it not do this. Aside from git blame, I've used this for git rev-list and git bundle create. I removed --exit-code from the common diff_options. I think it is only applicable to diff, diff-index and diff-tree. There may be other cases like it. The latter of these was duplicating --cc. I also identified a couple of possibly new options that were missing from the completion. Oliver diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 49f9fa504..1a9c79034 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -393,7 +393,7 @@ _git-bundle () { ':bundle:_files' && ret=0 else local revision_options - __git_setup_revision_options + __git_setup_revision_options -d _arguments -S -s \ $revision_options \ @@ -783,6 +783,7 @@ _git-diff () { _arguments -C -s $endopt \ $* \ $diff_options \ + '--exit-code[report exit code 1 if differences, 0 otherwise]' \ '(--exit-code)--quiet[disable all output]' \ $diff_stage_options \ '(--cached --staged)--no-index[show diff between two paths on the filesystem]' \ @@ -974,6 +975,7 @@ _git-format-patch () { '--interdiff=[insert interdiff against previous patch series in cover letter or single patch]:reference to tip of previous series:__git_revisions' \ '--range-diff=[insert range-diff against previous patch series in cover letter or single patch]:reference to tip ot previous series:__git_revisions' \ '--creation-factor=[for range-diff, specify weighting for creation]:weighting (percent)' \ + '--force-in-body-from[show in-body From: even if identical to the e-mail header]' \ ': :->commit-or-commit-range' && ret=0 case $state in @@ -4096,7 +4098,7 @@ _git-blame () { declare -A opt_args declare -a revision_options - __git_setup_revision_options + __git_setup_revision_options -d # TODO: Not sure about __git_cached_files. _arguments -C -S -s $endopt \ @@ -5344,8 +5346,11 @@ _git-diff-index () { # to given tree-ish? This should be done for git-diff as well, in that case. _arguments -S \ $revision_options \ + '--exit-code[report exit code 1 if differences, 0 otherwise]' \ + '(--exit-code)--quiet[disable all output]' \ "--cached[don't consider the work tree at all]" \ '-m[flag non-checked-out files as up-to-date]' \ + '--merge-base[use merge base instead of comparing directly]' \ ': :__git_tree_ishs' \ '*: :__git_cached_files' } @@ -5362,16 +5367,18 @@ _git-diff-tree () { # __git_setup_revision_options, but only used by this command, so only have # them here. _arguments -C -S -s \ - $revision_options \ + ${revision_options:#*--cc\[*} \ + '--exit-code[report exit code 1 if differences, 0 otherwise]' \ + '(--exit-code)--quiet[disable all output]' \ '-r[recurse into subdirectories]' \ '(-r )-t[display tree objects in diff output]' \ '--root[display root diff]' \ + '--merge-base[use merge base instead of comparing directly]' \ '-m[do not ignore merges]' \ '-s[do not show differences]' \ '(--pretty --header)-v[display commit message before differences]' \ '--no-commit-id[do not display commit IDs]' \ - '(-c --cc)-c[show differences from each of parents to merge result]' \ - '(-c --cc)--cc[how differences from each of parents and omit differences from only one parent]' \ + '(-c)--cc[combined diff format for merge commits, further omitting uninteresting hunks]' \ '--combined-all-paths[show name of file in all parents for combined diffs]' \ '--always[always show commit itself and commit log message]' \ ': :__git_tree_ishs' \ @@ -5560,7 +5567,7 @@ _git-rev-list () { declare -A opt_args declare -a revision_options - __git_setup_revision_options + __git_setup_revision_options -d _arguments -C -S $endopt \ $revision_options \ @@ -7691,8 +7698,9 @@ __git_setup_diff_options () { local exclusive_diff_options='(--name-only --name-status --check -s --no-patch)' diff_options=( - {-p,-u,--patch}'[generate diff in patch format]' - {-U,--unified=}'[generate diff with given lines of context]: :__git_guard_number lines' + '(-p -u --patch)'{-p,-u,--patch}'[generate diff in patch format]' + '(-U --unified -W --function-context)'{-U-,--unified=-}'[generate diff with given lines of context]:: :__git_guard_number lines' + '(-U --unified -W --function-context)'{-W,--function-context}'[show whole function where a match was found]' \ '--raw[generate default raw diff output]' '--patch-with-raw[generate patch but also keep the default raw diff output]' $exclusive_diff_options{-s,--no-patch}'[suppress diff output]' @@ -7773,7 +7781,6 @@ __git_setup_diff_options () { '--output-indicator-new=[specify the character to indicate a new line]:character [+]' '--output-indicator-old=[specify the character to indicate a old line]:character [-]' '--output-indicator-context=[specify the character to indicate a context line]:character [ ]' - '--exit-code[report exit code 1 if differences, 0 otherwise]' '( --no-ext-diff)--ext-diff[allow external diff helper to be executed]' '(--ext-diff )--no-ext-diff[disallow external diff helper to be executed]' '(--textconv --no-textconv)--textconv[allow external text conversion filters to be run when comparing binary files]' @@ -7784,7 +7791,10 @@ __git_setup_diff_options () { '--line-prefix=[prepend additional prefix to every line of output]:prefix' '(--src-prefix --dst-prefix)--no-prefix[do not show any source or destination prefix]' '(-c --cc)'{-c,--cc}'[combined diff format for merge commits]' - '--output=[output to a specific file]: :_files') + '--output=[output to a specific file]: :_files' + '--expand-tabs=-[replace each tab with spaces]::tab width [8]' + '!(--expand-tabs)--no-expand-tabs' + ) } (( $+functions[__git_setup_diff_stage_options] )) || @@ -7894,11 +7904,15 @@ __git_format_placeholders() { (( $+functions[__git_setup_revision_options] )) || __git_setup_revision_options () { - local -a diff_options - __git_setup_diff_options + if [[ $1 = "-d" ]]; then # don't include diff options if passed -d + revision_options=() + else + local -a diff_options + __git_setup_diff_options + revision_options=( $diff_options ) + fi - revision_options=( - $diff_options + revision_options+=( '(-v --header)'{--pretty=-,--format=-}'[pretty print commit messages]::format:__git_format_placeholders' '(--abbrev-commit --no-abbrev-commit)--abbrev-commit[show only partial prefixes of commit object names]' '(--abbrev-commit --no-abbrev-commit)--no-abbrev-commit[show the full 40-byte hexadecimal commit object name]'