* [PATCH] doc: option value may be separate for valid reasons @ 2024-11-24 9:43 Junio C Hamano 2024-11-24 23:54 ` Eric Sunshine 2024-11-25 3:14 ` [PATCH v2] " Junio C Hamano 0 siblings, 2 replies; 6+ messages in thread From: Junio C Hamano @ 2024-11-24 9:43 UTC (permalink / raw) To: git Even though `git help cli` recommends users to prefer using "--option=value" over "--option value", there can be reasons why giving them separately is a good idea. One reason is that shells do not perform tilde expansion for `--option=~/path/name` but they expand `--options ~/path/name` just fine. This is not a problem for many options whose option parsing is properly written using OPT_FILENAME(), because the value given to OPT_FILENAME() is tilde-expanded internally by us, but some commands take a pathname as a mere string, which needs this trick to have the shell help us. I think the reason we originally decided to recommend the stuck form was because an option that takes an optional value requires you to use it in the stuck form, and it is one less thing for users to worry about if they get into the habit to always use the stuck form. But we should be discouraging ourselves from adding an option with an optional value in the first place, and we might want to weaken the current recommendation. In any case, let's describe this one case where it is necessary to use the separate form, with an example. Signed-off-by: Junio C Hamano <gitster@pobox.com> --- Documentation/gitcli.txt | 10 ++++++++++ Documentation/gitcredentials.txt | 5 +++++ 2 files changed, 15 insertions(+) diff --git c/Documentation/gitcli.txt w/Documentation/gitcli.txt index 7c709324ba..e484be9a36 100644 --- c/Documentation/gitcli.txt +++ w/Documentation/gitcli.txt @@ -88,10 +88,20 @@ scripting Git: other words, write `git foo -oArg` instead of `git foo -o Arg` for short options, and `git foo --long-opt=Arg` instead of `git foo --long-opt Arg` for long options. An option that takes optional option-argument must be written in the 'stuck' form. + * Despite the above suggestion, when Arg is a path relative to the + home directory of a user, e.g. ~/directory/file or ~u/d/f, you + may want to use the separate form, e.g. `git credential-store + --file ~/sec/rit`, not `git credential-store --file=~/sec/rit`. + The shell will expand `~/` in the former to your home directory, + but most shells keep the tilde in the latter. Some of our + commands know how to tilde-expand the option value internally, + but not all. The `--file` option of `credential-store` is an + example that it needs shell's help to tilde-expand its value. + * When you give a revision parameter to a command, make sure the parameter is not ambiguous with a name of a file in the work tree. E.g. do not write `git log -1 HEAD` but write `git log -1 HEAD --`; the former will not work if you happen to have a file called `HEAD` in the work tree. diff --git c/Documentation/gitcredentials.txt w/Documentation/gitcredentials.txt index 71dd19731a..f6ce923f25 100644 --- c/Documentation/gitcredentials.txt +++ w/Documentation/gitcredentials.txt @@ -240,10 +240,15 @@ Here are some example specifications: # the arguments are parsed by the shell, so use shell # quoting if necessary [credential] helper = "foo --bar='whitespace arg'" +# store helper (discouraged) with custom location for the db file; +# tilde expansion often requires the filename as a separate argument. +[credential] + helper = "store --file ~/.git-secret.txt" + # you can also use an absolute path, which will not use the git wrapper [credential] helper = "/path/to/my/helper --with-arguments" # or you can specify your own shell snippet ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] doc: option value may be separate for valid reasons 2024-11-24 9:43 [PATCH] doc: option value may be separate for valid reasons Junio C Hamano @ 2024-11-24 23:54 ` Eric Sunshine 2024-11-25 3:04 ` Junio C Hamano 2024-11-25 3:14 ` [PATCH v2] " Junio C Hamano 1 sibling, 1 reply; 6+ messages in thread From: Eric Sunshine @ 2024-11-24 23:54 UTC (permalink / raw) To: Junio C Hamano; +Cc: git On Sun, Nov 24, 2024 at 4:44 AM Junio C Hamano <gitster@pobox.com> wrote: > Even though `git help cli` recommends users to prefer using > "--option=value" over "--option value", there can be reasons why > giving them separately is a good idea. One reason is that shells do > not perform tilde expansion for `--option=~/path/name` but they > expand `--options ~/path/name` just fine. > > This is not a problem for many options whose option parsing is > properly written using OPT_FILENAME(), because the value given to > OPT_FILENAME() is tilde-expanded internally by us, but some commands > take a pathname as a mere string, which needs this trick to have the > shell help us. > > I think the reason we originally decided to recommend the stuck form > was because an option that takes an optional value requires you to > use it in the stuck form, and it is one less thing for users to > worry about if they get into the habit to always use the stuck form. > But we should be discouraging ourselves from adding an option with > an optional value in the first place, and we might want to weaken > the current recommendation. > > In any case, let's describe this one case where it is necessary to > use the separate form, with an example. > > Signed-off-by: Junio C Hamano <gitster@pobox.com> > --- > diff --git c/Documentation/gitcli.txt w/Documentation/gitcli.txt > @@ -88,10 +88,20 @@ scripting Git: > + * Despite the above suggestion, when Arg is a path relative to the > + home directory of a user, e.g. ~/directory/file or ~u/d/f, you > + may want to use the separate form, e.g. `git credential-store > + --file ~/sec/rit`, not `git credential-store --file=~/sec/rit`. > + The shell will expand `~/` in the former to your home directory, > + but most shells keep the tilde in the latter. Some of our > + commands know how to tilde-expand the option value internally, > + but not all. The `--file` option of `credential-store` is an > + example that it needs shell's help to tilde-expand its value. I'm not sure the final sentence adds any value considering that credential-store was already mentioned in the example earlier in the paragraph, though I suppose it doesn't hurt to keep the sentence. > diff --git c/Documentation/gitcredentials.txt w/Documentation/gitcredentials.txt > @@ -240,10 +240,15 @@ Here are some example specifications: > # the arguments are parsed by the shell, so use shell > # quoting if necessary > [credential] > helper = "foo --bar='whitespace arg'" > > +# store helper (discouraged) with custom location for the db file; > +# tilde expansion often requires the filename as a separate argument. > +[credential] > + helper = "store --file ~/.git-secret.txt" In the context of the commit message, I understand why you added the comment above this example, but as a mere user without having that context, I think the part starting "tilde expansion..." would confuse me more than help. Perhaps being a bit more explicit might help: # use `--file ~/path` rather than `--file=~/path` to allow the # shell to expand tilde to the home directory ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] doc: option value may be separate for valid reasons 2024-11-24 23:54 ` Eric Sunshine @ 2024-11-25 3:04 ` Junio C Hamano 0 siblings, 0 replies; 6+ messages in thread From: Junio C Hamano @ 2024-11-25 3:04 UTC (permalink / raw) To: Eric Sunshine; +Cc: git Eric Sunshine <sunshine@sunshineco.com> writes: >> + may want to use the separate form, e.g. `git credential-store >> + --file ~/sec/rit`, not `git credential-store --file=~/sec/rit`. >> + The shell will expand `~/` in the former to your home directory, >> + but most shells keep the tilde in the latter. Some of our >> + commands know how to tilde-expand the option value internally, >> + but not all. The `--file` option of `credential-store` is an >> + example that it needs shell's help to tilde-expand its value. > > I'm not sure the final sentence adds any value considering that > credential-store was already mentioned in the example earlier in the > paragraph, though I suppose it doesn't hurt to keep the sentence. Probably. >> diff --git c/Documentation/gitcredentials.txt w/Documentation/gitcredentials.txt >> @@ -240,10 +240,15 @@ Here are some example specifications: >> # the arguments are parsed by the shell, so use shell >> # quoting if necessary >> [credential] >> helper = "foo --bar='whitespace arg'" >> >> +# store helper (discouraged) with custom location for the db file; >> +# tilde expansion often requires the filename as a separate argument. >> +[credential] >> + helper = "store --file ~/.git-secret.txt" > > In the context of the commit message, I understand why you added the > comment above this example, but as a mere user without having that > context, I think the part starting "tilde expansion..." would confuse > me more than help. Perhaps being a bit more explicit might help: > > # use `--file ~/path` rather than `--file=~/path` to allow the > # shell to expand tilde to the home directory You're right. That reads much better. Thanks. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] doc: option value may be separate for valid reasons 2024-11-24 9:43 [PATCH] doc: option value may be separate for valid reasons Junio C Hamano 2024-11-24 23:54 ` Eric Sunshine @ 2024-11-25 3:14 ` Junio C Hamano 2024-11-25 3:35 ` Eric Sunshine 1 sibling, 1 reply; 6+ messages in thread From: Junio C Hamano @ 2024-11-25 3:14 UTC (permalink / raw) To: git, Eric Sunshine Even though `git help cli` recommends users to prefer using "--option=value" over "--option value", there can be reasons why giving them separately is a good idea. One reason is that shells do not perform tilde expansion for `--option=~/path/name` but they expand `--options ~/path/name` just fine. This is not a problem for many options whose option parsing is properly written using OPT_FILENAME(), because the value given to OPT_FILENAME() is tilde-expanded internally by us, but some commands take a pathname as a mere string, which needs this trick to have the shell help us. I think the reason we originally decided to recommend the stuck form was because an option that takes an optional value requires you to use it in the stuck form, and it is one less thing for users to worry about if they get into the habit to always use the stuck form. But we should be discouraging ourselves from adding an option with an optional value in the first place, and we might want to weaken the current recommendation. In any case, let's describe this one case where it is necessary to use the separate form, with an example. Signed-off-by: Junio C Hamano <gitster@pobox.com> --- Documentation/gitcli.txt | 9 +++++++++ Documentation/gitcredentials.txt | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt index 7c709324ba..bd62cbd043 100644 --- a/Documentation/gitcli.txt +++ b/Documentation/gitcli.txt @@ -90,6 +90,15 @@ scripting Git: for long options. An option that takes optional option-argument must be written in the 'stuck' form. + * Despite the above suggestion, when Arg is a path relative to the + home directory of a user, e.g. ~/directory/file or ~u/d/f, you + may want to use the separate form, e.g. `git foo --file ~/mine`, + not `git foo --file=~/mine`. The shell will expand `~/` in the + former to your home directory, but most shells keep the tilde in + the latter. Some of our commands know how to tilde-expand the + option value even when given in the stuck form, but not all of + them do. + * When you give a revision parameter to a command, make sure the parameter is not ambiguous with a name of a file in the work tree. E.g. do not write `git log -1 HEAD` but write `git log -1 HEAD --`; the former will not work diff --git a/Documentation/gitcredentials.txt b/Documentation/gitcredentials.txt index 71dd19731a..35a7452c8f 100644 --- a/Documentation/gitcredentials.txt +++ b/Documentation/gitcredentials.txt @@ -242,6 +242,12 @@ Here are some example specifications: [credential] helper = "foo --bar='whitespace arg'" +# store helper (discouraged) with custom location for the db file; +# use `--file ~/.git-secret.txt`, rather than `--file=~/.git-secret.txt`, +# to allow the shell to expand tilde to the home directory. +[credential] + helper = "store --file ~/.git-secret.txt" + # you can also use an absolute path, which will not use the git wrapper [credential] helper = "/path/to/my/helper --with-arguments" Interdiff: diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt index e484be9a36..bd62cbd043 100644 --- a/Documentation/gitcli.txt +++ b/Documentation/gitcli.txt @@ -92,13 +92,12 @@ scripting Git: * Despite the above suggestion, when Arg is a path relative to the home directory of a user, e.g. ~/directory/file or ~u/d/f, you - may want to use the separate form, e.g. `git credential-store - --file ~/sec/rit`, not `git credential-store --file=~/sec/rit`. - The shell will expand `~/` in the former to your home directory, - but most shells keep the tilde in the latter. Some of our - commands know how to tilde-expand the option value internally, - but not all. The `--file` option of `credential-store` is an - example that it needs shell's help to tilde-expand its value. + may want to use the separate form, e.g. `git foo --file ~/mine`, + not `git foo --file=~/mine`. The shell will expand `~/` in the + former to your home directory, but most shells keep the tilde in + the latter. Some of our commands know how to tilde-expand the + option value even when given in the stuck form, but not all of + them do. * When you give a revision parameter to a command, make sure the parameter is not ambiguous with a name of a file in the work tree. E.g. do not write diff --git a/Documentation/gitcredentials.txt b/Documentation/gitcredentials.txt index f6ce923f25..35a7452c8f 100644 --- a/Documentation/gitcredentials.txt +++ b/Documentation/gitcredentials.txt @@ -243,7 +243,8 @@ Here are some example specifications: helper = "foo --bar='whitespace arg'" # store helper (discouraged) with custom location for the db file; -# tilde expansion often requires the filename as a separate argument. +# use `--file ~/.git-secret.txt`, rather than `--file=~/.git-secret.txt`, +# to allow the shell to expand tilde to the home directory. [credential] helper = "store --file ~/.git-secret.txt" -- 2.47.0-496-g788c9fe963 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] doc: option value may be separate for valid reasons 2024-11-25 3:14 ` [PATCH v2] " Junio C Hamano @ 2024-11-25 3:35 ` Eric Sunshine 2024-11-25 4:49 ` Junio C Hamano 0 siblings, 1 reply; 6+ messages in thread From: Eric Sunshine @ 2024-11-25 3:35 UTC (permalink / raw) To: Junio C Hamano; +Cc: git On Sun, Nov 24, 2024 at 10:14 PM Junio C Hamano <gitster@pobox.com> wrote: > Even though `git help cli` recommends users to prefer using > "--option=value" over "--option value", there can be reasons why > giving them separately is a good idea. One reason is that shells do > not perform tilde expansion for `--option=~/path/name` but they > expand `--options ~/path/name` just fine. > > This is not a problem for many options whose option parsing is > properly written using OPT_FILENAME(), because the value given to > OPT_FILENAME() is tilde-expanded internally by us, but some commands > take a pathname as a mere string, which needs this trick to have the > shell help us. > > I think the reason we originally decided to recommend the stuck form > was because an option that takes an optional value requires you to > use it in the stuck form, and it is one less thing for users to > worry about if they get into the habit to always use the stuck form. > But we should be discouraging ourselves from adding an option with > an optional value in the first place, and we might want to weaken > the current recommendation. > > In any case, let's describe this one case where it is necessary to > use the separate form, with an example. > > Signed-off-by: Junio C Hamano <gitster@pobox.com> v2 looks good to me. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] doc: option value may be separate for valid reasons 2024-11-25 3:35 ` Eric Sunshine @ 2024-11-25 4:49 ` Junio C Hamano 0 siblings, 0 replies; 6+ messages in thread From: Junio C Hamano @ 2024-11-25 4:49 UTC (permalink / raw) To: Eric Sunshine; +Cc: git Eric Sunshine <sunshine@sunshineco.com> writes: > On Sun, Nov 24, 2024 at 10:14 PM Junio C Hamano <gitster@pobox.com> wrote: >> Even though `git help cli` recommends users to prefer using >> "--option=value" over "--option value", there can be reasons why >> giving them separately is a good idea. One reason is that shells do >> not perform tilde expansion for `--option=~/path/name` but they >> expand `--options ~/path/name` just fine. >> >> This is not a problem for many options whose option parsing is >> properly written using OPT_FILENAME(), because the value given to >> OPT_FILENAME() is tilde-expanded internally by us, but some commands >> take a pathname as a mere string, which needs this trick to have the >> shell help us. >> >> I think the reason we originally decided to recommend the stuck form >> was because an option that takes an optional value requires you to >> use it in the stuck form, and it is one less thing for users to >> worry about if they get into the habit to always use the stuck form. >> But we should be discouraging ourselves from adding an option with >> an optional value in the first place, and we might want to weaken >> the current recommendation. >> >> In any case, let's describe this one case where it is necessary to >> use the separate form, with an example. >> >> Signed-off-by: Junio C Hamano <gitster@pobox.com> > > v2 looks good to me. Thanks. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-11-25 4:49 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-11-24 9:43 [PATCH] doc: option value may be separate for valid reasons Junio C Hamano 2024-11-24 23:54 ` Eric Sunshine 2024-11-25 3:04 ` Junio C Hamano 2024-11-25 3:14 ` [PATCH v2] " Junio C Hamano 2024-11-25 3:35 ` Eric Sunshine 2024-11-25 4:49 ` Junio C Hamano
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).