From patchwork Wed Dec 30 23:29:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11993747 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 357CBC433E0 for ; Wed, 30 Dec 2020 23:30:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE48D207A9 for ; Wed, 30 Dec 2020 23:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726337AbgL3Xaf (ORCPT ); Wed, 30 Dec 2020 18:30:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbgL3Xae (ORCPT ); Wed, 30 Dec 2020 18:30:34 -0500 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F215C061575 for ; Wed, 30 Dec 2020 15:29:54 -0800 (PST) Received: by mail-ot1-x329.google.com with SMTP id q25so16777880otn.10 for ; Wed, 30 Dec 2020 15:29:54 -0800 (PST) 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=LYMFb60oj1ozuA3IBJgnIIJ4JjKCmOzQUHPrcHLsidA=; b=tPDB8Dg7acMpAsFdB0++PMprhaRnYqC+bxAV4OO9F7u9qZxpohRLD6AQi8qWwIMg9x TD3b3lD1TaLt9k5wbClNw3TX+NOLrWc4TmewTrjBuQziWXAraHn99y8AzVTfJ4N5ddYK DK58coZ5Sq5a8TpsBq8HfvRLnvnxeHLjEpr5mLYY5DqTY+haLN0ZG0PtPz39unXfFcZk UQAF6g/U699Xy9TH3KBzqBCLXqiBq8YhiYEIJBR1/gitcMG4f9GHKfVRmG8xMwIiYDor 8cGi76R7+ETiCN4Vnopscs6hNP27XB2RVi1wY52NDB6dkMuOfyouU3rnbkFB0l9pimbK 7aEg== 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=LYMFb60oj1ozuA3IBJgnIIJ4JjKCmOzQUHPrcHLsidA=; b=DAIm6K6SJcioD/CWskji94cc88P7VCQ0sFZ6lQwnP39HswAYyNfeVnS1EhbVJzxq3z K95g0UO9veRSFA8w4zeYRU/lNkmDloEUIacnok1GVcmOq2tSZ/e1ssxM+V7s6YjiIUc+ lEacddExoBUt9ubsaNV9mS3fADlnIvXs+40pIoGlb6ecIqKyWwBmF+LS5nao/RkCnGe4 tyCuJVVHvRN89Z/r+dp0FazIC8muj6a5ASS1+g4Vwkcx41Jig1kic+mHM4cgT7tv5hzL RXwrFlN/5R78yivUaTRtmZz2fc18lGnCDtKzZlkHxENdzBxCC84h37e93VaexOzReUvZ 5b3A== X-Gm-Message-State: AOAM531FqgbGRhyuK3OqyM2AkRdmJ0LFVdTbCbI/YaVojR1QSCJFkkTy HEm1+LOL83VoUSGXYLTL79gptNK/dm3NLw== X-Google-Smtp-Source: ABdhPJwLyNzrB4nRwHnc1jCihK5jfwj9VwypyxCsdpWQzmbKKpW+GLXr+oiT2h6XkWXbOQwKTJ8f8w== X-Received: by 2002:a05:6830:10d1:: with SMTP id z17mr39693544oto.156.1609370993735; Wed, 30 Dec 2020 15:29:53 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id t24sm9640258oij.7.2020.12.30.15.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 15:29:53 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano , Jonathan Nieder , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Ren=C3=A9_Scharfe?= , Denton Liu , Felipe Contreras Subject: [PATCH v3 1/4] completion: bash: add __git_have_func helper Date: Wed, 30 Dec 2020 17:29:47 -0600 Message-Id: <20201230232950.582152-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230232950.582152-1-felipe.contreras@gmail.com> References: <20201230232950.582152-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This makes the code more readable, and also will help when new code wants to do similar checks. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 463a3124da..869c73ee2c 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3358,15 +3358,19 @@ __git_support_parseopt_helper () { esac } +__git_have_func () { + declare -f $1 >/dev/null 2>/dev/null +} + __git_complete_command () { local command="$1" local completion_func="_git_${command//-/_}" - if ! declare -f $completion_func >/dev/null 2>/dev/null && - declare -f _completion_loader >/dev/null 2>/dev/null + if ! __git_have_func $completion_func && + __git_have_func _completion_loader then _completion_loader "git-$command" fi - if declare -f $completion_func >/dev/null 2>/dev/null + if __git_have_func $completion_func then $completion_func return 0 From patchwork Wed Dec 30 23:29:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11993745 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 42D8EC433DB for ; Wed, 30 Dec 2020 23:30:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EC93207AB for ; Wed, 30 Dec 2020 23:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726390AbgL3Xah (ORCPT ); Wed, 30 Dec 2020 18:30:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbgL3Xah (ORCPT ); Wed, 30 Dec 2020 18:30:37 -0500 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 101B1C061799 for ; Wed, 30 Dec 2020 15:29:57 -0800 (PST) Received: by mail-ot1-x332.google.com with SMTP id w3so16792661otp.13 for ; Wed, 30 Dec 2020 15:29:57 -0800 (PST) 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=aCMgXY3vpMqUcC3T7M7K4A9kovLqoa1ejdPojoT23z8=; b=A128VblPAZm/Sb1wvtYye7bXzVlzzPMdIWvS11nK+kTww7D79M+xKwbbVcueJ68dLg ceLSav+dA+9P5XD8/Amo3636pXDH1o0qS3Vn5VCAXT2nKBG3Ywz9+UCRaBKIASBlTq1V 0VEcDy6o1JUIpWBL3B3NRvZlZIWdL1M6BuROBp7wVviYQX8Q+VPBHJaPSP5NwwX1PPus G5IMI9rOMgomxWeerUarSHqEpm2LvDkbS8ZXTVe02nSDrQqMSXo0kwx3bxGf3q1BQ5UV 0YVTKzrIOQT6+1lz/w0JwWkoffIDmkE9sCqcjFCJjok56d7HmwZ6AQDF0huq4dCc+HeS n/kA== 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=aCMgXY3vpMqUcC3T7M7K4A9kovLqoa1ejdPojoT23z8=; b=MV9WuCx5cwu7bdKG91htrj0T/BIpZbCzQ2Xf0GBgCUOI2OSLLIeNP+V/v/zfAiKOfN 4dn1LnATZYqoKq37E3lG3FZnv6cXbYLuC/PN/rk0EjSgN3NKc4+K08Cq4n0A2lfp6mJp Um2Ci02PYeW66TWWA3sw0oyBNzd1SdkoTCfuPDcjtEh4cEoyTPYR2kO0kKswZrtyF4hF 9K3l/e2+YutWHTZl9LcZ8C9QxsGRUaqDni4khBHqlGh5HzCeniK0tg88wXg1Jda86PUn /YfplgDVN8gNtRlBuKDIxbHUzWrFeixOqJL+e8MtdA/+IVy0ele1agWG+Ym2/4UHCKYv KE6w== X-Gm-Message-State: AOAM533nQINAB8+BJfYPR87Haa7m5hraN280PpspSwO+jIueNLvoYq/r 6NyuF55jHPynaUBlus/wWmbENPLLGx7zhA== X-Google-Smtp-Source: ABdhPJyEiC7Z8B8hshvw9HB+lZLgU3+qvN8wyQxW9I4iynfFMD+5M7yQ6vkEc3/pWhmE0Ape5asQzw== X-Received: by 2002:a05:6830:19ca:: with SMTP id p10mr40738516otp.233.1609370995581; Wed, 30 Dec 2020 15:29:55 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id h7sm10907457otq.21.2020.12.30.15.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 15:29:55 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano , Jonathan Nieder , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Ren=C3=A9_Scharfe?= , Denton Liu , Felipe Contreras Subject: [PATCH v3 2/4] completion: bash: improve function detection Date: Wed, 30 Dec 2020 17:29:48 -0600 Message-Id: <20201230232950.582152-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230232950.582152-1-felipe.contreras@gmail.com> References: <20201230232950.582152-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 1. We should quote the argument 2. We don't need two redirections 3. A safeguard for arguments (-a) would be good Suggested-by: René Scharfe Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 869c73ee2c..1150d4bf44 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3359,7 +3359,7 @@ __git_support_parseopt_helper () { } __git_have_func () { - declare -f $1 >/dev/null 2>/dev/null + declare -f -- "$1" >/dev/null 2>&1 } __git_complete_command () { From patchwork Wed Dec 30 23:29:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11993749 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 4F95AC433E6 for ; Wed, 30 Dec 2020 23:30:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24D22207AF for ; Wed, 30 Dec 2020 23:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726422AbgL3Xai (ORCPT ); Wed, 30 Dec 2020 18:30:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbgL3Xai (ORCPT ); Wed, 30 Dec 2020 18:30:38 -0500 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28E72C06179B for ; Wed, 30 Dec 2020 15:29:58 -0800 (PST) Received: by mail-oi1-x22b.google.com with SMTP id s2so20338006oij.2 for ; Wed, 30 Dec 2020 15:29:58 -0800 (PST) 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=BHfDTQko7xjogX2qIZ9vgKqkR01FLXLg1Z25DmZlx8U=; b=kjc7HkqsPTumoGuZiW8z6WRUBmP6ASQ8/ha0iLv1ixlbDqtIvgPOnyJB6RXrjYyMAj l0ULKenl7Hs+qCil6bqJL53k6gdc3+ZnuYZ7kqpar1F5mwh/2z+CqRm+u52kYdgeSEVK KQDqOVyCSk3q8wIHjv9S8cWbBwLbJXintZsZPXMFvmHX0+i878l52XH0zRx8n9LSXb5l JI9/f+zWefEAIMn8yOrWyGNAGPrWgcqHQ2ioYxFszyvTOL2uzh/giQUhLaajK+9cvl8m 283eMrRnKxGhI7k8tDdOFcXvxfrIGn5XPqErKL4uJsThmxnepAktVbGo/X5s7ys87Uaq w1sw== 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=BHfDTQko7xjogX2qIZ9vgKqkR01FLXLg1Z25DmZlx8U=; b=J+7ZLNqcXBtnRKDp0674jmmyn3qbCEpCwsNGQsmcrHfGrZTjrr9qw14LD5yMEAPIx+ itooF0OXtvMLAXCkzGvPJo0gdUlM+Cw6CVEJhBwDIkQJfYXPhh0MUJK8Zw+ABGVj+cJb iVav2+tBJuYxfdF975C4YasDVHKSDPFoLfo/8XXCMIrSy6oEZXfqZnnL+u53yG+ysz4w 9phJfInlnkrDYbXH8D13b6ROPM0afJSq/IanE7cjn1p0yhS8n0i5y2SGzE+r+KL3CHg8 dw1Uz2BGJrkCyW0+5ynnxE7hz4Vt5Y0H3waVarKN5JJFDxzOghCTnuzh5/jxYUKytpdl SZ+Q== X-Gm-Message-State: AOAM532Luz43iq/ZKWgIFJ3yXNMcQgL7mwHrtMHjK345CffbX4ZYxP92 yK2LzpGgA1+KAmHOSLtE4Ioyw41Kmp10pw== X-Google-Smtp-Source: ABdhPJzqpY37FGl1dh3VoxovZtMDQ1EdQ2NELicGpOp1drDFeLUVRFRxUrVZIXGLnrduP7zXJ100uw== X-Received: by 2002:aca:4c4f:: with SMTP id z76mr6652135oia.1.1609370997357; Wed, 30 Dec 2020 15:29:57 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id i25sm10738032oto.56.2020.12.30.15.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 15:29:56 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano , Jonathan Nieder , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Ren=C3=A9_Scharfe?= , Denton Liu , Felipe Contreras Subject: [PATCH v3 3/4] test: completion: add tests for __git_complete Date: Wed, 30 Dec 2020 17:29:49 -0600 Message-Id: <20201230232950.582152-4-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230232950.582152-1-felipe.contreras@gmail.com> References: <20201230232950.582152-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Even though the function was marked as not public, it's already used in the wild. We should at least test basic functionality. Signed-off-by: Felipe Contreras --- t/t9902-completion.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index a1c4f1f6d4..c0b4380eae 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2380,4 +2380,12 @@ test_expect_success 'sourcing the completion script clears cached --options' ' verbose test -z "$__gitcomp_builtin_notes_edit" ' +test_expect_success '__git_complete' ' + unset -f __git_wrap__git_main && + __git_complete foo __git_main && + __git_have_func __git_wrap__git_main && + __git_complete gf _git_fetch && + __git_have_func __git_wrap_git_fetch +' + test_done From patchwork Wed Dec 30 23:29:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11993751 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 66751C433E9 for ; Wed, 30 Dec 2020 23:30:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D3B1207A9 for ; Wed, 30 Dec 2020 23:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726462AbgL3Xak (ORCPT ); Wed, 30 Dec 2020 18:30:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbgL3Xak (ORCPT ); Wed, 30 Dec 2020 18:30:40 -0500 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3843BC06179C for ; Wed, 30 Dec 2020 15:30:00 -0800 (PST) Received: by mail-ot1-x331.google.com with SMTP id n42so16768400ota.12 for ; Wed, 30 Dec 2020 15:30:00 -0800 (PST) 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=smZocRqMF3CWtA6vOntnj7QESILxz+VTtrQ1xn/eGzc=; b=rRQMFHjNQ8/UivvPNbfbwgS8belHyb3JURuPFH/pdqBbt3muh3s/jmfjo3sd+iHIsW oLXFtLUm1IE/WES3qO4AbaErdt/EoRCh/aD1osk2htLFmpBWWySdJYoV44UuqKr5xsu0 MvcKOOYucaKJCBslHwNrAPr0cfP/ZQTJxGhV4xBFyXrHTWpmEn9PYDuqrwQBvX78fllF YLdgmK+XXmGJFHOkK7KZXNJQyQ86CxZOKl5/yG4Qgp4SdfkoxwGy05LY0PAqixwFrFDo URVa874qxwtG8uFSEwofpnISJG6UIqeyJslXc0Hv1bFXcaPfnlNmh2peDLaBT3yZmOk5 TxrA== 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=smZocRqMF3CWtA6vOntnj7QESILxz+VTtrQ1xn/eGzc=; b=p96qFCguiYjUidG2nn8sCOnFPSkdC2n4w8DE5NkNvdKi3De2vACvcTUr2xK+w01OmB 19z16UO/nQqyHnPsuLvM0x0q7z4cs00fsWb++F9/YBghRH1DcdcbEvQB5DAZSiHmY76S 8aZwhowABOMM9co9Sva66syOyVlz7lCRbLJuK5heiNMuYWySoGDx+8XhqyLgI2eaCxer pYGQBal4VSmNMBuvVAEZGOFXHkkHiFdg+ik92MJHVEmxyjR3TVCrwE9nfArk8bklsq9r OOEAo7fXG++sDNiYpJJER656i3ecsh+1r2qu8PrQFTmhhsGyMSI9DOVXFVj7QxvoLIfs U+Og== X-Gm-Message-State: AOAM530D/WiU8xSTYYqLwRs15pe+lP3UN0Mj6LGuv4HZlwuz0HPsVXXr tvAgHOTRmLC/SGPaSFgKHRJ6+0VM82rsaQ== X-Google-Smtp-Source: ABdhPJy6ehxs0034w7ABpSx/zpRt3or3WDTPkpMVE4wt8fiY5Pif33clIT+uMjQOdPmV3jkR3JGmcw== X-Received: by 2002:a9d:19aa:: with SMTP id k39mr21442231otk.28.1609370999311; Wed, 30 Dec 2020 15:29:59 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id t24sm10674156oou.4.2020.12.30.15.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 15:29:58 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano , Jonathan Nieder , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Ren=C3=A9_Scharfe?= , Denton Liu , Felipe Contreras Subject: [PATCH v3 4/4] completion: add proper public __git_complete Date: Wed, 30 Dec 2020 17:29:50 -0600 Message-Id: <20201230232950.582152-5-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230232950.582152-1-felipe.contreras@gmail.com> References: <20201230232950.582152-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When __git_complete was introduced, it was meant to be temporarily, while a proper guideline for public shell functions was established (tentatively _GIT_complete), but since that never happened, people in the wild started to use __git_complete, even though it was marked as not public. Eight years is more than enough wait, let's mark this function as public, and make it a bit more user-friendly. So that instead of doing: __git_complete gk __gitk_main The user can do: __git_complete gk gitk And instead of: __git_complete gf _git_fetch Do: __git_complete gf git_fetch Backwards compatibility is maintained. Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.bash | 40 +++++++++++++++++++++----- t/t9902-completion.sh | 14 ++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 1150d4bf44..4b1f4264a6 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -29,6 +29,15 @@ # tell the completion to use commit completion. This also works with aliases # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". # +# If you have a command that is not part of git, but you would still +# like completion, you can use __git_complete: +# +# __git_complete gl git_log +# +# Or if it's a main command (i.e. git or gitk): +# +# __git_complete gk gitk +# # Compatible with bash 3.2.57. # # You can set the following environment variables to influence the behavior of @@ -3497,10 +3506,7 @@ __git_func_wrap () $1 } -# Setup completion for certain functions defined above by setting common -# variables and workarounds. -# This is NOT a public function; use at your own risk. -__git_complete () +___git_complete () { local wrapper="__git_wrap${2}" eval "$wrapper () { __git_func_wrap $2 ; }" @@ -3508,13 +3514,33 @@ __git_complete () || complete -o default -o nospace -F $wrapper $1 } -__git_complete git __git_main -__git_complete gitk __gitk_main +# Setup the completion for git commands +# 1: command or alias +# 2: function to call (e.g. `git`, `gitk`, `git_fetch`) +__git_complete () +{ + local func + + if __git_have_func $2; then + func=$2 + elif __git_have_func __$2_main; then + func=__$2_main + elif __git_have_func _$2; then + func=_$2 + else + echo "ERROR: could not find function '$2'" 1>&2 + return 1 + fi + ___git_complete $1 $func +} + +___git_complete git __git_main +___git_complete gitk __gitk_main # The following are necessary only for Cygwin, and only are needed # when the user has tab-completed the executable name and consequently # included the '.exe' suffix. # if [ "$OSTYPE" = cygwin ]; then - __git_complete git.exe __git_main + ___git_complete git.exe __git_main fi diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index c0b4380eae..c4a7758409 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2382,10 +2382,22 @@ test_expect_success 'sourcing the completion script clears cached --options' ' test_expect_success '__git_complete' ' unset -f __git_wrap__git_main && + __git_complete foo __git_main && __git_have_func __git_wrap__git_main && + unset -f __git_wrap__git_main && + __git_complete gf _git_fetch && - __git_have_func __git_wrap_git_fetch + __git_have_func __git_wrap_git_fetch && + + __git_complete foo git && + __git_have_func __git_wrap__git_main && + unset -f __git_wrap__git_main && + + __git_complete gd git_diff && + __git_have_func __git_wrap_git_diff && + + test_must_fail __git_complete ga missing ' test_done