git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Cc: Duy Nguyen <pclouds@gmail.com>
Subject: [PATCH 2/2] builtins: setup repository before print unknown command error
Date: Thu, 25 Mar 2010 20:38:15 +0700	[thread overview]
Message-ID: <1269524295-24569-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1269524295-24569-1-git-send-email-pclouds@gmail.com>

From: Duy Nguyen <pclouds@gmail.com>

help_unknown_cmd() will need to look into repository's config, in
order to collect all possible commands/aliases and give a
suggestion. So, repository must be set up before this function is
called.

As it is now, because
 - alias handling will always be done before help_unknown_cmd()
 - alias handling code will search and set up repository if found
 - alias handline code will not undo repository setup

These ensure that repository will always be set up (or attempted to
set up) before help_unknown_cmd(), so there is no issue. But the setup
dependency here is subtle. It may break some day if someone reorders
the loop, for example.

Make the repository setup explicit, to express it clearer, although
this code will never be run (It does not mean the code is not tested,
I removed alias handling code to reproduce the problem, and this code
helped fix it)

Signed-off-by: Duy Nguyen <pclouds@gmail.com>
---
 git.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/git.c b/git.c
index bd1d4bb..d84996c 100644
--- a/git.c
+++ b/git.c
@@ -547,6 +547,10 @@ int main(int argc, const char **argv)
 			exit(1);
 		}
 		if (!done_help) {
+			if (!startup_info->have_run_setup_gitdir) {
+				int nongit_ok;
+				setup_git_directory_gently(&nongit_ok);
+			}
 			cmd = argv[0] = help_unknown_cmd(cmd);
 			done_help = 1;
 		} else
-- 
1.7.0.rc1.541.g2da82.dirty

  reply	other threads:[~2010-03-25 19:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-25 13:38 [PATCH 1/2] builtins: do not commit pager choice early Nguyễn Thái Ngọc Duy
2010-03-25 13:38 ` Nguyễn Thái Ngọc Duy [this message]
2010-03-26 20:58   ` [PATCH 2/2] builtins: setup repository before print unknown command error Jonathan Nieder
2010-03-26 20:03 ` [PATCH 1/2] builtins: do not commit pager choice early Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1269524295-24569-2-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).