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

Re: git silently ignores include directive with single quotes

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 8, 2018, 22:32 UTC
Message-ID
<87musr7h7q.fsf@evledraar.gmail.com>
In-Reply-To
<20180908211436.GA31560@sigill.intra.peff.net>
On Sat, Sep 08 2018, Jeff King wrote:
Show 62 quoted lines
> On Sat, Sep 08, 2018 at 09:54:14PM +0200, Ævar Arnfjörð Bjarmason wrote:
>
>> The reason missing includes are ignored is that the way this is expected
>> to be used is e.g.:
>>
>>     [include]
>>         path ~/.gitconfig.work
>>
>> Where .gitconfig.work is some configuration you're going to drop into
>> place on your $dayjob servers, but not on your personal machine, even
>> though you sync the same ~/.gitconfig everywhere.
>>
>> A lot of people who use includes rely on this, but I see from this
>> thread this should be better documented.
>
> Right, this was an intentional choice at the time the feature was added,
> to support this kind of feature. I'd note also that it mirrors other
> misspelled keys. E.g.:
>
>   [include]
>   psth = whatever
>
> will also not generate an error. This is also intentional, for two
> reasons:
>
>   1. Git's config format has always been designed to carry extra keys
>      used by third-party scripts and porcelain. So we don't actually
>      know the complete set of valid keys. (Though you could make an
>      argument that git-core could stake out include.* as its own).
>
>   2. It makes using multiple git versions easier in some ways (though
>      also harder in others). A config key that isn't known to the
>      current version will be quietly ignored.
>
> Of course those things mean that true spelling mistakes are harder to
> catch as such, because Git doesn't know that's what they are. And here
> I'm talking config _keys_, not values. So I'm just explaining the
> philosophical thinking that led to the "missing file is a silent noop".
> It doesn't _have_ to behave the same.
>
> That said, it _does_ behave the same and people are likely depending on
> it at this point. So if we introduce a warning, for example, there needs
> to be some way to suppress it.
>
> Probably:
>
>   [include]
>   warnOnMissing = false
>   path = ...
>
> would be enough (with the default being "true").
>
> You could even do:
>
>   [include]
>   warnOnMissing = false
>   path = one
>   warnOnMissing = true
>   path = two
>
> to treat two includes differently (though I'm not sure why you would
> want to).

I think this is introducing a brand new caveat into our *.ini syntax, i.e. that we're sensitive to the order in which we're parsing *different* keys.

I.e. we already had the concept that some keys override existing sets (e.g. user.name), but not that a x.y=foo controls the behavior of a subsequent a.b=bar, or the other way around.

This also makes programmatic (via "git config") editing of the config hard, we'd need to introduce something like:

    git config -f ~/.gitconfig a.b bar
    git config -f ~/.gitconfig --before a.b x.y foo
To set a.b=bar before x.y=foo, or --after or whatever.
Show 20 quoted lines
>> If we were to make nonexisting files an error, we'd need something like
>> an extension of the includeIf syntax added in 3efd0bedc6 ("config: add
>> conditional include", 2017-03-01) 3efd0bedc6 ("config: add conditional
>> include", 2017-03-01). I.e.:
>>
>>     [includeIfcond "test -e ~/.gitconfig.work"]
>>         path = ~/.gitconfig.work
>>
>> Or something like that, this is getting increasingly harder to shove
>> into the *.ini config syntax.
>
> I think it would be simpler to just introduce a new key that's a variant
> of "path". Like:
>
>   [include]
>   maybePath = ~/.gitconfig.work
>
> Though if it really is just a warning, the "warnOnMissing" above would
> make that unnecessary (and it also scales better if we have to end up
> adding more behavior tweaks in the future).

Yeah, we could do that, and it wouldn't break the model described above, We can make that work, but this would be nasty. E.g. are we going to treat EACCES and ENOENT the same way in this construct?

Previous: Junio C HamanoNext: Jeff King
Message 26 of 37 in “git silently ignores include directive with single quotes”
  1. Stas BekmanSep 8, 2018
  2. Martin ÅgrenSep 8, 2018
  3. Stas BekmanSep 8, 2018
  4. Stas BekmanSep 8, 2018
  5. Ævar Arnfjörð BjarmasonSep 8, 2018
  6. Stas BekmanSep 8, 2018
  7. Ævar Arnfjörð BjarmasonSep 8, 2018
  8. Stas BekmanSep 8, 2018
  9. Paul SmithSep 9, 2018
  10. Stas BekmanSep 9, 2018
  11. Ævar Arnfjörð BjarmasonSep 8, 2018
  12. Stas BekmanSep 8, 2018
  13. Ævar Arnfjörð BjarmasonSep 8, 2018
  14. Jeff KingSep 8, 2018
  15. Ramsay JonesSep 8, 2018
  16. Jeff KingSep 9, 2018
  17. Junio C HamanoSep 11, 2018
  18. Jeff KingSep 11, 2018
  19. Stas BekmanSep 23, 2018
  20. Ævar Arnfjörð BjarmasonSep 24, 2018
  21. Stas BekmanSep 24, 2018
  22. 0/1 Re: git silently ignores include directive with single quotesPhilip Oakley, Sep 24, 2018
  23. Stas BekmanSep 24, 2018
  24. 1/1 config doc: highlight the name=value syntaxPhilip Oakley, Sep 24, 2018
  25. Junio C HamanoSep 25, 2018
  26. Ævar Arnfjörð BjarmasonSep 8, 2018
  27. Jeff KingSep 9, 2018
  28. Jeff KingSep 8, 2018
  29. Stas BekmanSep 8, 2018
  30. Jeff KingSep 9, 2018
  31. Junio C HamanoSep 10, 2018
  32. Jonathan NiederSep 10, 2018
  33. Junio C HamanoSep 10, 2018
  34. Jonathan NiederSep 10, 2018
  35. Junio C HamanoSep 10, 2018
  36. Stas BekmanSep 10, 2018
  37. Junio C HamanoSep 10, 2018

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.