From patchwork Mon Oct 1 11:21:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10621857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9175D15A7 for ; Mon, 1 Oct 2018 11:21:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81E74293A1 for ; Mon, 1 Oct 2018 11:21:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75FED293B6; Mon, 1 Oct 2018 11:21:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B153B293A1 for ; Mon, 1 Oct 2018 11:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729164AbeJAR6e (ORCPT ); Mon, 1 Oct 2018 13:58:34 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:44035 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728921AbeJAR6d (ORCPT ); Mon, 1 Oct 2018 13:58:33 -0400 Received: by mail-ed1-f68.google.com with SMTP id t11-v6so13813625edq.11 for ; Mon, 01 Oct 2018 04:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l1ODIU9iEfHmqL7k7k7lWOMTtI2qht62/ymAyEfv31k=; b=NUEi8+tW74Hs6zU4+7WQeOn+NkZ/wY2/PadOe0LyrLBEpQR9AaLSb/9rzVLErHe5gU SbABXZP00KozxXsx/TZ/8bkCGIj5qQnDxaT23CurIZWCPkHYKRhMcHirWynBdvz1g6ux Bm3+2GJrrfYikdVfm6EzglathnzP6CiY5K/e4= 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=l1ODIU9iEfHmqL7k7k7lWOMTtI2qht62/ymAyEfv31k=; b=FpMp5rmuAcDbk1Jgp/Lt1u2c9zZYffrDExevSAzvFEwP0k74B+jwQPDEfRQ1p44Zax Y42rAKzmfAOuVWro5qeJVzThUopEFkNwNtRv+Nu7yZm+JHlf3SIjREwOF/AGUO3F50Lz THg1xmuCSDRscheBQ6YgkNGQyQMSFrO1dVpG07WUek1A4dl/o/J/DdVIcm+0CWxfXcmB ThTgCL0W94L4eoQW4iDaH55ABmZxcYLmcILXKZp8pHdDlA59boTEgWN3M1AAZ8i2Akmb fSeuXMhU3hMP4KMzQR/0/krq+IYGohDYHjFl2y2p7Ldpxz40BOdQ53QfogxrsjyxA6fb 78Gw== X-Gm-Message-State: ABuFfogs4Jz6E2ICXHu7c5wobIUaZfClVh8L3Sq5T060TYPKhAjfdnI9 WVF58kWbw94Ih6WJiSpyE+jHY+SNmxSmNQ== X-Google-Smtp-Source: ACcGV62YmCo2+yR0LDXx7tWSTW/AvuApg+y83EaKcYEdYslaDV1HbE4Wme6nQzaIzAdwaGy/yQSpsQ== X-Received: by 2002:a50:b399:: with SMTP id s25-v6mr16695991edd.217.1538392873821; Mon, 01 Oct 2018 04:21:13 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-116-96.cgn.ip.fibianet.dk. [5.186.116.96]) by smtp.gmail.com with ESMTPSA id d13-v6sm1908560eda.51.2018.10.01.04.21.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Oct 2018 04:21:13 -0700 (PDT) From: Rasmus Villemoes To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Duy Nguyen , Taylor Blau , Rasmus Villemoes Subject: [PATCH v2 1/3] help: redirect to aliased commands for "git cmd --help" Date: Mon, 1 Oct 2018 13:21:05 +0200 Message-Id: <20181001112107.28956-1-rv@rasmusvillemoes.dk> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180926102636.30691-1-rv@rasmusvillemoes.dk> References: <20180926102636.30691-1-rv@rasmusvillemoes.dk> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As discussed in the thread for v1 of this patch [1] [2], this changes the rules for "git foo --help" when foo is an alias. (0) When invoked as "git help foo", we continue to print the "foo is aliased to bar" message and nothing else. (1) If foo is an alias for a shell command, print "foo is aliased to !bar" as usual. (2) Otherwise, break the alias string into words, and pretend that "git word0 --help" was called. At least for me, getting the man page for git-cherry-pick directly with "git cp --help" is more useful (and how I expect an alias to behave) than the short "is aliased to" notice. It is also consistent with "--help" generally providing more comprehensive help than "-h". I believe that printing the "is aliased to" message also in case (2) has value: Depending on pager setup, or if the user has help.format=web, the message is still present immediately above the prompt when the user quits the pager/returns to the terminal. That serves as an explanation for why one was redirected to "man git-cherry-pick" from "git cp --help", and if cp is actually 'cherry-pick -n', it reminds the user that using cp has some flag implicitly set before firing off the next command. It also provides some useful info in case we end up erroring out, either in the "bad alias string" check, or in the "No manual entry for gitbar" case. [1] https://public-inbox.org/git/20180926102636.30691-1-rv@rasmusvillemoes.dk/ [2] https://public-inbox.org/git/20180926184914.GC30680@sigill.intra.peff.net/ Signed-off-by: Rasmus Villemoes --- builtin/help.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/builtin/help.c b/builtin/help.c index 8d4f6dd301..4802a06f37 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -415,9 +415,29 @@ static const char *check_git_cmd(const char* cmd) alias = alias_lookup(cmd); if (alias) { - printf_ln(_("'%s' is aliased to '%s'"), cmd, alias); - free(alias); - exit(0); + const char **argv; + int count; + + /* + * If we were invoked as "git help cmd", or cmd is an + * alias for a shell command, we inform the user what + * cmd is an alias for and do nothing else. + */ + if (!exclude_guides || alias[0] == '!') { + printf_ln(_("'%s' is aliased to '%s'"), cmd, alias); + free(alias); + exit(0); + } + /* + * Otherwise, we pretend that the command was "git + * word0 --help. + */ + fprintf_ln(stderr, _("'%s' is aliased to '%s'"), cmd, alias); + count = split_cmdline(alias, &argv); + if (count < 0) + die(_("bad alias.%s string: %s"), cmd, + split_cmdline_strerror(count)); + return alias; } if (exclude_guides) From patchwork Mon Oct 1 11:21:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10621859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3C6D1926 for ; Mon, 1 Oct 2018 11:21:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3B8D293A1 for ; Mon, 1 Oct 2018 11:21:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7A74293B0; Mon, 1 Oct 2018 11:21:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1DC6293A6 for ; Mon, 1 Oct 2018 11:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729171AbeJAR6f (ORCPT ); Mon, 1 Oct 2018 13:58:35 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:45797 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729147AbeJAR6e (ORCPT ); Mon, 1 Oct 2018 13:58:34 -0400 Received: by mail-ed1-f67.google.com with SMTP id h6-v6so12340702eds.12 for ; Mon, 01 Oct 2018 04:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zyRyjQqb8Mk4ojrUggpsKR7Q7R9H4mCxpPjWjQPAOLw=; b=cqxawfppHFXONqorpzTAN/8wsM1RUs/dXtDQz4g9vmfKIOBfbB44k9ICWN51FhmzUq rZOBmx/Gx5OS3dGGmDaKvLDW1pgOt9xCwePOEVJN06pa91MbVZhToyVdgugwYdjQV9uo mXLnhJDqCAmbeFvocEU17f8Q265QnJzUlumyU= 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=zyRyjQqb8Mk4ojrUggpsKR7Q7R9H4mCxpPjWjQPAOLw=; b=fpA3GS+XKYA/iwaLv1a9GwpxycbakajOAdHyXyi9bmEDMCn9PNr3PYT7sCcRm7/vo2 6sE0bJgRcMsvgx7aeNFCRfS+hcOJbY0NC42hJB9F31O+IyvkuWH9+WPL8C9bw0expdVA ur005blMVjqVVDnlGgExPGds3JHHXkTkvQhMZnBz1D8h+kL/nXxU9xndj0b3KzLqb4sf fhS9aHBECTdEBSQRY/kZZVvJ/Q2FMkTSQ/55dPsB4SG0pgracJI3fhbzOs9oByhVwdOm UWmDEiYnaGYLaCzcGV7QWgZXsY/6SHHYuEQOZs9HwVRbZo6io3/7TgT1HvNHiPB0ZPfC FtRg== X-Gm-Message-State: ABuFfoiIlLVxayHHgzaqXPShjZhmaI1OasiKVNdisYiVqTNXrgSkLjnm PKqZ02W0dn66Weal7PLWuyg+LPrePU3WSA== X-Google-Smtp-Source: ACcGV63xDfJEBWDGhKB4vOl+sPBUQ9hmNJJy7Pq1VdNGcfiFYQC+iOBv0ieo9ixr2hLTpofof4luyw== X-Received: by 2002:a50:b68b:: with SMTP id d11-v6mr17423127ede.283.1538392874955; Mon, 01 Oct 2018 04:21:14 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-116-96.cgn.ip.fibianet.dk. [5.186.116.96]) by smtp.gmail.com with ESMTPSA id d13-v6sm1908560eda.51.2018.10.01.04.21.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Oct 2018 04:21:14 -0700 (PDT) From: Rasmus Villemoes To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Duy Nguyen , Taylor Blau , Rasmus Villemoes Subject: [PATCH v2 2/3] git.c: handle_alias: prepend alias info when first argument is -h Date: Mon, 1 Oct 2018 13:21:06 +0200 Message-Id: <20181001112107.28956-2-rv@rasmusvillemoes.dk> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181001112107.28956-1-rv@rasmusvillemoes.dk> References: <20180926102636.30691-1-rv@rasmusvillemoes.dk> <20181001112107.28956-1-rv@rasmusvillemoes.dk> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Most git commands respond to -h anywhere in the command line, or at least as a first and lone argument, by printing the usage information. For aliases, we can provide a little more information that might be useful in interpreting/understanding the following output by prepending a line telling that the command is an alias, and for what. When one invokes a simple alias, such as "cp = cherry-pick" with -h, this results in $ git cp -h 'cp' is aliased to 'cherry-pick' usage: git cherry-pick [] ... ... When the alias consists of more than one word, this provides the additional benefit of informing the user which options are implicit in using the alias, e.g. with "cp = cherry-pick -n": $ git cp -h 'cp' is aliased to 'cherry-pick -n' usage: git cherry-pick [] ... ... For shell commands, we cannot know how it responds to -h, but printing this line to stderr should not hurt, and can help in figuring out what is happening in a case like $ git sc -h 'sc' is aliased to '!somecommand' somecommand: invalid option '-h' Suggested-by: Jeff King Signed-off-by: Rasmus Villemoes --- git.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git.c b/git.c index a6f4b44af5..0211c2d4c0 100644 --- a/git.c +++ b/git.c @@ -318,6 +318,9 @@ static int handle_alias(int *argcp, const char ***argv) alias_command = (*argv)[0]; alias_string = alias_lookup(alias_command); if (alias_string) { + if (*argcp > 1 && !strcmp((*argv)[1], "-h")) + fprintf_ln(stderr, _("'%s' is aliased to '%s'"), + alias_command, alias_string); if (alias_string[0] == '!') { struct child_process child = CHILD_PROCESS_INIT; int nongit_ok; From patchwork Mon Oct 1 11:21:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10621861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D9C015A7 for ; Mon, 1 Oct 2018 11:21:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DC18293A1 for ; Mon, 1 Oct 2018 11:21:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 712EB293A6; Mon, 1 Oct 2018 11:21:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F28E0293A9 for ; Mon, 1 Oct 2018 11:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729175AbeJAR6g (ORCPT ); Mon, 1 Oct 2018 13:58:36 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:37008 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728921AbeJAR6f (ORCPT ); Mon, 1 Oct 2018 13:58:35 -0400 Received: by mail-ed1-f66.google.com with SMTP id c22-v6so223003edc.4 for ; Mon, 01 Oct 2018 04:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9kNdEip7Gd3rQA86IfR1rSbKzsFJ+zSxgaPg4ALGOo4=; b=hgYYKtOFVOvPomXfi/izctMZKXsj20Q4DSMIqxnDlxvMoNPqFKkzUGN2/9TwtnbOEf D0kmVvYTwYPR/8b4u7UW17PX8D9AhksUu8FMa0dNRLc033Lzud1I1pIaZSO+IG2jwjS9 UB1KXLaTay21iuDeWS+RZRUPFxrWPZJ6nsx58= 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=9kNdEip7Gd3rQA86IfR1rSbKzsFJ+zSxgaPg4ALGOo4=; b=F4uaRsUReLz7Ai9jJ/T8NszwbbwhIH/igXB3wg5x395+583dYxpp99YfEveDKP2ZNG t92O+expiuWu7cE2FKIVizMgzQxNmEa+dvaBvc3D8u0ZCI9R1pUBCwDBhwLLgVNiBJri GnNLJDcVnt6VlK8A+Y49QE2Re1zD7eVtZMeEJ2wH0x53rVjb0s90AFkvBy9/TyV93uUV +YhwNCoOZ1iZ20MqlLjXouKB1AmrGpxX7gJWkTD+1H2lV7i0N4IPdocDGvLdAaBlwCUB 9Iuu70K5ED+n9XTF0TzqK6xoB3WzbdRc7EqDJ2Bs6DtVVkTg59TAkrr1elypYEgxWWG1 qj6g== X-Gm-Message-State: ABuFfogaM+7AgMxQ6Y8+0aE04p7x2StH//n6zAidvjo2MpPCS/uyuC2Q 1fLZJsspXfMRJMnD3cctcqIfuDtIUi/j+w== X-Google-Smtp-Source: ACcGV63jnMOOsPO0XmBc5SitxJy5eHWhMgAHKhfG+05l3nDcCilNpxNEo+jRlikF7IT7P1X9QS7llg== X-Received: by 2002:a50:b3dd:: with SMTP id t29-v6mr4979933edd.76.1538392876228; Mon, 01 Oct 2018 04:21:16 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-116-96.cgn.ip.fibianet.dk. [5.186.116.96]) by smtp.gmail.com with ESMTPSA id d13-v6sm1908560eda.51.2018.10.01.04.21.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Oct 2018 04:21:15 -0700 (PDT) From: Rasmus Villemoes To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Duy Nguyen , Taylor Blau , Rasmus Villemoes Subject: [PATCH v2 3/3] git-help.txt: document "git help cmd" vs "git cmd --help" for aliases Date: Mon, 1 Oct 2018 13:21:07 +0200 Message-Id: <20181001112107.28956-3-rv@rasmusvillemoes.dk> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181001112107.28956-1-rv@rasmusvillemoes.dk> References: <20180926102636.30691-1-rv@rasmusvillemoes.dk> <20181001112107.28956-1-rv@rasmusvillemoes.dk> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This documents the existing behaviour of "git help cmd" when cmd is an alias, as well as providing a hint to use the "git cmd --help" form to be taken directly to the man page for the aliased command. Signed-off-by: Rasmus Villemoes --- Documentation/git-help.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt index 83d25d825a..37e85868fd 100644 --- a/Documentation/git-help.txt +++ b/Documentation/git-help.txt @@ -29,6 +29,10 @@ guide is brought up. The 'man' program is used by default for this purpose, but this can be overridden by other options or configuration variables. +If an alias is given, git prints a note explaining what it is an alias +for on standard output. To get the manual page for the aliased +command, use `git COMMAND --help`. + Note that `git --help ...` is identical to `git help ...` because the former is internally converted into the latter.