From patchwork Wed Mar 24 08:36:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12160513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2119C433C1 for ; Wed, 24 Mar 2021 08:37:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99EEF619F7 for ; Wed, 24 Mar 2021 08:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234028AbhCXIhL (ORCPT ); Wed, 24 Mar 2021 04:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233888AbhCXIgl (ORCPT ); Wed, 24 Mar 2021 04:36:41 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87891C061763 for ; Wed, 24 Mar 2021 01:36:41 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id q11so7540221pld.11 for ; Wed, 24 Mar 2021 01:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wOu7vx20e9QwWcsk8yCbee9+9MMnJbJ02UM9I3Vs1Z8=; b=vbJq1n0PpdcZ0zCU1oUzN/9uEB/583fzP0cOoVjA0+qaagJwZLU2WSS9pzoyE1fZXv SnUIrM5RXBP9IAjSS2tFgAV99TQC7JLANSAATP3WcW1IK5FkIW6rvX8EHwSGn7ixtge8 ClMo0Gmo1U0O2/o37kK6EInydLPFI8wW2EqIhpKDObsxZJHzRXbkzilaSH3tkLKkLYV1 ve+rsoY1Y/KzQrUG1nBPMlFst7hz8ZHlSntUQwdKmNELzCWaY/KlqZiyvxbB7wIl/y0I v/f4uuvTfQcEI/39ePQxJNf4/haFDcRJNxlWqrqR1sX5p535OthT7VI4u5LlUGR8M8O1 H82g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wOu7vx20e9QwWcsk8yCbee9+9MMnJbJ02UM9I3Vs1Z8=; b=gQjWxbYrrRfpKAXEXkwfkNCwgxHGWwCVRBrYPTaLlekARnVoCKK5NOlPPrnnmicQ2Z /kmsUmD1WWvIyOKK5QLbEuqyyl/WwJLjo3gAXObDmN1e4T9Bh5ynGqxRgPdSHL6H7yy4 JgPKjNwbloyUqj07I0j1k/mZuDDTBDtGsael5bi5xVDPfssBmsssRGVKpGyu7M8+1znV 6Fju3oZ0nOm8MWPCU6QutThfJX+3uNRUyRs0QL1xzeNR2CvPuUx5dmJpOPaKeKTkAe96 CWq3Ho9gSOpHZR3W1QyZGgNkC1prfBqziC3eQZglwKwKDS0GPBP5DMENZOepnJvKoOUY 1kjQ== X-Gm-Message-State: AOAM532lyxGQecQvOTBRMgGIC6i+i1iy1GYV63tKt4pcuuyPvuQvKPpa 62gE5hake/NXZYpbgBS0IohfbqZC8rE= X-Google-Smtp-Source: ABdhPJyNYGuE7/GIsQjx08pa9kL1UP5U0zFJrLS1RsHFgpBiYiC4gtuS9ZBKBuHxotzUKJf3MX2K+A== X-Received: by 2002:a17:90b:809:: with SMTP id bk9mr2304537pjb.83.1616575000819; Wed, 24 Mar 2021 01:36:40 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id a15sm1609361pju.34.2021.03.24.01.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 01:36:40 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v2 1/3] git-completion.bash: pass $__git_subcommand_idx from __git_main() Date: Wed, 24 Mar 2021 01:36:27 -0700 Message-Id: X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Many completion functions perform hardcoded comparisons with $cword. This fails in the case where the main git command is given arguments (e.g. `git -C . bundle` would fail to complete its subcommands). Even _git_worktree(), which uses __git_find_on_cmdline(), could still fail. With something like `git -C add worktree move`, the subcommand would be incorrectly identified as "add" instead of "move". Assign $__git_subcommand_idx in __git_main(), where the git subcommand is actually found and the corresponding completion function is called. Use this variable to replace hardcoded comparisons with $cword. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 7dc6cd8eb8..a2f1b5e916 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1474,12 +1474,12 @@ _git_branch () _git_bundle () { - local cmd="${words[2]}" + local cmd="${words[__git_subcommand_idx+1]}" case "$cword" in - 2) + $((__git_subcommand_idx+1))) __gitcomp "create list-heads verify unbundle" ;; - 3) + $((__git_subcommand_idx+2))) # looking for a file ;; *) @@ -1894,7 +1894,7 @@ _git_grep () esac case "$cword,$prev" in - 2,*|*,-*) + $((__git_subcommand_idx+1)),*|*,-*) __git_complete_symbol && return ;; esac @@ -3058,7 +3058,7 @@ _git_stash () branch,--*) ;; branch,*) - if [ $cword -eq 3 ]; then + if [ $cword -eq $((__git_subcommand_idx+2)) ]; then __git_complete_refs else __gitcomp_nl "$(__git stash list \ @@ -3277,11 +3277,9 @@ __git_complete_worktree_paths () _git_worktree () { local subcommands="add list lock move prune remove unlock" - local subcommand subcommand_idx + local subcommand - subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")" - subcommand_idx="${subcommand% *}" - subcommand="${subcommand#* }" + subcommand="$(__git_find_on_cmdline "$subcommands")" case "$subcommand,$cur" in ,*) @@ -3306,7 +3304,7 @@ _git_worktree () # be either the 'add' subcommand, the unstuck # argument of an option (e.g. branch for -b|-B), or # the path for the new worktree. - if [ $cword -eq $((subcommand_idx+1)) ]; then + if [ $cword -eq $((__git_subcommand_idx+2)) ]; then # Right after the 'add' subcommand: have to # complete the path, so fall back to Bash # filename completion. @@ -3330,7 +3328,7 @@ _git_worktree () __git_complete_worktree_paths ;; move,*) - if [ $cword -eq $((subcommand_idx+1)) ]; then + if [ $cword -eq $((__git_subcommand_idx+2)) ]; then # The first parameter must be an existing working # tree to be moved. __git_complete_worktree_paths @@ -3398,6 +3396,7 @@ __git_main () { local i c=1 command __git_dir __git_repo_path local __git_C_args C_args_count=0 + local __git_subcommand_idx while [ $c -lt $cword ]; do i="${words[c]}" @@ -3412,7 +3411,7 @@ __git_main () __git_C_args[C_args_count++]="${words[c]}" ;; -*) ;; - *) command="$i"; break ;; + *) command="$i"; __git_subcommand_idx="$c"; break ;; esac ((c++)) done From patchwork Wed Mar 24 08:36:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12160519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02D2AC433E0 for ; Wed, 24 Mar 2021 08:37:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCE8761A01 for ; Wed, 24 Mar 2021 08:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234041AbhCXIhM (ORCPT ); Wed, 24 Mar 2021 04:37:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233914AbhCXIgn (ORCPT ); Wed, 24 Mar 2021 04:36:43 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77BBDC061763 for ; Wed, 24 Mar 2021 01:36:42 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id ha17so11367767pjb.2 for ; Wed, 24 Mar 2021 01:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pPD7sCID0VXn8yIgbuQ7c1tD2tj8rOHNIJKo8TfsTso=; b=a6ppjBMbxrYjQat0ZAqcT7spbCSgUyh1uptgbrvYugb1aHkOdNdOgb2Z6c9tFWkYrk Q/6YiL/Z+h2DCkC0obtncUjEZuESWpMm8q/R4u8aE7RZGchjaIpTcXT3B/vdQvMV3H0L KsNtU2fO03vyLU3nUaTCjBe78NovzIHBgBoclNTcKG+PJzwksyddSCCbiLLB/pR0q9dF 9suZ70e/gYwSozPy+Ni5WZi8oOa5g29z9re/GjtL8XYuwGBxwCFir/vG7aBFTuy6PTlw tXsG6oIKEWQXLaxuyoMlSPPJWa/daljeIq+VMA9SgernikJR20Aif5QCfifg7W2O6cYA 2/Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pPD7sCID0VXn8yIgbuQ7c1tD2tj8rOHNIJKo8TfsTso=; b=lj3aBOx01QXpzH61zFbL5pXcYZS6qVd52X8Qn90WlD0GPMn2KlORxHc32rh+WBcL/V 11cGVjMjv60+S4Pj2ss5anqS+/J0KP1TFmeB13iY3+cmIiwZEyfpP/p1PWYsrL1f8s// IlsTzWpz+N3GRdbk59UJXaIRFjDtgrOFI1ZLnmkWXyeHxB8PbwUXTYgvkK2WhgEiclfs 0pElX9oYFU1xPbLjvpsLlcAIc31IRLM7fBQ9A/JqaryFBgqTRqCBjkG2jjvPhfe8agGP 952m+0ncUTIj1bvfIIsdEEPxEPo0uw/8wEEGz0ksmHDzg8M7cvYpohIwJoqmvDnVRTBt xH9A== X-Gm-Message-State: AOAM533JyHHLukwHWCE7KLVuHN5rMh5bODZB3C60LN/b1qqzkwM4Xyv+ y87qgGzt2WXdfNYxxwsT0OKZ6Skoozw= X-Google-Smtp-Source: ABdhPJzO6t7f/fe9WcBAzunT0xL9iyzMF6JLDiplEN3qyilFWoEKACvrAZy2TIDMjP0/8cnYWcrlYw== X-Received: by 2002:a17:902:eb11:b029:e4:a5c3:4328 with SMTP id l17-20020a170902eb11b02900e4a5c34328mr2621589plb.7.1616575001868; Wed, 24 Mar 2021 01:36:41 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id a15sm1609361pju.34.2021.03.24.01.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 01:36:41 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v2 2/3] git-completion.bash: extract from else in _git_stash() Date: Wed, 24 Mar 2021 01:36:28 -0700 Message-Id: <430d5acf972f39aa8cfc9b266dd658aabcf1babb.1616574955.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To save a level of indentation, perform an early return in the "if" arm so we can move the "else" code out of the block. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 73 +++++++++++++------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index a2f1b5e916..8d4d8cc0fe 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3035,44 +3035,45 @@ _git_stash () fi ;; esac - else - case "$subcommand,$cur" in - push,--*) - __gitcomp "$save_opts --message" - ;; - save,--*) - __gitcomp "$save_opts" - ;; - apply,--*|pop,--*) - __gitcomp "--index --quiet" - ;; - drop,--*) - __gitcomp "--quiet" - ;; - list,--*) - __gitcomp "--name-status --oneline --patch-with-stat" - ;; - show,--*) - __gitcomp "$__git_diff_common_options" - ;; - branch,--*) - ;; - branch,*) - if [ $cword -eq $((__git_subcommand_idx+2)) ]; then - __git_complete_refs - else - __gitcomp_nl "$(__git stash list \ - | sed -n -e 's/:.*//p')" - fi - ;; - show,*|apply,*|drop,*|pop,*) + return + fi + + case "$subcommand,$cur" in + push,--*) + __gitcomp "$save_opts --message" + ;; + save,--*) + __gitcomp "$save_opts" + ;; + apply,--*|pop,--*) + __gitcomp "--index --quiet" + ;; + drop,--*) + __gitcomp "--quiet" + ;; + list,--*) + __gitcomp "--name-status --oneline --patch-with-stat" + ;; + show,--*) + __gitcomp "$__git_diff_common_options" + ;; + branch,--*) + ;; + branch,*) + if [ $cword -eq $((__git_subcommand_idx+2)) ]; then + __git_complete_refs + else __gitcomp_nl "$(__git stash list \ | sed -n -e 's/:.*//p')" - ;; - *) - ;; - esac - fi + fi + ;; + show,*|apply,*|drop,*|pop,*) + __gitcomp_nl "$(__git stash list \ + | sed -n -e 's/:.*//p')" + ;; + *) + ;; + esac } _git_submodule () From patchwork Wed Mar 24 08:36:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12160517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10AD3C433E1 for ; Wed, 24 Mar 2021 08:37:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8ACC619EC for ; Wed, 24 Mar 2021 08:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234063AbhCXIhN (ORCPT ); Wed, 24 Mar 2021 04:37:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233915AbhCXIgo (ORCPT ); Wed, 24 Mar 2021 04:36:44 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8717C061763 for ; Wed, 24 Mar 2021 01:36:43 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id g15so16806371pfq.3 for ; Wed, 24 Mar 2021 01:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8hPzGPdDYZtIlbuwbtu5eIHsr+yILMTARd22XBhMVvw=; b=CR3zSzXugdKMEkQ3Zz7c4YlFetjjlvepJZ5aI+Y2nWq9JjizW1S8oUDjc/7HRs1ziT Zg+bgYQypsh28P6HWcjvFYGWJlKO6PtkJcITyJELTFERv+J2pth4ZB9GiOOXUdYdK65X jVw0bSGsC4Qyn4nzWEi6lnF1UUxjnkbNhNiEaK15oJbYE8Fw04pkou80fQKgeQfctDVm Tqml9VeLyqvf/wdnUPRPtpPdCNcMByV85tfTATk7m0O06TuEzsCf3dRpAR7StmsHZ4p4 BjwY6EoI573dPql+HRc/nklWXOwAjgvMby0stgID+DqVnlnrGhwfRU/V2AGtr7QNKKAH hQ2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8hPzGPdDYZtIlbuwbtu5eIHsr+yILMTARd22XBhMVvw=; b=VJ/iXYgLtI0AtD+GbY4ai4LezteitkM3QO7lUaZp+/SBwth0v1LOJjtmH7ppaEQOFx +Uwba2fHbMukiiPO0mGJiZYpsYUwJ+QcIxmjgdD/x5r75iyzp4eGi3rLvpoJmA8NeJK/ THZ8nlj1HSXalkOTeNjtJWWPCCLIkL5uE5UVXlSp0kZxdZpBXHDJ1FRt9uahm0w8WG/d DfeJj9cte39dqkCrhyKQCii0veP9wEBGarIYj/wl+WG4Ni8qd7efa1KvMcSOqKWPBjO0 PqHWrOBfd9QgpwB/ofPV7G9B8co9yVYMUehccO6rPah1kVf0XIXizQ8qXxEhcREw6xc6 UxCQ== X-Gm-Message-State: AOAM532LLCc1YDtU8GsS8yxXlKmGjN567am65OpNWsX8nebGWSZ0QakL Ulmogjml/rNWj5pYbZJ9vAVtOEHSRdo= X-Google-Smtp-Source: ABdhPJyG0kzFDetf149Kf8xiDfkrAHpyZodGlckXvaltMXkPy4LvXijxwJBLLF//nQ8Ome2FnzdM8A== X-Received: by 2002:a65:4347:: with SMTP id k7mr2141019pgq.88.1616575002783; Wed, 24 Mar 2021 01:36:42 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id a15sm1609361pju.34.2021.03.24.01.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 01:36:42 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v2 3/3] git-completion.bash: use __gitcomp_builtin() in _git_stash() Date: Wed, 24 Mar 2021 01:36:29 -0700 Message-Id: <680f3a3146355e6b09aa2e0f59471c7695954a1b.1616574955.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The completion for 'git stash' has not changed in a major way since it was converted from shell script to builtin. Now that it's a builtin, we can take advantage of the groundwork laid out by parse-options and use the generated options. Rewrite _git_stash() to take use __gitcomp_builtin() to generate completions for subcommands. The main `git stash` command does not take any arguments directly. If no subcommand is given, it automatically defaults to `git stash push`. This means that we can simplify the logic for when no subcommands have been given yet. We only have to offer subcommand completions when we're completing a non-option after "stash". One area that this patch could improve upon is that the `git stash list` command accepts log-options. It would be nice if the completion for this were unified with that of _git_log() and _git_show() which would allow completions to be provided for options such as `--pretty` but that is outside the scope of this patch. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 42 ++++++++++++-------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8d4d8cc0fe..c926ca26c6 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3013,26 +3013,19 @@ _git_sparse_checkout () _git_stash () { - local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked' local subcommands='push list show apply clear drop pop create branch' local subcommand="$(__git_find_on_cmdline "$subcommands save")" - if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then - subcommand="push" - fi + if [ -z "$subcommand" ]; then - case "$cur" in - --*) - __gitcomp "$save_opts" + case "$((cword - __git_subcommand_idx)),$cur" in + *,--*) + __gitcomp_builtin stash_push ;; - sa*) - if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then - __gitcomp "save" - fi + 1,sa*) + __gitcomp "save" ;; - *) - if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then - __gitcomp "$subcommands" - fi + 1,*) + __gitcomp "$subcommands" ;; esac return @@ -3040,24 +3033,29 @@ _git_stash () case "$subcommand,$cur" in push,--*) - __gitcomp "$save_opts --message" + __gitcomp_builtin stash_push ;; save,--*) - __gitcomp "$save_opts" + __gitcomp_builtin stash_save ;; - apply,--*|pop,--*) - __gitcomp "--index --quiet" + pop,--*) + __gitcomp_builtin stash_pop + ;; + apply,--*) + __gitcomp_builtin stash_apply ;; drop,--*) - __gitcomp "--quiet" + __gitcomp_builtin stash_drop ;; list,--*) - __gitcomp "--name-status --oneline --patch-with-stat" + # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show() + __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options" ;; show,--*) - __gitcomp "$__git_diff_common_options" + __gitcomp_builtin stash_show "$__git_diff_common_options" ;; branch,--*) + __gitcomp_builtin stash_branch ;; branch,*) if [ $cword -eq $((__git_subcommand_idx+2)) ]; then