All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brandon Williams <bmwill@google.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] clone: handle empty config values in -c
Date: Mon, 1 May 2017 17:08:56 -0700	[thread overview]
Message-ID: <20170502000856.GI39135@google.com> (raw)
In-Reply-To: <20170502000515.GU28740@aiede.svl.corp.google.com>

On 05/01, Jonathan Nieder wrote:
> "git clone --config" uses the following incantation to add an item to
> a config file, instead of replacing an existing value:
> 
> 	git_config_set_multivar_gently(key, value, "^$", 0)
> 
> As long as no existing value matches the regex ^$, that works as
> intended and adds to the config.  When a value is empty, though, it
> replaces the existing value.
> 
> Noticed while trying to set credential.helper during a clone to use a
> specific helper without inheriting from ~/.gitconfig and
> /etc/gitconfig.  That is, I ran
> 
> 	git clone -c credential.helper= \
> 		-c credential.helper=myhelper \
> 		https://example.com/repo
> 
> intending to produce the configuration
> 
> 	[credential]
> 		helper =
> 		helper = myhelper
> 
> Without this patch, the 'helper =' line is not included and the
> credential helper from /etc/gitconfig gets used.
> 
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
> Thoughts?

After reading this I'm still a little fuzzy on why the empty helper line
is needed to avoid using the credential helper from /etc/gitconfig.

> 
> Thanks,
> Jonathan
> 
>  builtin/clone.c         | 4 +++-
>  t/t5611-clone-config.sh | 8 ++++++++
>  2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/clone.c b/builtin/clone.c
> index de85b85254..a6ae7d6180 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -773,7 +773,9 @@ static int checkout(int submodule_progress)
>  
>  static int write_one_config(const char *key, const char *value, void *data)
>  {
> -	return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0);
> +	return git_config_set_multivar_gently(key,
> +					      value ? value : "true",
> +					      CONFIG_REGEX_NONE, 0);
>  }
>  
>  static void write_config(struct string_list *config)
> diff --git a/t/t5611-clone-config.sh b/t/t5611-clone-config.sh
> index e4850b778c..39329eb7a8 100755
> --- a/t/t5611-clone-config.sh
> +++ b/t/t5611-clone-config.sh
> @@ -19,6 +19,14 @@ test_expect_success 'clone -c can set multi-keys' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'clone -c can set multi-keys, including some empty' '
> +	rm -rf child &&
> +	git clone -c credential.helper= -c credential.helper=hi . child &&
> +	printf "%s\n" "" hi >expect &&
> +	git --git-dir=child/.git config --get-all credential.helper >actual &&
> +	test_cmp expect actual
> +'
> +
>  test_expect_success 'clone -c without a value is boolean true' '
>  	rm -rf child &&
>  	git clone -c core.foo . child &&
> -- 
> 2.13.0.rc1.294.g07d810a77f
> 

-- 
Brandon Williams

  reply	other threads:[~2017-05-02  0:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-02  0:05 [PATCH] clone: handle empty config values in -c Jonathan Nieder
2017-05-02  0:08 ` Brandon Williams [this message]
2017-05-02  0:21   ` [PATCH] credential doc: make multiple-helper behavior more prominent (Re: [PATCH] clone: handle empty config values in -c) Jonathan Nieder
2017-05-02  0:26     ` Brandon Williams
2017-05-02  0:30     ` Jonathan Nieder
2017-05-02  3:11       ` Jeff King
2017-05-02  3:07     ` Jeff King
2017-05-02  2:56 ` [PATCH] clone: handle empty config values in -c Jeff King

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=20170502000856.GI39135@google.com \
    --to=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.