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

Re: [PATCH v2 2/3] config: values of pathname type can be prefixed with :(optional)

From
D. Ben Knoble <ben.knoble+github@gmail.com>
Date
Nov 2, 2025, 16:20 UTC
Message-ID
<CALnO6CC02MDThBJZg47ecZQnzdEE+tXPBcNzregduPvgkASceg@mail.gmail.com>
In-Reply-To
<a687ec17-8ee4-428e-bae5-063716d59a08@gmail.com>
Hi Phillip
On Tue, Sep 30, 2025 at 11:26 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 32 quoted lines
>
> Hi Ben
>
> On 28/09/2025 22:29, D. Ben Knoble wrote:
> > From: Junio C Hamano <gitster@pobox.com>
> >
> > Sometimes people want to specify additional configuration data
> > as "best effort" basis.  Maybe commit.template configuration file points
> > at somewhere in ~/template/ but on a particular system, the file may not
> > exist and the user may be OK without using the template in such a case.
> >
> > When the value given to a configuration variable whose type is
> > pathname wants to signal such an optional file, it can be marked by
> > prepending ":(optional)" in front of it.  Such a setting that is
> > marked optional would avoid getting the command barf for a missing
> > file, as an optional configuration setting that names a missing
> > file is not even seen.
>
> I think this would be a useful addition, we've had several people
> wanting to make blame.ignoreRevsFile optional and this provides a
> general way to do that.
>
> > --- a/config.c
> > +++ b/config.c
> > @@ -1279,11 +1279,23 @@ int git_config_string(char **dest, const char *var, const char *value)
> >
> >   int git_config_pathname(char **dest, const char *var, const char *value)
> >   {
> > +     int is_optional;
>
> This could be bool rather than int, the rest of the implementation looks
> good.

Agreed. For now I've split this change and the parseopt change to bool as separate commits, but I'm indifferent to making them a single change.

Show 33 quoted lines
>
> > --- a/t/t7500-commit-template-squash-signoff.sh
> > +++ b/t/t7500-commit-template-squash-signoff.sh
> > @@ -46,6 +46,15 @@ commit_msg_is ()
> >       )
> >   '
> >
> > +test_expect_success 'nonexistent optional template file in config' '
> > +     test_config commit.template ":(optional)$PWD"/notexist &&
> > +     (
> > +             GIT_EDITOR="echo hello >\"\$1\"" &&
>
> when git runs the editor this will be expanded to
>
>      sh -c 'echo hello >"$1" "$@"' 'echo hello >"$1"' path/to/file
>
> I think it should be
>
>      GIT_EDITOR="echo hello >"
>
> instead
> > +             export GIT_EDITOR &&
> > +             git commit --allow-empty
>
> Maybe I'm missing something but don't we want to ensure that we have a
> non-empty message here? Also as it is a single command we can avoid the
> subshell with
>
>      GIT_EDITOR="echo hello >" git commit
>
> Thanks
>
> Phillip

Great catch, thanks. I've certainly had some trouble with this expansion before [1]. It looks like this has been fixed in the version that was merged, so I'll avoid touching it further for now. And thanks also to Junio for the updates here.

[1]:
Previous: Junio C HamanoNext: D. Ben Knoble
Message 29 of 47 in “blame: Skip missing ignore-revs file”
  1. 0/1 blame: Skip missing ignore-revs fileNoah Pendleton, Aug 7, 2021
  2. Junio C HamanoAug 7, 2021
  3. Noah PendletonAug 7, 2021
  4. Junio C HamanoAug 8, 2021
  5. Junio C HamanoAug 8, 2021
  6. Noah PendletonAug 8, 2021
  7. Junio C HamanoAug 9, 2021
  8. 0/3 specifying a file that can optionally existJunio C Hamano, Oct 14, 2024
  9. 1/3 t7500: make each piece more independentJunio C Hamano, Oct 14, 2024
  10. 2/3 config: values of pathname type can be prefixed with :(optional)Junio C Hamano, Oct 14, 2024
  11. 3/3 parseopt: values of pathname type can be prefixed with :(optional)Junio C Hamano, Oct 14, 2024
  12. 0/3 specifying a file that can optionally existJunio C Hamano, May 1, 2025
  13. 1/3 t7500: make each piece more independentJunio C Hamano, May 1, 2025
  14. 2/3 config: values of pathname type can be prefixed with :(optional)Junio C Hamano, May 1, 2025
  15. Patrick SteinhardtMay 2, 2025
  16. Phillip WoodMay 2, 2025
  17. Junio C HamanoMay 2, 2025
  18. 3/3 parseopt: values of pathname type can be prefixed with :(optional)Junio C Hamano, May 1, 2025
  19. 0/3 Support :(optional) filepathsD. Ben Knoble, Sep 28, 2025
  20. 1/3 t7500: make each piece more independentD. Ben Knoble, Sep 28, 2025
  21. 2/3 config: values of pathname type can be prefixed with :(optional)D. Ben Knoble, Sep 28, 2025
  22. Phillip WoodSep 30, 2025
  23. Junio C HamanoOct 6, 2025
  24. Junio C HamanoOct 6, 2025
  25. Junio C HamanoOct 6, 2025
  26. Junio C HamanoOct 6, 2025
  27. Kristoffer HaugsbakkOct 7, 2025
  28. Junio C HamanoOct 7, 2025
  29. D. Ben KnobleNov 2, 2025
  30. 3/3 parseopt: values of pathname type can be prefixed with :(optional)D. Ben Knoble, Sep 28, 2025
  31. Phillip WoodSep 30, 2025
  32. D. Ben KnobleNov 2, 2025
  33. Eric SunshineNov 3, 2025
  34. D. Ben KnobleNov 4, 2025
  35. Junio C HamanoSep 28, 2025
  36. Ben KnobleSep 29, 2025
  37. t7500: fix tests with absolute path following ":(optional)" on WindowsJohannes Sixt, Oct 20, 2025
  38. Ben KnobleOct 20, 2025
  39. Johannes SixtOct 20, 2025
  40. Junio C HamanoOct 20, 2025
  41. D. Ben KnobleOct 20, 2025
  42. D. Ben KnobleOct 20, 2025
  43. Eric SunshineOct 20, 2025
  44. Junio C HamanoOct 20, 2025
  45. Johannes SixtOct 20, 2025
  46. Thranur AndulMar 4, 2022
  47. blame: add config `blame.ignoreRevsFileIsOptional`Noah Pendleton, Aug 8, 2021

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.