git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH RFC] init-db: introduce new -c/--config option

From
Jeff King <peff@peff.net>
Date
Mar 25, 2015, 18:39 UTC
Message-ID
<20150325183959.GA16989@peff.net>
In-Reply-To
<CANCZXo56RY18xKJbQoU=VRYApnKfy6e9ieu8munNsF6WB6YWYg@mail.gmail.com>
On Thu, Mar 26, 2015 at 12:30:13AM +0600, Alexander Kuleshov wrote:
Show 6 quoted lines
> I'm not sure about two things:
> 
> 1. Is there any way to do this with the current git? At least i didn't
> find how to do it, so decided to write this patch.
> If there is already ability to do the same without this patch, please
> let me know.

The reason we originally added "-c" to clone and not init is that clone performs several other follow-on actions after the repository is initialized. For example, you might want to run:

  git clone -c core.autocrlf=true ...

to have that option in place before clone checks out files to the working tree. There is no direct way to have "git init" set the config for you, but there is no harm in doing:

  git init
  git config core.autocrlf=true
because init returns control to you immediatel.
Show 9 quoted lines
> 2. Now current patch overwrite the value of the configuration option
> from config,
> if there is given option with the same key. For example, when we do git init,
> .git/config contains core.filemode = true. If we will pass
> core.filemode = false with this patch to git init,
> there will be core.filemode = false in the .git/config. So, I'm not
> sure about it.
> I looked on git clone -c/--config, it just adds the same option to the
> .git/config, but it looks strange to me....

Most options, when there are multiple present, will use the last-seen value (core.filemode is one of these, so having it there twice means the second one takes precedence). Some options form a list (e.g., fetch refspecs). So if you run:

  git clone -c remote.origin.fetch=refs/notes/*:refs/notes/* ...

you add a new refspec, but do not replace the default one to fetch the actual branches. The knowledge of which config keys are which is known only to the config callbacks, so it is generally safer for generic config-munging code to add a potentially overriding key (the downside is that you cannot use "-c" to "clear" a list-like key, but the inability to do that is a failing of the config code in general).

-Peff
Previous: Alexander KuleshovNext: Eric Sunshine
Message 3 of 4 in “init-db: introduce new -c/--config option”
  1. init-db: introduce new -c/--config optionAlexander Kuleshov, Mar 25, 2015
  2. Alexander KuleshovMar 25, 2015
  3. Jeff KingMar 25, 2015
  4. Eric SunshineMar 25, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.