Re: [PATCH] git config: error when editing a repo config and not being in one
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 29, 2009, 23:01 UTC
- Message-ID
- <7vws935ak8.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <1241043939-29013-1-git-send-email-felipe.contreras@gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 23 quoted lines
> Let's throw an error on this specific case. If the user specifies the
> config file, he must know what he is doing.
>
> Teemu Likonen pointed this out.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
> builtin-config.c | 2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/builtin-config.c b/builtin-config.c
> index d8da72c..6e936e1 100644
> --- a/builtin-config.c
> +++ b/builtin-config.c
> @@ -390,6 +390,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
> }
> else if (actions == ACTION_EDIT) {
> check_argc(argc, 0, 0);
> + if (!config_exclusive_filename && !is_inside_git_dir())
> + die("not in a git directory");
> git_config(git_default_config, NULL);
> launch_editor(config_exclusive_filename ?
> config_exclusive_filename : git_path("config"),How could this be correct?
When you are inside a work tree controlled by a git repository, and you want to edit the configuration file that belongs to the repository, I do not think is_inside_git_dir() is true.
What you are trying to catch is if $GIT_DIR exists (not in the sense that "is it a non-empty string?", but in the sense that "does it point at an existing directory?"), I think.
So perhaps you want to say something like this instead?
No, I did not test it.
builtin-config.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c index d8da72c..a4bd516 100644 --- a/builtin-config.c +++ b/builtin-config.c @@ -390,6 +390,12 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix) } else if (actions == ACTION_EDIT) { check_argc(argc, 0, 0); + if (!config_exclusive_filename) { + const char *git = get_git_dir(); + struct stat sb; + if (!git || stat(git, &sb) || !S_ISDIR(sb.st_mode)) + die("not in a git directory"); + } git_config(git_default_config, NULL); launch_editor(config_exclusive_filename ? config_exclusive_filename : git_path("config"),