From patchwork Thu Dec 19 15:09:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11303847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 060C514E3 for ; Thu, 19 Dec 2019 15:09:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8A0221D7D for ; Thu, 19 Dec 2019 15:09:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NuUj/gzW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726847AbfLSPJi (ORCPT ); Thu, 19 Dec 2019 10:09:38 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:42585 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbfLSPJh (ORCPT ); Thu, 19 Dec 2019 10:09:37 -0500 Received: by mail-ed1-f68.google.com with SMTP id e10so5185539edv.9 for ; Thu, 19 Dec 2019 07:09:36 -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=sMOsSTcUib/0Oo6jSASJfIPkvF/od7VhhAhfKVBa5BM=; b=NuUj/gzW2uWBL7ni4y6q8EjZPUNKFhPIkFjMhr5DNNh3ewhC/QHfhkgiYhDiOy1WKA 1L5Nnge44M0l5sAZr+Wc99Es3rPNpbe3Zt+bTQoQe3LSYi0DQ2DcJT5+Kq3nJSf6TJA4 Dsv8xfQaBkTTuaeV4/ZPV9K5OH3q3CKuY70DqrHSfiuOffSAFWSJYaoolf4Timqff/AL 9pODNkmCLU8hQauTYVTB/NbqB9QQYRL3V1xqMeYLtLh+d7MkqeYPedumcb6J1xuSKihe 3tYBdEuBdM8937c1g6twWEnBSMu1WuzgIG48fvXyq5LQILXtUKr73sM4136lcoa3LESv a3zA== 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=sMOsSTcUib/0Oo6jSASJfIPkvF/od7VhhAhfKVBa5BM=; b=DktJRx5Dyej7MUMNUZgZvlAy7qBo2muT8YRoLL5nEUrhzcr5bjMd6x0DMJB9etLf3f MKRoOp1wvmsi1ykbRwnUKn60M9j5eVWFZfxuEeuK/2qj5Y9zR2wvinNiW2XGNfgPG6JR he6AkmirE730OaBsK8vR6Wi50KwaD1MQwZJqZ3fpFP3pCGdMs9i2xLyxRZ26BQ9CTvaf B2eONVmy4Z8vxWgnnYFZJVAbIUg8t2w3R8DkDbwkVlbu3zzoIyhjJZItIx0JO6HAn4YL qpJKGYV7DNfjjaIY5ZDiEzT+/e1OTzzJfyBl3ABHU9IvvwoDwR1ZNLMbr4SxBKEF7Y5w i7Eg== X-Gm-Message-State: APjAAAWvrw0KcITkAjEs0wlHwO6ETLKFSwVTbW05TcUrxQBkTOrJ1M9n ztnuQDG2W/P2gmmri+Oi4PU= X-Google-Smtp-Source: APXvYqyjBsXuDRlQEvlz8mJgFkWf1DuosXc/8NOmxCk6avEIeIWSlaSRKIFi1oQjyGW51Tp4eQvRgw== X-Received: by 2002:a17:906:4089:: with SMTP id u9mr10139932ejj.205.1576768176343; Thu, 19 Dec 2019 07:09:36 -0800 (PST) Received: from localhost.localdomain (x4db583fb.dyn.telefonica.de. [77.181.131.251]) by smtp.gmail.com with ESMTPSA id b27sm546584ejg.40.2019.12.19.07.09.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Dec 2019 07:09:35 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Eric Sunshine , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 1/6] t9902-completion: add tests for the __git_find_on_cmdline() helper Date: Thu, 19 Dec 2019 16:09:16 +0100 Message-Id: <20191219150921.5889-2-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.1.982.ga4d4aba446 In-Reply-To: <20191219150921.5889-1-szeder.dev@gmail.com> References: <20191017173501.3198-1-szeder.dev@gmail.com> <20191219150921.5889-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The following two patches will refactor and extend the __git_find_on_cmdline() helper function, so let's add a few tests first to make sure that its basic behavior doesn't change. Signed-off-by: SZEDER Gábor --- t/t9902-completion.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 54f8ce18cb..847ce601d2 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1363,6 +1363,34 @@ test_expect_success 'teardown after path completion tests' ' BS\\dir '$'separators\034in\035dir'' ' +test_expect_success '__git_find_on_cmdline - single match' ' + echo list >expect && + ( + words=(git command --opt list) && + cword=${#words[@]} && + __git_find_on_cmdline "add list remove" >actual + ) && + test_cmp expect actual +' + +test_expect_success '__git_find_on_cmdline - multiple matches' ' + echo remove >expect && + ( + words=(git command -o --opt remove list add) && + cword=${#words[@]} && + __git_find_on_cmdline "add list remove" >actual + ) && + test_cmp expect actual +' + +test_expect_success '__git_find_on_cmdline - no match' ' + ( + words=(git command --opt branch) && + cword=${#words[@]} && + __git_find_on_cmdline "add list remove" >actual + ) && + test_must_be_empty actual +' test_expect_success '__git_get_config_variables' ' cat >expect <<-EOF && From patchwork Thu Dec 19 15:09:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11303849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E509F14F6 for ; Thu, 19 Dec 2019 15:09:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C28C1218AC for ; Thu, 19 Dec 2019 15:09:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PYzh4R1x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbfLSPJk (ORCPT ); Thu, 19 Dec 2019 10:09:40 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:45885 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbfLSPJj (ORCPT ); Thu, 19 Dec 2019 10:09:39 -0500 Received: by mail-ed1-f67.google.com with SMTP id v28so5172599edw.12 for ; Thu, 19 Dec 2019 07:09:38 -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=YHLrGWWVsIYzZ9gOiB4l/Hc43a9dJKvUWEfhR3t/WNg=; b=PYzh4R1xsvV6VstP1DpXAaLsQ+CC2vXbY0YM3MkhXY+ZYtBlC+BxaDMxsmpbKw4tuN GohI2WboN2iW5UIkWvt2SM0eHhTQRnRPfYFHAVR1Zk5vmDD+3qigNhqpOKiJFg2EkKt0 zg/xHAZBShcbafR5v9/TA7eOHcK2zcNd1K2s37rgYN2ZHD5IjMe8e/KikP7EXinSZ4lk /xSD7a/d38jA/UE7ihWnEPclqyRepu2iDHbFwPZ/lXmIgqancfhndQgJbkDijCa+jy4o kWhkPosWEeI5XjzBlyZq+VwnJxWU2PYHDoe3/eg4Z7sDNm6MwRUCub3JOp4Qm81woJJu s9vQ== 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=YHLrGWWVsIYzZ9gOiB4l/Hc43a9dJKvUWEfhR3t/WNg=; b=gcSvFEds0htUtBfljG8YhbtOLuJqm+AeOaVGcfi/BtSrqyNDYa63vVah0NTgccWVql cgN3UkrjO5AIkqLS2l00FcBp0xEWq3jjYRT2S49krv0i7k4hGN8FuP9JlvhfPGXQXbuE 4L31cowPwX8qLXDo1h1z/iogu2f2fRZ4cjsOh+bUunNOZqIS2YY2SzLhs02+Igrgzmc5 iR8eQdt+FWC3kNtR9AR1tncv5jwjrSshxPhvaJ06JUve1pVHTap3zHFQJ2pa39BaJrL7 06zhPaO0ezvRvlWCAqvQOCE8zPrsIxzbSoHsrMm2lDmJh7qje/+xeSTouyo7oFvNpLt3 yP6w== X-Gm-Message-State: APjAAAWU+pq+XgSz2vkUYt2SoHDK37BrSackU6IDdW6fg0LWsnGJH6YJ M9KfsFsxkUTgyEUYzgJgMN98MTgZ X-Google-Smtp-Source: APXvYqzW7PGiQgVlEMq6vc2V3xKC1NHGzz0lSphUf2h+tfqmxQKHYkYUOjpzlOM4YWOA28mkDv1gpA== X-Received: by 2002:a17:906:27d3:: with SMTP id k19mr9949153ejc.290.1576768178319; Thu, 19 Dec 2019 07:09:38 -0800 (PST) Received: from localhost.localdomain (x4db583fb.dyn.telefonica.de. [77.181.131.251]) by smtp.gmail.com with ESMTPSA id b27sm546584ejg.40.2019.12.19.07.09.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Dec 2019 07:09:37 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Eric Sunshine , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 2/6] completion: clean up the __git_find_on_cmdline() helper function Date: Thu, 19 Dec 2019 16:09:17 +0100 Message-Id: <20191219150921.5889-3-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.1.982.ga4d4aba446 In-Reply-To: <20191219150921.5889-1-szeder.dev@gmail.com> References: <20191017173501.3198-1-szeder.dev@gmail.com> <20191219150921.5889-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The __git_find_on_cmdline() helper function started its life as __git_find_subcommand() [1], but it served a more general purpose than looking for subcommands, so later it was renamed accordingly [2]. However, that rename didn't touch the body of the function, and left the $subcommand local variable behind, still reminiscent of the function's original purpose. Let's clean up the names of __git_find_on_cmdline()'s local variables and get rid of that $subcommand variable name. While at it, add a short comment describing the function's purpose. [1] 3ff1320d4b (bash: refactor searching for subcommands on the command line, 2008-03-10), [2] 918c03c2a7 (bash: rename __git_find_subcommand() to __git_find_on_cmdline(), 2009-09-15) Signed-off-by: SZEDER Gábor --- contrib/completion/git-completion.bash | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 00fbe6c03d..2384f91e78 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1070,14 +1070,17 @@ __git_aliased_command () } # __git_find_on_cmdline requires 1 argument +# Check whether one of the given words is present on the command line, +# and print the first word found. __git_find_on_cmdline () { - local word subcommand c=1 + local word c=1 + local wordlist="$1" + while [ $c -lt $cword ]; do - word="${words[c]}" - for subcommand in $1; do - if [ "$subcommand" = "$word" ]; then - echo "$subcommand" + for word in $wordlist; do + if [ "$word" = "${words[c]}" ]; then + echo "$word" return fi done From patchwork Thu Dec 19 15:09:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11303851 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C118814F6 for ; Thu, 19 Dec 2019 15:09:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EE7A21D7D for ; Thu, 19 Dec 2019 15:09:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MH4KYNfu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726874AbfLSPJl (ORCPT ); Thu, 19 Dec 2019 10:09:41 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:43477 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726855AbfLSPJl (ORCPT ); Thu, 19 Dec 2019 10:09:41 -0500 Received: by mail-ed1-f66.google.com with SMTP id dc19so5176657edb.10 for ; Thu, 19 Dec 2019 07:09:39 -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=p+gm8hi+B2+57fpj63eg+nE8Lr5sFnGuz2vJzMEg9l8=; b=MH4KYNfuoZUlAslXQCsPRF+C3LwH3/CeN7Pm/9vjMLbTi5hg2YUNu+PXPFgN4V0eOn K+PeKiWTL2cu+WkNDN8jBkHEKRQ455TAARMgGSPVAmg43NiQr6fgul2tEGQSL3kB4jJd 6fFozeeN3YpULrBUzkv4o+RAT1VIjo7eOqDa/657vGOSYP+F360mjUvQEkpD11B/91Le tfb4H1eqXikD/3kQbSJwyv8OMn+tUlFfLy5UockKVUlBHUAjiH/FB2Ayy65BIXDNosYr x467U00zUNZU+IFgYWagagjtiFSgFB/rliiLODiksqBvxlKloBFRknbkXCSmSWDIe/ZP eFKg== 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=p+gm8hi+B2+57fpj63eg+nE8Lr5sFnGuz2vJzMEg9l8=; b=rBnlS9RrbPYQa9wS9c0UDKkLX8nmB18XEiq2zjZ6HCDNYCclbUoqSyk+mv/zqInQRJ /r6Eecg87KzsLPm1wkYBDXHZ6mi1jHQ1jaZp8IBYkwkFtOFAGPWFFJHvFJyoOemhRXmv R47bwM7cSOlx3rDwEOOY94OGGcnRcMAJZIw93KGeHOvIBe7TD7oOJQxFjQJJPHFM3uG0 mEKdV6oCSpjJbn9JmSecbhnu9S4gF9bUqJcgJjWFUjVjhpvsytqrzPxPzvHt0jTNW6Wi PMqINfjqaiqYb8pc0RwhbYmMY/YCnvHikB7D5LUyJ4vLY6mmuJ7saB9WUhDUCvA15OkZ IyMQ== X-Gm-Message-State: APjAAAXGG+YCX8JqD++sB2ymliUmqegYiFJCy5go/6O1Upe0vUFaBPw5 g8ltiX85CbF4nMcVj+e0xnI= X-Google-Smtp-Source: APXvYqzgDvA6c9rN803qAFiFhtgq7ld0TGXZ+WzWnprMu4oaD6QIqDyGnVen0lHOQ4brIsbJ0EA1OA== X-Received: by 2002:a17:906:3299:: with SMTP id 25mr10016454ejw.118.1576768179270; Thu, 19 Dec 2019 07:09:39 -0800 (PST) Received: from localhost.localdomain (x4db583fb.dyn.telefonica.de. [77.181.131.251]) by smtp.gmail.com with ESMTPSA id b27sm546584ejg.40.2019.12.19.07.09.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Dec 2019 07:09:38 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Eric Sunshine , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 3/6] completion: return the index of found word from __git_find_on_cmdline() Date: Thu, 19 Dec 2019 16:09:18 +0100 Message-Id: <20191219150921.5889-4-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.1.982.ga4d4aba446 In-Reply-To: <20191219150921.5889-1-szeder.dev@gmail.com> References: <20191017173501.3198-1-szeder.dev@gmail.com> <20191219150921.5889-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When using the __git_find_on_cmdline() helper function so far we've only been interested in which one of a set of words appear on the command line. To complete options for some of 'git worktree's subcommands in the following patches we'll need not only that, but the index of that word on the command line as well. Extend __git_find_on_cmdline() to optionally show the index of the found word on the command line (IOW in the $words array) when the '--show-idx' option is given. Signed-off-by: SZEDER Gábor --- contrib/completion/git-completion.bash | 20 +++++++++++++++--- t/t9902-completion.sh | 29 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 2384f91e78..55a2d3e174 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1069,18 +1069,32 @@ __git_aliased_command () done } -# __git_find_on_cmdline requires 1 argument # Check whether one of the given words is present on the command line, # and print the first word found. +# +# Usage: __git_find_on_cmdline [