From patchwork Fri Jan 26 12:51:27 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: 13532547 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 66AE0BA39 for ; Fri, 26 Jan 2024 12:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273504; cv=none; b=s5z7fLgOpyk+xRzM0doomDw4Yjum6WFcrBATZW3Jehe9xcthNxLEi6CBTIahrsDBhZP9DHPMpEEyTgTZPSNDdQXV57nmI0yBZzRqQEFyVLizGeNFmh1hCgy4HVXM1ECneHPW8R4/GTXjg4CixUDc6CaX3VTKd4qczHnXVqJBRbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273504; c=relaxed/simple; bh=j1Ymds+8YcI8kes1Q1TQbcjQwOEGiBMCk/erMJBvLgw=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=arteTO3aS7jaE/XbL/uNHUI5Obny7M3TdSyhKPlsuEWFebj0/0wi00hSCjXWSDPlgWeiwyAa0VBzFQKzwoUF5eaxEHgjKfUwS9ToTP05WKxkhRqrUK8UTPVKSksZVUckakDIJE/FaYZGDLxoDUWZkVySKomAwsjOvlXCE0ylYKQ= 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=bq0lyP88; arc=none smtp.client-ip=209.85.221.48 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="bq0lyP88" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-339261a6ec2so482874f8f.0 for ; Fri, 26 Jan 2024 04:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706273500; x=1706878300; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=fr3RRk4gJOHyZ6BRA8C6KS3vsaNA7K3KSDq5xY4nvoo=; b=bq0lyP88mAlpY+/nM4hVoXVeFNh+E7kmBh4AcVw5Q19HeP842y79cT7MNJcQCxtbI8 4OdOhYngF+TJ6LTw4MaCE+RJDNzYOk3G4ffvA+Vw58AP6qG0Ok4+7dY4knc3/1JeDTG4 EsXG0WFR5lDY4ovcOG8fUJKfrR0NJD4byl/ZYC0XKnFj+ArS70yWPGUzHtPuvSck69wB BqQ/xNJM32JkcMZ+Nb+A7yJ+kiBDD5ab/tan+TV9VcjMPJJEYCYxA2ITQdH2ifDpFtdz wouE5elhr/D3WXWoOTA3xF3c1KkPcNgF+J43SmkAszoyYZ7Ul+1awdd649w65z3GqAJB ix6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706273500; x=1706878300; h=content-transfer-encoding:in-reply-to:references: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=fr3RRk4gJOHyZ6BRA8C6KS3vsaNA7K3KSDq5xY4nvoo=; b=EQIuWdab2MFn8GnKcvxT2CNHnYSssU1hfgP+jwi32XZOIGd+gBquhUVQ0JpTnHhTUN Uh14LwpU4zasxNm3scyv0n0NBcGt5ZUjAuHiwo8EGA6XiZ2EuVtttmsMjSc3Wg5wwoeq RsGqSu8AlhIOqPLk62G/EQJm9eTH10hRKY0ZVsF3bFs+KI1q0Py2FzuH2oKg4cqa+bS4 w+lS5hYOQcE9fYjtLQit74hzJeaTjzLdf0oTQTpFbfH7256OQF1tyDBT5w1vG4I49IC3 cMLa3OuGwZdDrdNXRqM9qddtHBLPaKxGGuL4LpXWkJ3kLtnLAvSqzq0mKnmoYj12XCF1 KPMA== X-Gm-Message-State: AOJu0YyG7cwDvX2tga3hsR11rV+cbfnu9Ai9OlsmaVbS8F8Vv4Lgowwd QJ6m/wjrRS/APctpjnP/oQG53KIKIRcnIKjN8vTql+df9vmZ5S6jyBsw5tU5 X-Google-Smtp-Source: AGHT+IGrIUBh7k6Sf8Qx2W5Rhjwqyb4BB6hjDT8RNwX/NyIVGCf98EOtzKCxFdsuM7YF+VCHs6i9RQ== X-Received: by 2002:a05:6000:18c6:b0:33a:b27d:9563 with SMTP id w6-20020a05600018c600b0033ab27d9563mr907388wrq.109.1706273500444; Fri, 26 Jan 2024 04:51:40 -0800 (PST) Received: from gmail.com (77.red-88-14-198.dynamicip.rima-tde.net. [88.14.198.77]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4806000000b003392ae3aee8sm1207551wrq.97.2024.01.26.04.51.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jan 2024 04:51:40 -0800 (PST) Message-ID: <8c902c53-815d-43c2-8ba9-8144d8884804@gmail.com> Date: Fri, 26 Jan 2024 13:51:27 +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 1/4] completion: introduce __gitcomp_subcommand Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> Let's have a function to complete "subcommands" only in the correct position (right after the command), in commands that follow the syntax: git Signed-off-by: Rubén Justo --- contrib/completion/git-completion.bash | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8c40ade494..916e137021 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -554,6 +554,27 @@ __gitcomp_file () true } +# Completion for subcommands in commands that follow the syntax: +# +# git +# +# 1: List of possible completion words. +# Returns false if the current word is not a possible subcommand +# (possitioned after the command), or if no option is found in +# the list provided. +__gitcomp_subcommand () +{ + local subcommands="$1" + + if [ $cword -eq $(($__git_cmd_idx + 1)) ]; then + __gitcomp "$subcommands" + + test -n "$COMPREPLY" + else + false + fi +} + # 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 Fri Jan 26 12:51:46 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: 13532548 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 484191B7E1 for ; Fri, 26 Jan 2024 12:51:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273514; cv=none; b=Y1rtLJ1/Y2d4RrlRwuY/fdzy3yyzMfG5thWXH51s9b6ANQZ48h3RMl9lOZGGLM+WKoyupd9CC61pLcon8V3PbX7Eo9hkjvMof5EJRX0h5dYNIV23yQUTbVBEZwShX8iOKwJXJyiJjCt28ZjqDq8nYhulC7J7vRAtobm9pSlFdMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273514; c=relaxed/simple; bh=ZVMrJhmZ0iYeqX5s7/hJ+FD0EcG+m3KajBAqHIMbnLQ=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=dzVXBPp0s1vQGMLm7QagILwc+8KWLIQr3cfBdAxPzhEA8pRgmwqCiruDBfzklqGcxpzhZk04r6DbDixczsXNaG1KHUKW/H0Pshgve7M4ZWu1/dwB+vzQ3AuQSrVGmmPdTbRdo0tu7j0b76sNxTUhUrA708LxNdcSJ70n0WmQrEw= 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=BxTM2vgW; arc=none smtp.client-ip=209.85.221.54 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="BxTM2vgW" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3387ef9fc62so413857f8f.2 for ; Fri, 26 Jan 2024 04:51:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706273511; x=1706878311; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=1Elvlj4iHgS5wE1do01iMZrviPd+cSNw5eRLk064PUQ=; b=BxTM2vgWx5TeLhJLW3oLIU3x4DOyPvE2mwI1Bp+ingXhbpb9v9i84lM1sVVb0rNKik 9Yz3peRh6Ttv/MMw+9NFPasE5xRMJ1qaehztyI+JSC92YXptXW9WVMKLweepmgCcUYNs ZeS9svI3yvdGL5DP26WTwPJD9XMYuxijp9DMmj7FUY3UV3ovmtsEk3mn1ZUXiqig7uU7 q+XpVwz7Qx5eGSoEJ4nEYN2bGP6iAJih6JvmETYdxBZkYwb6XeVIPrmi/CZR5oi5bTum D4sxybfRoJR/7RRhCY7GUPC/nW70PAOVTErVQghWyevzb24txuPDWSNScjhi92DHdERk JZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706273511; x=1706878311; h=content-transfer-encoding:in-reply-to:references: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=1Elvlj4iHgS5wE1do01iMZrviPd+cSNw5eRLk064PUQ=; b=DrLMIlvj8NU03/OZBvxOZt2UWEuLnkuGr3JztADqygrz/zSDBe1IZX//BaYYNvblOp 1ZzJzFQwUP/Mgxza9HGIbZrLwakXtS+DqfUkSCR6v6olSMOhkKdAWEv4+p+GsxpzGmR9 FrqFYsE/6/2wKPm3rX0/VXoKgg0b2cJq6HQ7EAFOU6/soxOFit+XZLJ2Y+iv+nj0/ZGu dIZ7Nz3j7iOhOOLoDdmF1U8ZKti42Oq8nTpSH4isFPWMTRjgt/EollBj35+HfSc8CmAK u5YOsAuFg9AsX53it8EmsfyTZXnL33aYVVFesqXy/M77VfKj8SAk/17KOqMRdRbTw/g3 wVvg== X-Gm-Message-State: AOJu0YyOv6WO5Vex1rxwxjteNpna56FtG4v+PoZ0Y6peaBVi1ditS29Z WLvmgEKvZ/ms6nT0tGYODw2mq5eLHD+CwNfHXAG8AHQPnYKtwAtYs+OPvu3o X-Google-Smtp-Source: AGHT+IGr/0OnUxAjBrVZj79GpmYNqWis6NE7Ut0hk004hpx2bW1vJeUURmh+YMEWIAUoBi5xU6Th+g== X-Received: by 2002:a5d:526a:0:b0:33a:d1c2:2f77 with SMTP id l10-20020a5d526a000000b0033ad1c22f77mr789998wrc.132.1706273511348; Fri, 26 Jan 2024 04:51:51 -0800 (PST) Received: from gmail.com (77.red-88-14-198.dynamicip.rima-tde.net. [88.14.198.77]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4806000000b003392ae3aee8sm1207551wrq.97.2024.01.26.04.51.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jan 2024 04:51:51 -0800 (PST) Message-ID: <221f88b9-fc91-479f-8d08-f530796e2d13@gmail.com> Date: Fri, 26 Jan 2024 13:51:46 +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 2/4] completion: introduce __git_find_subcommand Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> 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 916e137021..5f2e904b56 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -575,6 +575,26 @@ __gitcomp_subcommand () fi } +# 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 Fri Jan 26 12:53:01 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: 13532549 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 DFD3914A83 for ; Fri, 26 Jan 2024 12:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273592; cv=none; b=fmkcIb84EZOehOv8SPixYdgaAjM656JASOJ0GAjfPgR4MisxZirDT7F8xBjoZ0JS44GvwimJwguqsnBadb2QQosTjgs1JQ//KW9gPrwf/9k9Xa85Z/0siJ1AYfKGdfp8rABMKcedxtYDJmHFOxyaNRVaenLk2gunpc3UzphCbk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273592; c=relaxed/simple; bh=P97VhY7mgv+haIaL4099aEIm8ieuksACoN8NoGnorSQ=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=TaLSjx6T1LfUaaf93VLGpMM8GwX0eNCDjZl2M0ul7B9KqzYSJVMAuXU/jtnl/qYRLQStB+03oFvB3QAQN0usYkiq8qGAPg6+Yc9TrqZd8EWzqPohyGQ51xPu3diLpa4/QpxptdVLVX3uSiBjZ0HndgxJ+OSh/0aevgRGirggKKo= 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=KATe0ggX; arc=none smtp.client-ip=209.85.128.49 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="KATe0ggX" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40e60e137aaso9365265e9.0 for ; Fri, 26 Jan 2024 04:53:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706273588; x=1706878388; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=rKXj/xLI0k1peLlffj+79N3IMFOUS4YDMGT0CBhAv6o=; b=KATe0ggX/O1A8vitwUGsaQ4plZ9ZMKwwn5OqEgcKgd8j4hiY6IzBzJ5lMYa0BLxot1 sXTt7I9epicF56pW2HEx+xmUWUwV8bM4jK2Sz04iaG55i/D3EVcqfh5AyHeXVYlszYAZ MJ0Js5cHA3UiAwMTBLRKgHG0mZZXWwRP815UTPnWGUCNlAEijQmYfsx+PQSgnRfajHWe Yp5A4SahGKfAuGy6EkwbxKn2huuh3uiOUsI8n1XAiXLrwxx+4YpH6CGf7t5Cdimn+M8+ /rQWh+aSvM1EbDDZ00J2QgjuQ/vMhtiPUGnlbjHXf93BXcJbgEENCUas19ZThYPkHo5V AvDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706273588; x=1706878388; h=content-transfer-encoding:in-reply-to:references: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=rKXj/xLI0k1peLlffj+79N3IMFOUS4YDMGT0CBhAv6o=; b=uksBCtqgmN/dHhailTkxLIcCsrjQWQKWJLyo+VgKaxT0bjAHtwGMscuVEL/OZqVogC +PrZ61QB1yzuUEFiVRpqcl59W4GQuFlUFWVXat4rcaHaMuvcBAOXI5WHt6d3HScehdfe uMyabIBbuK/Dsj30sB/Rxqt2crO39NUc4SvPP0/Vh1iP19aMEjOVmu8v6aHEvde8J8dd 4Swwo4PWPUkar6MzJVN2lddinQFWmADpVAukiQtmso31tib7ErWzVEGEEixKMR0Jt+oE Zp2qLSqMoRZnAa+iaOHGsUnDImM2jCcV5VIrNon7/2sNfjykkud8GbM7jotTYnlQZxjc Q5uA== X-Gm-Message-State: AOJu0YyKSB5Xtt6Z8y49Kzk+lDpymKR1kRdoM9CQjy7HYLKIfKrsYv7L woXfcBZnHULwZ34WIseZVJRpqnCTJ4tBvnmZUlg96UKmqvjlP83Y8ISrWidM X-Google-Smtp-Source: AGHT+IEwFlY0SgGFL8PDa7CPSOLjplHHBmrF2v1HHvS9JaeTRHfd7PfKn1vJi3OoixZ5AlSBg7lWXQ== X-Received: by 2002:a05:600c:5115:b0:40e:5f07:8179 with SMTP id o21-20020a05600c511500b0040e5f078179mr903601wms.55.1706273588011; Fri, 26 Jan 2024 04:53:08 -0800 (PST) Received: from gmail.com (77.red-88-14-198.dynamicip.rima-tde.net. [88.14.198.77]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4806000000b003392ae3aee8sm1207551wrq.97.2024.01.26.04.53.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jan 2024 04:53:07 -0800 (PST) Message-ID: <5991b58c-770c-4aaa-bce5-f396d9f7f16f@gmail.com> Date: Fri, 26 Jan 2024 13:53:01 +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 3/4] completion: reflog with implicit "show" Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> When no subcommand is specified to "reflog", we assume "show" [1]: $ git reflog -h usage: git reflog [show] [] [] ... We are not completing correctly this implicit uses of "show": With ... $ git checkout -b default ... we are not completing "default": $ git reflog def And we are incorrectly returning the "subcommands" when: $ git reflog default delete expire show Let's use __gitcomp_subcommand to correctly handle implicit subcommands. 1. cf39f54efc (git reflog show, 2007-02-08) Signed-off-by: Rubén Justo --- contrib/completion/git-completion.bash | 9 ++++----- t/t9902-completion.sh | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 5f2e904b56..c41f25aa80 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2448,13 +2448,12 @@ _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 + if __gitcomp_subcommand "$subcommands"; then + return fi + + __git_complete_refs } __git_send_email_confirm_options="always never auto cc compose" diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index aa9a614de3..231e17f378 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2618,6 +2618,14 @@ test_expect_success 'git clone --config= - value' ' EOF ' +test_expect_success 'git reflog show' ' + test_when_finished "git checkout -" && + git checkout -b shown && + test_completion "git reflog sho" "show " && + 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 Fri Jan 26 12:53: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: 13532550 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 4F4141B7E5 for ; Fri, 26 Jan 2024 12:53:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273611; cv=none; b=Znph3HKxgaM4+CHttT6O1Ls2VJiIPW3jJ/g+zm7g5T3p1/RTGuVsGT+V/Tg5e6l5GHNGAwiZs52VaZSC9a/276v2jvbS8U2R4qp05pXQjyubdqLt9JwkORw2QOdvTyhtV+8blZRu8ire3dDN2bMOOHbzZ8JYhXkGJp4ABpH2IU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706273611; c=relaxed/simple; bh=F6GH+jz8q2fksQP8UgA7+8VtDzqLwQJz+PtCp31EtMk=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=Aa3XCm76ut/8AfWx4fHgUvL8VFV42x+R+Y4NSBdAKH6z8v7ni+mWlowXtXZnjkYb/UpW4la6KFOBSM+oDfLgQ3SzQ2nRKRVR4bWUBKJx1C/lykIUN1OnAIetyMRBd6j3JPVlYwauVLWy12cvSxWoV/rMen1nqqobtGeoFvgWj5k= 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=Wj1A5qUS; arc=none smtp.client-ip=209.85.221.42 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="Wj1A5qUS" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-33ade052953so224656f8f.1 for ; Fri, 26 Jan 2024 04:53:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706273608; x=1706878408; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=G7BZyHaahLPTuros5zaVvI85PZTPdM+woCXvZteLJVY=; b=Wj1A5qUSyga+ut0YwYkwi8kcIfOk5yRb2f7OJZQDVpIAo24DT/+pfKqG0T5RzcBQAQ 6zTIjPrOyxEj3V02+Rs6E0fLAFYVMsgYgveCpXzclP+TiX8zfdgYvEJgdOb7tVnylPNc Ehi2fEmWFGtSGtNPwLvoRpzXIQIhFuDY7iSQnH9pFReEoPTg8I2asCMFzydyefoJC6tE nHxZdf/qWsYC8nINq+pEKREo49hvD8i0FjwewTBKegHRajvW1r3arF7KOY1hiz98HhQC VlaYaFGxM96qJfwJyk6lyUfTYCAbRcQnkJqNFgOYS9VPQZbe64uICyIhWvo5R9G2mafx LvPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706273608; x=1706878408; h=content-transfer-encoding:in-reply-to:references: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=G7BZyHaahLPTuros5zaVvI85PZTPdM+woCXvZteLJVY=; b=WrDkrYJ6owtwPk0RifeogDkB5Jwiclpde15jcFgTwEV2nqHgFUu761b5TriVcKP+Gx Jq8YDyIzs8U6QfHKXfsu9ld2jEMz5dJDuEaeSWUCJWkICtT88MBzHDBXHbg5bWFCMAOz PTeigph67UKb+nTbRkFo4qX05D4QMyUDcXCLi2jxwkYHOi29uCH7OiirdcuAbP27C6z/ 7FRL+KVxOXedknM5hED5kYbJA+SHCzpH0sam/vbJAO6euJlRcr1L+s4H9TWQtxciX0Rj fa0Zzr/X98ve4Hlv2BkL4+WvCqFdvLpS3xS3/zB7ha6crZI6+WnAve5VLFSv0agcFnBB 8Cxw== X-Gm-Message-State: AOJu0Yy9HkMx15xuW/I34Uu8XJF8hXGsO+Vj8TMwVOxOy2Qs87nqWayb uOTDtbBXAI89CacyHp4BPkn+Mhu41uq5Xf9PIVWG7o5aeY+l41zg792ya7gl X-Google-Smtp-Source: AGHT+IE5IgunkH/Fbg6y8+gIQmqWwa1DcUtU++MpJzwz+KnGU3FhBd0iLqWdI8tDA5M/I0xGv2+gCg== X-Received: by 2002:adf:f284:0:b0:337:c7f2:850f with SMTP id k4-20020adff284000000b00337c7f2850fmr822839wro.53.1706273608492; Fri, 26 Jan 2024 04:53:28 -0800 (PST) Received: from gmail.com (77.red-88-14-198.dynamicip.rima-tde.net. [88.14.198.77]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4806000000b003392ae3aee8sm1207551wrq.97.2024.01.26.04.53.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jan 2024 04:53:28 -0800 (PST) Message-ID: <42861028-3ffa-40e2-bb97-a54cfc11ddcc@gmail.com> Date: Fri, 26 Jan 2024 13:53: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 4/4] completion: reflog show Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> In-Reply-To: <98daf977-dbad-4d3b-a293-6a769895088f@gmail.com> 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 | 13 ++++++++++++- t/t9902-completion.sh | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c41f25aa80..3deb98389c 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2447,12 +2447,23 @@ _git_rebase () _git_reflog () { - local subcommands="show delete expire" + local subcommand subcommands="show delete expire" if __gitcomp_subcommand "$subcommands"; then return fi + 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 231e17f378..a74d774168 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2623,7 +2623,10 @@ test_expect_success 'git reflog show' ' git checkout -b shown && test_completion "git reflog sho" "show " && 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' '