From patchwork Sat Mar 2 14:37:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13579542 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F806107A6 for ; Sat, 2 Mar 2024 14:37:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709390263; cv=none; b=ntcGjPrFycQfVlmfeV0HeLn3tzmyCkvtH7FSyoc7DidLD0ASGurJ9drqU8tDv6hMbjji9+sDCkebkewBtwtg1+G0IhTOxY5m3YMIVcE3O77dEozkgGPlBa3zEOrBg/01VElaB4eBCMsCIigK4J13v1w7L+nVS8NFZTcVNVSh1Oo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709390263; c=relaxed/simple; bh=R3/aojfXwKwvpbcHAQ6lVTpIeDegistZAX3HjLuNMRY=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=XA3qUm6gI58n3UxM1dtNZWOLT0FP29mvVD0RnpAfzKKz2uJM2tYZVA/VDR0fbVmygyGTxBdlHSNemHy3MYjUjaIA4ssfTD60vnQP3C5B7ZAa3Ss48kMYcCQuvMvgAVjdjPyzHNHuRFKeetGKlyV1UctAJNF92K+S4MtkmlpBKNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SH1nbrbQ; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SH1nbrbQ" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2d24a727f78so34991181fa.0 for ; Sat, 02 Mar 2024 06:37:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709390259; x=1709995059; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=R8tMzxoQNRI8tKk3VpGlWSYH7DZZbWtTbAa4nyfvXsU=; b=SH1nbrbQ25qoH0JtIwylB++JFHs27fOde3lmbd8cRxblv6e33e2hr2B4bwpb+3vS7m fsrvSEzSW8ts+d/7MQcPVoh7fpUuTXiwQABkep3JYuff2SixiaA7qWgOVjdyyFMl9BEx 1cHHboCPgnbEYkPSfGj2uQVdum6Gv+BPK51lXRTfzhVmXYQbec2SQCW7ApUs+u0YJ2qB cQFiCehyFIY5KbHFrOozuaGUVTYFBJumlTHeO/AwUchyEQhN9MRRMqP+n8Hc/+DpfEEq 7m4O11forZpxM5NYRKtDWpfUxlrG3Np2lzUbMTBvPQ3SuKzHTtGFQzQbatT/ayz8kcEC iHYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709390259; x=1709995059; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R8tMzxoQNRI8tKk3VpGlWSYH7DZZbWtTbAa4nyfvXsU=; b=itTPhGv2LpW9KqP7px/g5ZQkW/C1r8/RSxvq/FHuE9f3uqt8kPOX0HQBvupa5ceI+9 rcgyzgJX3AS3SIlLSu0vORtoYeA8oqp8LBi+aA0qZ0QFGoX8csBp8nzAAGXFMPEQ/DPi CU04BCMg57RnEpgE6D6Z4e5TC0JB2lcp7MxreKqHDiig8aPKiRcFJJgvUHOTxPWA+twS 1iR0lAu2oTWQbfdWKjoL9oCM4KV0aSIJ7GsEWMmFxzTquvAOIaQly/U4JopXyGNyrMcW YtS8Rzta7HxSAZT3loi2476VZFPQHsuZNFUA710rdQgSScG/cJxbQo/Bp9zISbts6BBE B2TA== X-Gm-Message-State: AOJu0YyWznIb9aupiZvKcBEbIyOaF/S7ZfvtoBnR+1ZceRBjyBuTc8Cx jSkUrmLwLv3/ilhZdQyIroPitrdupRkYuGWaoAH/gQKq91ydXlV2LXbo6Zwx X-Google-Smtp-Source: AGHT+IH8wU2MrWwdhOPQk5WJkYl6jFiIk/Mcv9E5+XcjvUXxE2r/QIx3a5qBn1VIuvNMYBBgQczI5A== X-Received: by 2002:a05:651c:10a1:b0:2d2:d6a0:6f3e with SMTP id k1-20020a05651c10a100b002d2d6a06f3emr3479750ljn.13.1709390259261; Sat, 02 Mar 2024 06:37:39 -0800 (PST) Received: from gmail.com (243.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.243]) by smtp.gmail.com with ESMTPSA id jz12-20020a05600c580c00b00411a6ce0f99sm8567187wmb.24.2024.03.02.06.37.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Mar 2024 06:37:38 -0800 (PST) Message-ID: Date: Sat, 2 Mar 2024 15:37:34 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 1/5] completion: reflog with implicit "show" Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: When no subcommand is specified to "reflog", we assume "show" [1]: $ git reflog -h usage: git reflog [show] [] [] ... This implicit "show" is not being completed correctly: $ git checkout -b default $ git reflog def ... no completion options ... The expected result is: $ git reflog default This happens because we're completing references after seeing a valid subcommand in the command line. This prevents the implicit "show" from working properly, but also introduces a new problem: it keeps offering subcommand options when the subcommand is implicit: $ git checkout -b explore $ git reflog default ex ... $ git reflog default expire The expected result is: $ git reflog default explore To fix this, complete references even if no subcommand is present, or in other words when the subcommand is implicit "show". Also, only include completion options for subcommands when completing the right position in the command line. 1. cf39f54efc (git reflog show, 2007-02-08) Signed-off-by: Rubén Justo --- contrib/completion/git-completion.bash | 9 ++++----- t/t9902-completion.sh | 11 +++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8c40ade494..ff216f1c65 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2407,12 +2407,11 @@ _git_rebase () _git_reflog () { local subcommands="show delete expire" - local subcommand="$(__git_find_on_cmdline "$subcommands")" - if [ -z "$subcommand" ]; then - __gitcomp "$subcommands" - else - __git_complete_refs + __git_complete_refs + + if [ $((cword - __git_cmd_idx)) -eq 1 ]; then + __gitcompappend "$subcommands" "" "$cur" " " fi } diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index aa9a614de3..dbd57e6a28 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2618,6 +2618,17 @@ test_expect_success 'git clone --config= - value' ' EOF ' +test_expect_success 'git reflog show' ' + test_when_finished "git checkout - && git branch -d shown" && + git checkout -b shown && + test_completion "git reflog sho" <<-\EOF && + show Z + shown Z + EOF + test_completion "git reflog show sho" "shown " && + test_completion "git reflog shown sho" "shown " +' + test_expect_success 'options with value' ' test_completion "git merge -X diff-algorithm=" <<-\EOF From patchwork Sat Mar 2 15:51:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13579546 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8287518627 for ; Sat, 2 Mar 2024 15:51:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394676; cv=none; b=l9XP/yhN12+enWzZqfXdRL/pfNOw6v/cwy5v/g+aMVwNGOZOWRE8GxPy73YkGLNwLxcry7e5pWMNwt0iAX4me4njAoClK4mPy1MJ6X+bENBtLMCncVNTCGvaO6+hHyh/j+oWwLK444h6K+2vlXbD77FVKkopkGQaInMrnip1UqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394676; c=relaxed/simple; bh=tKZFnWm2BzNRZXOSi0G6MCpqcOTrJlu8UFAvP4ddKUE=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=foIkN4YrWO7PdFbQ/v5xq+d0bgzebjaIy2oCvNOBOAcTe6LFUeNdLxKKSjf5o8oCf5khzhU4iE0jMMlKXZP/aA1joviNdMSGor+2yjcv/1mhEBI98t4MO9HsyJSe8QlD6e4Gr5Emz+wno4h4maoLuPZp4nVCfTuyMr8MreX/fco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AWEiRoLa; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AWEiRoLa" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d37f6bbab6so3153261fa.1 for ; Sat, 02 Mar 2024 07:51:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709394673; x=1709999473; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=e7BlxXP0GO2d0Y/z0JgYaWtM2zccmb+RqF1MhPjVI2M=; b=AWEiRoLaNekOTxCRrQv5ZRIkxLP5kHgpJT0wkhovWMR5JPfq/au8myzn1ZPsREfmpf 73+CQhCBvdu2bbascnTZ7a5BfIozBdsE7tSvp8TqDV+BGVcNLJiTrN6r+r1OWL2dFYEz KcFI13dhL8sPz4Igvfqucqb+GUNjuDCw4kwDchh/m866mWVdmAY0U5QeNyd6Aovib7fU 6US/2pkvbB3TvM7GeIw2NzmDi8JOx/JfBY882x2NkH9/WHZsU0qSnQJ48a6XvVge0m9K W144vqHfVUZeaTS43pyrH1ECWEGmrBIVBKcVGOtncXgTIaoY+XcrYWeEVO/+WtkxcKlw RpBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709394673; x=1709999473; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=e7BlxXP0GO2d0Y/z0JgYaWtM2zccmb+RqF1MhPjVI2M=; b=uq3QdC2nac8I7J5jdeU9XoxBhZ1+sTaH7W/QxbCFb9mUWEZd7ay4doNoEA5Z+1nSn3 TvF9OaHnhUQOZLVwiF9cq/PGBsxGw1ZjJdQbn+XVUpl+/27ojLpMvnCGkLNV9ShNy8YT 0JUtCfJknNBag0vxUWj3F4u8bLqj0f3VCm6ONnUoflNuYTT27TPZFgYRei5r2379y4Mk vYZ4Y4eo1Yz/Ngxz0oTg/X0nmig5WTzkNdzaNA+1XEXOPV3SqN5NDc1oa/OtMpa7MnOF C2m8T5gDamyda7v8fZJOlLco8xTHPy6EkKLjRnAsmv0RHNmidTfS2F8T9B+VIfchH3h0 D0GQ== X-Gm-Message-State: AOJu0YxCXjAaPRhBQZgOiSge3Oaac2rt9Gc0MCEO9HH48PXsDhREpoeo z0MZfPKn10faK73SA/L67ZDoTnNU3Wocx2w2kYRAY0Upf5r4jBrtpNeB9lyb X-Google-Smtp-Source: AGHT+IGB9gw0DRl/DpHLOQ/NxZC3do4EzQHwtsXu3AjUhiCU1cDUB1zv1Ue/42A6DmlC/95QF4a8aA== X-Received: by 2002:a2e:3207:0:b0:2d3:4b73:7b40 with SMTP id y7-20020a2e3207000000b002d34b737b40mr2588539ljy.17.1709394672513; Sat, 02 Mar 2024 07:51:12 -0800 (PST) Received: from gmail.com (243.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.243]) by smtp.gmail.com with ESMTPSA id o6-20020a05600c4fc600b00412656ba919sm1204842wmq.20.2024.03.02.07.51.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Mar 2024 07:51:12 -0800 (PST) Message-ID: <58420452-9491-4e46-8746-55afe95f41de@gmail.com> Date: Sat, 2 Mar 2024 16:51:08 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/5] completion: introduce __git_find_subcommand Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: Let's have a function to get the current subcommand when completing commands that follow the syntax: git As a convenience, let's allow an optional "default subcommand" to be returned if none is found. Signed-off-by: Rubén Justo --- contrib/completion/git-completion.bash | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index ff216f1c65..849d191b02 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -554,6 +554,26 @@ __gitcomp_file () true } +# Find the current subcommand for commands that follow the syntax: +# +# git +# +# 1: List of possible subcommands. +# 2: Optional subcommand to return when none is found. +__git_find_subcommand () +{ + local subcommand subcommands="$1" default_subcommand="$2" + + for subcommand in $subcommands; do + if [ "$subcommand" = "${words[__git_cmd_idx+1]}" ]; then + echo $subcommand + return + fi + done + + echo $default_subcommand +} + # Execute 'git ls-files', unless the --committable option is specified, in # which case it runs 'git diff-index' to find out the files that can be # committed. It return paths relative to the directory specified in the first From patchwork Sat Mar 2 15:50:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13579545 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD88D18657 for ; Sat, 2 Mar 2024 15:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394655; cv=none; b=SMwTmBzpHhmcLIFU7KhPLy2jtoNWCDk1uGEQZAOyI0QYiQaWCoS8u/YpQkAacFD2q8cbeUCQAaebLzz3QgL/Y4qlCCoRqsrSU9Lmf2oAtFgNPQPFBTiLQy6HzzOitel8dmMfJ7QMu5BW9UEx/6NZK6lZgZJ4W8MLPYdq/gt2Gzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394655; c=relaxed/simple; bh=aMmT52VA3qq4tUJY1QcwlXwEw6+Fi0nOqbnLZFfTvSM=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=S9OrfXcKz4dW1X7pDXRGVvcVtVjfP+RNvKwzu9fPJklgSfu9B36RKbVO/R9vF8q+u99kz2RfO2lBCqoEkifczsqtt1sPEVNss7cwEtPuwLzMNtuR42BQSmQf+LEa+GsgpA1Bq3BG7+8QNUfVOU16eEswcbZ49ugb2IyR1Ee33mA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=asTPIDt2; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="asTPIDt2" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-412da818207so2220375e9.1 for ; Sat, 02 Mar 2024 07:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709394652; x=1709999452; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=8uKsMsTglGNrI2tQScoVSN5413wK+rz2J3hThgN9+rw=; b=asTPIDt29PbGcebt76e1lVedKf6j/IAwSeaIBuNESbTYoEPUB8g5u1zI1ZGUUoWhSG Ypoi8PdC5qW2v+FX+UF9mMu7qXtTbtlQ+QNQHqaQROLJsMSR7p6Cmbo50ZJnGfCug7xb fwq9EEL/niDl5Pr9Ukm8voF5IR2jhch16dAgySfycSHsZ1ppBWClMugictnG57tR6G7U r5jYZl71ICNXYCbEwd6UIdXgTpG0gxIbzB8wsW9Hzi3v9y+ULeyayKpqW5tpNQQtewpF Yi/0S3xx7w8LSXnmHgaSAaKnqTxBXbunsKC6jkug131Xk8GmgOf3mDB2vHB759BA3fYt CZbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709394652; x=1709999452; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8uKsMsTglGNrI2tQScoVSN5413wK+rz2J3hThgN9+rw=; b=jDBKOxRBTnH62GylGkd96NW/d39eRAx2tz499XeU6xG9sPhz6sD96wia392CgBOkO2 4RGPWJQ47ERI1C+L/MqnPSUMmuOHp7igwo322R/tYl3Af0IIDUQzuhK0/xZmsFHWguEX mi1ivD0mWTQopSy8BWJAkY2O8b1g66CVFk1c82yZiGg5TDvxrK6kStnr9pkdqIjxKatA Qd9K9KHniZX4PNejtmxVf4qc3IDU9TZz4Rn0ML64ZdlSnrpcd1OlRofzGJ4gp0vJkp2l MhyWCg7aarwP3sJ2XYR6081R7sFPNDEvavjoR5WH2wOCRcmdnZodfviCAhomRQ0J2No4 QcXw== X-Gm-Message-State: AOJu0Yw/yNahhEpgX064506+Ow5VRgquRiSK4p96XBSE7oco7cnhX9bI b0we7Qm301FpPg7xAx2+2lemacc+oAgAw3/+pZEhkAxR4WsFDDd4rzpXmRlz X-Google-Smtp-Source: AGHT+IH6p2E8Mquj73NNEShcyaJkBrs4tmAqn5/5XXg9UrY80NCIiiohlPxWt6qnB1ia5TLMOqMniw== X-Received: by 2002:a05:600c:45cf:b0:412:78c8:b31e with SMTP id s15-20020a05600c45cf00b0041278c8b31emr3892325wmo.2.1709394652007; Sat, 02 Mar 2024 07:50:52 -0800 (PST) Received: from gmail.com (243.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.243]) by smtp.gmail.com with ESMTPSA id o6-20020a05600c4fc600b00412656ba919sm1204842wmq.20.2024.03.02.07.50.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Mar 2024 07:50:51 -0800 (PST) Message-ID: <27fe304d-6011-430d-8f43-7e0581566182@gmail.com> Date: Sat, 2 Mar 2024 16:50:47 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 3/5] completion: reflog show Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: Let's add completion for in "reflog show" so that the user can easily discover uses like: $ git reflog --since=1.day.ago Signed-off-by: Rubén Justo --- contrib/completion/git-completion.bash | 10 ++++++++++ t/t9902-completion.sh | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 849d191b02..dc5f73a9f3 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2427,6 +2427,16 @@ _git_rebase () _git_reflog () { local subcommands="show delete expire" + local subcommand="$(__git_find_subcommand "$subcommands" "show")" + + case "$subcommand,$cur" in + show,--*) + __gitcomp " + $__git_log_common_options + " + return + ;; + esac __git_complete_refs diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index dbd57e6a28..04f3620e5b 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2626,7 +2626,10 @@ test_expect_success 'git reflog show' ' shown Z EOF test_completion "git reflog show sho" "shown " && - test_completion "git reflog shown sho" "shown " + test_completion "git reflog shown sho" "shown " && + test_completion "git reflog --unt" "--until=" && + test_completion "git reflog show --unt" "--until=" && + test_completion "git reflog shown --unt" "--until=" ' test_expect_success 'options with value' ' From patchwork Sat Mar 2 15:52:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13579547 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6534D18627 for ; Sat, 2 Mar 2024 15:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394731; cv=none; b=H3Hq8mL6qpGFZhX6RdO3R2Uii1LquDr/Ddo3IL5CU8TOFGnqEOfQLjX3kOtShV47foMBsd9/lb4a8B/R7rqooiZAe2fKmsobXvjVfUjo8lnEEPReZNMgawjl5HOnwB/PhAvXl4cvraklmbYaJTfxpXeA1CyIGu7mtimM+D0IB/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394731; c=relaxed/simple; bh=Wq16BpN2O8D6S3VvQPJymma+WTZ89an9xA0288k+kk4=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=QZ/ErThI373FtFbQ6FhDt4uuiYcmp3vhaux2uRsDfaHkFawHsBW0GWTQMF9gbhOg5JnC7ryeSY7USmlhf1D9hGD1F8M2tl/+913ljhsxxJbOJ+pPnAICGVfpR/jqNfadq+AYxFoikQ7rviPam/SNbDD0CXqqZLIxMCjkIqAKaqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aVuEvFy3; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aVuEvFy3" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-412d5ae1c5cso2921395e9.2 for ; Sat, 02 Mar 2024 07:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709394728; x=1709999528; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=oNZjf+nWm698qQGdEDR/KdDOnWOkO44NtsRJ1+2zHHA=; b=aVuEvFy3Q2zKxPXgZyPU3a8n7gzC5XgQqFBr5tIe0G2f0els3kxqcRUa0D6bayspoT GwbVIZXP3BmGC3rRjhpX6iEYQGQgkl5Qqziumk5rqyPLHupUWbtUntT6txMj1GBIge/T KEwkhUVWCOuWlY2jUnr7kj3sMvnqp82K2fjrTHQ1zDFTUkLQqJCRp4aYD2B8H2ilwsGe 42N+97xAvI605+bm0giIExzQ/mfbjeZXJ+HFxHwH/c2slEQTR8Z9/6uy6MDHTy0ycbhz qBSnU3jX5+NbBNML5yxC60hNKO0pEFoEpEjiN0OrMCEJ7fSEiF9rt84qBmVSjxgBgxbi A6bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709394728; x=1709999528; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oNZjf+nWm698qQGdEDR/KdDOnWOkO44NtsRJ1+2zHHA=; b=g6mMvEHjS4eWG6JaTSM20k8QDyvBnL2dncguZ1+CDu4YlngXVrazeMFsfLtnciDryc zZ5j6ZpinLCcfeJUoHoh8R+sbGUFz2LRqhLbM3N7lGAqGMYB6c5xCFWfg0/1xTy6Li+P nzmSQ9sgigDyFFFSkIO5MUoeiocfWdlDrz+8JgF+msQ9YLf/6hqt2n863ROz0kcZyYYx cxs3BexFP6SWtAbmGOMH492EN/Q8SiIY8CdtDCp393NgblzJcygpjxXjFHiDvUOxZsfL ErzbhC9tId7XLEI4Nq35RG0TUWIeamVSYs09fqq9evFnHplU97XtiCfyfrjUi/pLRSAu iRCA== X-Gm-Message-State: AOJu0YwR/t3lRwglztwgPgWDuCCaSII38NoK2nWS725oHoKY3S4xzvqJ YLjIYUKdr65HO/5pm/IeQOm8rXS38avLA2CzV6hczn3mRH1kHHlk1Kc5TIaI X-Google-Smtp-Source: AGHT+IF2DXKVJdIQdpfit4iqDmogNVNvr4EqxCtUADlasqJqvT3EFZICJ9if/fyg0NCtKd51M+JZAA== X-Received: by 2002:a05:600c:1384:b0:412:c213:d0fc with SMTP id u4-20020a05600c138400b00412c213d0fcmr4096614wmf.15.1709394727442; Sat, 02 Mar 2024 07:52:07 -0800 (PST) Received: from gmail.com (243.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.243]) by smtp.gmail.com with ESMTPSA id o6-20020a05600c4fc600b00412656ba919sm1204842wmq.20.2024.03.02.07.52.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Mar 2024 07:52:07 -0800 (PST) Message-ID: <69f1dd45-e19d-47ad-b83d-746e9f67368c@gmail.com> Date: Sat, 2 Mar 2024 16:52:03 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 4/5] completion: factor out __git_resolve_builtins Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: We're going to use the result of "git xxx --git-completion-helper" not only for feeding COMPREPLY. Therefore, factor out the execution and the caching of its results in __gitcomp_builtin, to a new function __git_resolve_builtins. While we're here, move an important comment we have in the function to its header, so it gains visibility. Signed-off-by: Rubén Justo --- I've changed my mind last minute, and renamed the function to __git_resolve_builtins, so the subject of this patch is different from the one included in the cover letter. contrib/completion/git-completion.bash | 31 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index dc5f73a9f3..f9fbf1f703 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -452,16 +452,18 @@ fi # This function is equivalent to # -# __gitcomp "$(git xxx --git-completion-helper) ..." +# ___git_resolved_builtins=$(git xxx --git-completion-helper) # -# except that the output is cached. Accept 1-3 arguments: +# except that the result of the execution is cached. +# +# Accept 1-3 arguments: # 1: the git command to execute, this is also the cache key +# (use "_" when the command contains spaces, e.g. "remote add" +# becomes "remote_add") # 2: extra options to be added on top (e.g. negative forms) # 3: options to be excluded -__gitcomp_builtin () +__git_resolve_builtins () { - # spaces must be replaced with underscore for multi-word - # commands, e.g. "git remote add" becomes remote_add. local cmd="$1" local incl="${2-}" local excl="${3-}" @@ -487,7 +489,24 @@ __gitcomp_builtin () eval "$var=\"$options\"" fi - __gitcomp "$options" + ___git_resolved_builtins="$options" +} + +# This function is equivalent to +# +# __gitcomp "$(git xxx --git-completion-helper) ..." +# +# except that the output is cached. Accept 1-3 arguments: +# 1: the git command to execute, this is also the cache key +# (use "_" when the command contains spaces, e.g. "remote add" +# becomes "remote_add") +# 2: extra options to be added on top (e.g. negative forms) +# 3: options to be excluded +__gitcomp_builtin () +{ + __git_resolve_builtins "$1" "$2" "$3" + + __gitcomp "$___git_resolved_builtins" } # Variation of __gitcomp_nl () that appends to the existing list of From patchwork Sat Mar 2 15:52:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13579548 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0E5F15EA2 for ; Sat, 2 Mar 2024 15:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394751; cv=none; b=fibJrvFCpwjnEMbSJhj4YTlG9h4oIF/F4NJWYA2THfn5t7vXV+9RE31kPkl4N0NeCYjsX0X0zwz3FMEk05JTyBXUl6JMF1s/UR6xk5BTYppBSxuft8Xg23Y/p71SDLZITp42eanBLRMoM2dut24yP2JjPIraDW++mGsYvL0XwGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394751; c=relaxed/simple; bh=+A+qOK+diXtjXBPuHwcxj6QJHxOFjkx6XVzHbwvElSc=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=AKwQqHPS1G3ijAt6tLPe6Jlbo4dr+5V4Z3zYu5cKjxyVBZ0/TYVmjnTP8e8h5pmdQJxdNVBhk8yX5Qnsw8U6MT4vVXpBBhGXKwp4tXz1X6fLuEHyFkoykeBX0WlJsRB6QwiZorLQlX6Jf+U28BYnQ9bZkNtxWkOWqrCUgcWwC4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Qp1zKShq; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qp1zKShq" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d37f6bbab6so3161881fa.1 for ; Sat, 02 Mar 2024 07:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709394748; x=1709999548; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=D6lCqzq6++SzEJIf3GoNH+DztW1Z6+HXpdaEeA/5uMo=; b=Qp1zKShq+8LYEh9y3QZ9zczwRWy3QsumHcQW472U5Eq9wcyMKHJtqVjt12qokd/6HX FsMgfsawFG6wWB325kfwCy0Dhr8mAmHXFTpNzd7SQWOrrGgGAueoANwV4FYB4CrtkTRG Ih+2K9peGZrfgFbz63b18oiMSbcEp1Qrj7H/LJo5gP13ScIatcpoVAm3r2P2AimFsEtD ZpnCAgm1a0JU3WSEJja3iGwmR8C9WbRxmERd0kmde+iQ+rZT5Rcya0GssUKvhrNlzjEV cFTzLk5+HLQzSRIjj6Uk44L8UBThcqEMcmRz8Kv0HfUnspxHeh8JN41oQ/Dpx3GDrsHT aAWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709394748; x=1709999548; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D6lCqzq6++SzEJIf3GoNH+DztW1Z6+HXpdaEeA/5uMo=; b=gKggHFTDsR+wr8/YpFfXW6YYdQIyL7p/lBjSnWg0GPOr9SsW+U3NVxac5pvRP6hff6 H3Sts2V05iPxhqt+Gekxb0PpeuAs9TjAKhWAn6oUOQEKEUz5Yb3DxjNsiH+DjZYfZe1j xLDBZdjRkuHEmsLthpmUqnj2Ur09ra67IQuph+d+anSFeC/LXiNCCg5bkHtf58HpCikz uK5E5hSHZ0gDpfXG/ncGkPNP655dzRK0ENEp5GRWMF5ouFzIKk1Kl7QjDc44puj0IoWL IE0XJaBL9Kc7wPn1ag3tIdmGsnSOC1E8vlG6TCme3/asLj19/dabTfRpqKsPQD9Y66wS iA3Q== X-Gm-Message-State: AOJu0YzSKQO+ZgNIfYJHDbzc3mO8qd0cJXPdTUhYPgeZU8hENmBe+k1f pABeSOwp8ettR478GNZIH2aDxUrpV4c9luLBTjcRVdF50btZQwOjn+xj6WXS X-Google-Smtp-Source: AGHT+IGbkpze3qZgChrp6wd1CSWOdrLbiGYeDQlu91LcL2sLwXVABXZbWmiCgdJGceZw6wDCQlpWzA== X-Received: by 2002:a05:651c:2cf:b0:2d3:5cfe:c600 with SMTP id f15-20020a05651c02cf00b002d35cfec600mr1706416ljo.3.1709394747736; Sat, 02 Mar 2024 07:52:27 -0800 (PST) Received: from gmail.com (243.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.243]) by smtp.gmail.com with ESMTPSA id o6-20020a05600c4fc600b00412656ba919sm1204842wmq.20.2024.03.02.07.52.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Mar 2024 07:52:27 -0800 (PST) Message-ID: Date: Sat, 2 Mar 2024 16:52:24 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 5/5] completion: reflog subcommands and options Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: Make generic the completion for reflog subcommands and its options. Note that we still need to special case the options for "show". Signed-off-by: Rubén Justo --- contrib/completion/git-completion.bash | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index f9fbf1f703..c5c9e9de2d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2445,8 +2445,12 @@ _git_rebase () _git_reflog () { - local subcommands="show delete expire" - local subcommand="$(__git_find_subcommand "$subcommands" "show")" + local subcommands subcommand + + __git_resolve_builtins "reflog" + + subcommands="$___git_resolved_builtins" + subcommand="$(__git_find_subcommand "$subcommands" "show")" case "$subcommand,$cur" in show,--*) @@ -2455,6 +2459,10 @@ _git_reflog () " return ;; + $subcommand,--*) + __gitcomp_builtin "reflog_$subcommand" + return + ;; esac __git_complete_refs