* [PATCH] config: introduce an Operating System-specific `includeIf` condition @ 2022-11-21 13:39 Johannes Schindelin via GitGitGadget 2022-11-21 13:51 ` Ævar Arnfjörð Bjarmason ` (2 more replies) 0 siblings, 3 replies; 26+ messages in thread From: Johannes Schindelin via GitGitGadget @ 2022-11-21 13:39 UTC (permalink / raw) To: git; +Cc: Johannes Schindelin, Johannes Schindelin From: Johannes Schindelin <johannes.schindelin@gmx.de> It is relatively common for users to maintain identical `~/.gitconfig` files across all of their setups, using the `includeIf` construct liberally to adjust the settings to the respective setup as needed. In case of Operating System-specific adjustments, Git currently offers no support to the users and they typically use a work-around like this: [includeIf "gitdir:/home/"] path = ~/.gitconfig-linux [includeIf "gitdir:/Users/"] path = ~/.gitconfig-mac [includeIf "gitdir:C:"] path = ~/.gitconfig-windows However, this is fragile, as it would not even allow to discern between Operating Systems that happen to host their home directories in `/home/`, such as Linux and the BSDs. Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the system name, i.e. the output of `uname -s`. This addresses https://github.com/git-for-windows/git/issues/4125 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- config: introduce an Operating System-specific includeIf condition I was about to write up guidelines how to write this patch, but it turned out that it was much faster to write the patch instead. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1429%2Fdscho%2Finclude-if-os-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1429/dscho/include-if-os-v1 Pull-Request: https://github.com/gitgitgadget/git/pull/1429 Documentation/config.txt | 5 +++++ config.c | 11 +++++++++++ t/t1309-early-config.sh | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index e376d547ce0..2db73d8228e 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -186,6 +186,11 @@ As for the naming of this keyword, it is for forwards compatibiliy with a naming scheme that supports more variable-based include conditions, but currently Git only supports the exact keyword described above. +`os`:: + The data that follows this keyword is taken as the name of an + Operating System; If it matches the output of `uname -s`, the + include condition is met. + A few more notes on matching via `gitdir` and `gitdir/i`: * Symlinks in `$GIT_DIR` are not resolved before matching. diff --git a/config.c b/config.c index 9b0e9c93285..9ab311ae99b 100644 --- a/config.c +++ b/config.c @@ -394,6 +394,15 @@ static int include_by_remote_url(struct config_include_data *inc, inc->remote_urls); } +static int include_by_os(const char *cond, size_t cond_len) +{ + struct utsname uname_info; + + return !uname(&uname_info) && + !strncasecmp(uname_info.sysname, cond, cond_len) && + !uname_info.sysname[cond_len]; +} + static int include_condition_is_true(struct config_include_data *inc, const char *cond, size_t cond_len) { @@ -408,6 +417,8 @@ static int include_condition_is_true(struct config_include_data *inc, else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond, &cond_len)) return include_by_remote_url(inc, cond, cond_len); + else if (skip_prefix_mem(cond, cond_len, "os:", &cond, &cond_len)) + return include_by_os(cond, cond_len); /* unknown conditionals are always false */ return 0; diff --git a/t/t1309-early-config.sh b/t/t1309-early-config.sh index 537435b90ae..7da67af06e7 100755 --- a/t/t1309-early-config.sh +++ b/t/t1309-early-config.sh @@ -100,4 +100,20 @@ test_expect_success 'onbranch config outside of git repo' ' nongit git help ' +test_expect_success '[includeIf "os:..."]' ' + test_config x.y 0 && + echo "[x] y = z" >.git/xyz && + + if test_have_prereq MINGW + then + uname_s=Windows + else + uname_s="$(uname -s)" + fi && + test_config "includeIf.os:not-$uname_s.path" xyz && + test 0 = "$(git config x.y)" && + test_config "includeIf.os:$uname_s.path" xyz && + test z = "$(git config x.y)" +' + test_done base-commit: e4a4b31577c7419497ac30cebe30d755b97752c5 -- gitgitgadget ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 13:39 [PATCH] config: introduce an Operating System-specific `includeIf` condition Johannes Schindelin via GitGitGadget @ 2022-11-21 13:51 ` Ævar Arnfjörð Bjarmason 2022-11-21 15:51 ` Phillip Wood 2022-11-21 19:19 ` [PATCH v2] " Johannes Schindelin via GitGitGadget 2022-11-22 0:03 ` [PATCH] " Junio C Hamano 2 siblings, 1 reply; 26+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2022-11-21 13:51 UTC (permalink / raw) To: Johannes Schindelin via GitGitGadget; +Cc: git, Johannes Schindelin On Mon, Nov 21 2022, Johannes Schindelin via GitGitGadget wrote: > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > It is relatively common for users to maintain identical `~/.gitconfig` > files across all of their setups, using the `includeIf` construct > liberally to adjust the settings to the respective setup as needed. > > In case of Operating System-specific adjustments, Git currently offers > no support to the users and they typically use a work-around like this: > > [includeIf "gitdir:/home/"] > path = ~/.gitconfig-linux > [includeIf "gitdir:/Users/"] > path = ~/.gitconfig-mac > [includeIf "gitdir:C:"] > path = ~/.gitconfig-windows > > However, this is fragile, as it would not even allow to discern between > Operating Systems that happen to host their home directories in > `/home/`, such as Linux and the BSDs. This looks like a really sensible thing to do, thanks. > +`os`:: > + The data that follows this keyword is taken as the name of an > + Operating System; If it matches the output of `uname -s`, the > + include condition is met. Here yu say it "matches uname -s", but later in the test we can see that's not the case. This is because compat/mingw.c is the source of that "Windows" string, which we use for the uname() at the C level. I don't think we've needed to document it before, but we should do so here I'd think. Per https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux users would follow these docs, try MinGw, then be confused, no? > +static int include_by_os(const char *cond, size_t cond_len) > +{ > + struct utsname uname_info; > + > + return !uname(&uname_info) && > + !strncasecmp(uname_info.sysname, cond, cond_len) && Our config.mak.uname doesn't to case-insensitive uname matching, and AFAIK these don't change between platforms versions. So why do we need to support LINUX, LiNuX etc. in addition to the canonical Linux? I'm not opposed to it if there's a good reason, but as we have "gitdir" and "gitdir/i" shouldn't we make that "os/i" for consistency, if it's needed? > +test_expect_success '[includeIf "os:..."]' ' > + test_config x.y 0 && > + echo "[x] y = z" >.git/xyz && > + > + if test_have_prereq MINGW > + then > + uname_s=Windows > + else > + uname_s="$(uname -s)" > + fi && > + test_config "includeIf.os:not-$uname_s.path" xyz && Re above: If it is important to support LINUX etc. these tests should check it, they pass if it's converted to strncmp(). > + test 0 = "$(git config x.y)" && Hides segfaults, use test_cmp or test_cmp_config? > + test_config "includeIf.os:$uname_s.path" xyz && > + test z = "$(git config x.y)" Ditto segfault-hiding. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 13:51 ` Ævar Arnfjörð Bjarmason @ 2022-11-21 15:51 ` Phillip Wood 2022-11-21 19:18 ` Johannes Schindelin 0 siblings, 1 reply; 26+ messages in thread From: Phillip Wood @ 2022-11-21 15:51 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason, Johannes Schindelin via GitGitGadget Cc: git, Johannes Schindelin Hi Dscho and Ævar On 21/11/2022 13:51, Ævar Arnfjörð Bjarmason wrote: > > On Mon, Nov 21 2022, Johannes Schindelin via GitGitGadget wrote: > >> From: Johannes Schindelin <johannes.schindelin@gmx.de> >> >> It is relatively common for users to maintain identical `~/.gitconfig` >> files across all of their setups, using the `includeIf` construct >> liberally to adjust the settings to the respective setup as needed. >> >> In case of Operating System-specific adjustments, Git currently offers >> no support to the users and they typically use a work-around like this: >> >> [includeIf "gitdir:/home/"] >> path = ~/.gitconfig-linux >> [includeIf "gitdir:/Users/"] >> path = ~/.gitconfig-mac >> [includeIf "gitdir:C:"] >> path = ~/.gitconfig-windows >> >> However, this is fragile, as it would not even allow to discern between >> Operating Systems that happen to host their home directories in >> `/home/`, such as Linux and the BSDs. > > This looks like a really sensible thing to do, thanks. Yes, it looks like a really useful enhancement >> +`os`:: >> + The data that follows this keyword is taken as the name of an >> + Operating System; If it matches the output of `uname -s`, the Maybe add e.g. "Windows or Linux" after Operating System? >> +static int include_by_os(const char *cond, size_t cond_len) >> +{ >> + struct utsname uname_info; >> + >> + return !uname(&uname_info) && >> + !strncasecmp(uname_info.sysname, cond, cond_len) && > > Our config.mak.uname doesn't to case-insensitive uname matching, and > AFAIK these don't change between platforms versions. So why do we need > to support LINUX, LiNuX etc. in addition to the canonical Linux? > > I'm not opposed to it if there's a good reason, but as we have "gitdir" > and "gitdir/i" shouldn't we make that "os/i" for consistency, if it's > needed? Why should we penalize users who write "linux" rather than "Linux"? Making the comparison case insensitive seems eminently sensible. File systems can be case sensitive so having the option to specify whether a match for "gitdir" is case sensitive or not makes sense there but not for the name of an operating system. Best Wishes Phillip ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 15:51 ` Phillip Wood @ 2022-11-21 19:18 ` Johannes Schindelin 0 siblings, 0 replies; 26+ messages in thread From: Johannes Schindelin @ 2022-11-21 19:18 UTC (permalink / raw) To: phillip.wood Cc: Ævar Arnfjörð Bjarmason, Johannes Schindelin via GitGitGadget, git [-- Attachment #1: Type: text/plain, Size: 1011 bytes --] Hi Phillip & Ævar, [Ævar, in your mail, which I suggest could have used some editing for spelling and brevity, I found only the concern about `uname -s` relevant, and since Phillip's suggestion is more actionable than the somewhat diffuse excurse about something to do with something in a StackOverflow thread, I will only reply here.] On Mon, 21 Nov 2022, Phillip Wood wrote: > On 21/11/2022 13:51, Ævar Arnfjörð Bjarmason wrote: > > > > On Mon, Nov 21 2022, Johannes Schindelin via GitGitGadget wrote: > > > > [...] > > > +`os`:: > > > + The data that follows this keyword is taken as the name of an > > > + Operating System; If it matches the output of `uname -s`, the > > Maybe add e.g. "Windows or Linux" after Operating System? Excellent idea. I'll also drop mentioning `uname -s` because it assumes more about the users' setup than can be assumed. I also replaced a space character in the added test case that was doubled by mistake with a single one. Ciao, Dscho ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 13:39 [PATCH] config: introduce an Operating System-specific `includeIf` condition Johannes Schindelin via GitGitGadget 2022-11-21 13:51 ` Ævar Arnfjörð Bjarmason @ 2022-11-21 19:19 ` Johannes Schindelin via GitGitGadget 2022-11-21 23:32 ` Jeff King ` (3 more replies) 2022-11-22 0:03 ` [PATCH] " Junio C Hamano 2 siblings, 4 replies; 26+ messages in thread From: Johannes Schindelin via GitGitGadget @ 2022-11-21 19:19 UTC (permalink / raw) To: git Cc: Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin, Johannes Schindelin From: Johannes Schindelin <johannes.schindelin@gmx.de> It is relatively common for users to maintain identical `~/.gitconfig` files across all of their setups, using the `includeIf` construct liberally to adjust the settings to the respective setup as needed. In case of Operating System-specific adjustments, Git currently offers no support to the users and they typically use a work-around like this: [includeIf "gitdir:/home/"] path = ~/.gitconfig-linux [includeIf "gitdir:/Users/"] path = ~/.gitconfig-mac [includeIf "gitdir:C:"] path = ~/.gitconfig-windows However, this is fragile, as it would not even allow to discern between Operating Systems that happen to host their home directories in `/home/`, such as Linux and the BSDs. Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the system name, i.e. the output of `uname -s`. This addresses https://github.com/git-for-windows/git/issues/4125 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- config: introduce an Operating System-specific includeIf condition I was about to write up guidelines how to write this patch, but it turned out that it was much faster to write the patch instead. Changes since v1: * The documentation now avoids mentioning uname -s and clarifies what it means by offering examples. * Replaced a double space in the test case with a single one. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1429%2Fdscho%2Finclude-if-os-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1429/dscho/include-if-os-v2 Pull-Request: https://github.com/gitgitgadget/git/pull/1429 Range-diff vs v1: 1: a7eb4a9d438 ! 1: 45231533883 config: introduce an Operating System-specific `includeIf` condition @@ Documentation/config.txt: As for the naming of this keyword, it is for forwards +`os`:: + The data that follows this keyword is taken as the name of an -+ Operating System; If it matches the output of `uname -s`, the -+ include condition is met. ++ Operating System, e.g. `Linux` or `Windows`; If it matches the ++ current Operating System, the include condition is met. + A few more notes on matching via `gitdir` and `gitdir/i`: @@ t/t1309-early-config.sh: test_expect_success 'onbranch config outside of git rep + uname_s="$(uname -s)" + fi && + test_config "includeIf.os:not-$uname_s.path" xyz && -+ test 0 = "$(git config x.y)" && ++ test 0 = "$(git config x.y)" && + test_config "includeIf.os:$uname_s.path" xyz && + test z = "$(git config x.y)" +' Documentation/config.txt | 5 +++++ config.c | 11 +++++++++++ t/t1309-early-config.sh | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index e376d547ce0..b90bcd8ecfe 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -186,6 +186,11 @@ As for the naming of this keyword, it is for forwards compatibiliy with a naming scheme that supports more variable-based include conditions, but currently Git only supports the exact keyword described above. +`os`:: + The data that follows this keyword is taken as the name of an + Operating System, e.g. `Linux` or `Windows`; If it matches the + current Operating System, the include condition is met. + A few more notes on matching via `gitdir` and `gitdir/i`: * Symlinks in `$GIT_DIR` are not resolved before matching. diff --git a/config.c b/config.c index 9b0e9c93285..9ab311ae99b 100644 --- a/config.c +++ b/config.c @@ -394,6 +394,15 @@ static int include_by_remote_url(struct config_include_data *inc, inc->remote_urls); } +static int include_by_os(const char *cond, size_t cond_len) +{ + struct utsname uname_info; + + return !uname(&uname_info) && + !strncasecmp(uname_info.sysname, cond, cond_len) && + !uname_info.sysname[cond_len]; +} + static int include_condition_is_true(struct config_include_data *inc, const char *cond, size_t cond_len) { @@ -408,6 +417,8 @@ static int include_condition_is_true(struct config_include_data *inc, else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond, &cond_len)) return include_by_remote_url(inc, cond, cond_len); + else if (skip_prefix_mem(cond, cond_len, "os:", &cond, &cond_len)) + return include_by_os(cond, cond_len); /* unknown conditionals are always false */ return 0; diff --git a/t/t1309-early-config.sh b/t/t1309-early-config.sh index 537435b90ae..b36afe1a528 100755 --- a/t/t1309-early-config.sh +++ b/t/t1309-early-config.sh @@ -100,4 +100,20 @@ test_expect_success 'onbranch config outside of git repo' ' nongit git help ' +test_expect_success '[includeIf "os:..."]' ' + test_config x.y 0 && + echo "[x] y = z" >.git/xyz && + + if test_have_prereq MINGW + then + uname_s=Windows + else + uname_s="$(uname -s)" + fi && + test_config "includeIf.os:not-$uname_s.path" xyz && + test 0 = "$(git config x.y)" && + test_config "includeIf.os:$uname_s.path" xyz && + test z = "$(git config x.y)" +' + test_done base-commit: e4a4b31577c7419497ac30cebe30d755b97752c5 -- gitgitgadget ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 19:19 ` [PATCH v2] " Johannes Schindelin via GitGitGadget @ 2022-11-21 23:32 ` Jeff King 2022-11-23 11:54 ` Đoàn Trần Công Danh 2022-11-22 14:01 ` Ævar Arnfjörð Bjarmason ` (2 subsequent siblings) 3 siblings, 1 reply; 26+ messages in thread From: Jeff King @ 2022-11-21 23:32 UTC (permalink / raw) To: Johannes Schindelin via GitGitGadget Cc: git, Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin On Mon, Nov 21, 2022 at 07:19:48PM +0000, Johannes Schindelin via GitGitGadget wrote: > It is relatively common for users to maintain identical `~/.gitconfig` > files across all of their setups, using the `includeIf` construct > liberally to adjust the settings to the respective setup as needed. This seems like a reasonable thing to have in general, but I wonder if you have an example of how people use this. Mostly I am wondering: - is it sometimes a misuse, where users _think_ that the OS is correlated with some feature of Git. And they would be better off with some flag like "does the current platform support fsmonitor". - for cases where it really is "uname -s" the best differentiator? Or would they commonly want to lump FreeBSD and Linux into the same category, or to tell the difference between Debian versus Fedora? -Peff ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 23:32 ` Jeff King @ 2022-11-23 11:54 ` Đoàn Trần Công Danh 2022-11-24 0:56 ` Jeff King 0 siblings, 1 reply; 26+ messages in thread From: Đoàn Trần Công Danh @ 2022-11-23 11:54 UTC (permalink / raw) To: Jeff King Cc: Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin On 2022-11-21 18:32:11-0500, Jeff King <peff@peff.net> wrote: > On Mon, Nov 21, 2022 at 07:19:48PM +0000, Johannes Schindelin via GitGitGadget wrote: > > > It is relatively common for users to maintain identical `~/.gitconfig` > > files across all of their setups, using the `includeIf` construct > > liberally to adjust the settings to the respective setup as needed. > > This seems like a reasonable thing to have in general, but I wonder if > you have an example of how people use this. Mostly I am wondering: > > - is it sometimes a misuse, where users _think_ that the OS is > correlated with some feature of Git. And they would be better off > with some flag like "does the current platform support fsmonitor". A possible use-case is setting credential.helper based on OS, let's say libsecret on Linux, and osxkeychain on macOS. Of course, users can have their own helper on specific OS. > > - for cases where it really is "uname -s" the best differentiator? Or > would they commonly want to lump FreeBSD and Linux into the same > category, or to tell the difference between Debian versus Fedora? > > -Peff -- Danh ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-23 11:54 ` Đoàn Trần Công Danh @ 2022-11-24 0:56 ` Jeff King 0 siblings, 0 replies; 26+ messages in thread From: Jeff King @ 2022-11-24 0:56 UTC (permalink / raw) To: Đoàn Trần Công Danh Cc: Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin On Wed, Nov 23, 2022 at 06:54:45PM +0700, Đoàn Trần Công Danh wrote: > > This seems like a reasonable thing to have in general, but I wonder if > > you have an example of how people use this. Mostly I am wondering: > > > > - is it sometimes a misuse, where users _think_ that the OS is > > correlated with some feature of Git. And they would be better off > > with some flag like "does the current platform support fsmonitor". > > A possible use-case is setting credential.helper based on OS, let's say > libsecret on Linux, and osxkeychain on macOS. Of course, users can > have their own helper on specific OS. Thanks, that's a very nice concrete example. I agree that's a pretty reasonable use of this feature, given the lack of other selection mechanisms. I do wonder if folks might run into annoyances when they want to use libsecret on Linux _and_ FreeBSD or similar. But this feature is definitely better than the status quo, and is not very much code to implement or support. -Peff ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 19:19 ` [PATCH v2] " Johannes Schindelin via GitGitGadget 2022-11-21 23:32 ` Jeff King @ 2022-11-22 14:01 ` Ævar Arnfjörð Bjarmason 2022-11-22 14:31 ` Phillip Wood 2022-11-22 18:40 ` Philippe Blain 2022-11-23 10:40 ` Philip Oakley 3 siblings, 1 reply; 26+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2022-11-22 14:01 UTC (permalink / raw) To: Johannes Schindelin via GitGitGadget Cc: git, Phillip Wood, Johannes Schindelin On Mon, Nov 21 2022, Johannes Schindelin via GitGitGadget wrote: > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > +`os`:: > + The data that follows this keyword is taken as the name of an > + Operating System, e.g. `Linux` or `Windows`; If it matches the > + current Operating System, the include condition is met. > + > A few more notes on matching via `gitdir` and `gitdir/i`: The reste of the "includeif" use glob matching and "/i" for icase. IOW this is how this new feature would fit in: |--------+--------+----------+----------+------------------+----| | | gitdir | gitdir/i | onbranch | hasconfig:remote | os | |--------+--------+----------+----------+------------------+----| | icase? | N | Y | N | N | Y | | glob? | Y | Y | Y | Y | N | | path? | Y | Y | Y | Y | N | |--------+--------+----------+----------+------------------+----| I think at least flipping that "glob" to "Y" so you could match e.g. "*BSD" would be useful, and easier to explain in context, rather than why the rest use wildmatch() and this doesn't. For matching the uname the case doesn't really matter, but for consistency of the interface I think making it case-sensitive or adding an "os/i" would make sense. I.e. let's consistently use "/i" if & when something's case-insensitive. > +test_expect_success '[includeIf "os:..."]' ' > + test_config x.y 0 && > + echo "[x] y = z" >.git/xyz && > + > + if test_have_prereq MINGW > + then > + uname_s=Windows > + else > + uname_s="$(uname -s)" > + fi && > + test_config "includeIf.os:not-$uname_s.path" xyz && > + test 0 = "$(git config x.y)" && > + test_config "includeIf.os:$uname_s.path" xyz && > + test z = "$(git config x.y)" > +' As I pointed out in the v1, this still: * Hides segfaults in "git config", let's check the exit code. * Doesn't test the "icase" semantics you're introducing. Let's do that if it's intentional. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-22 14:01 ` Ævar Arnfjörð Bjarmason @ 2022-11-22 14:31 ` Phillip Wood 2022-11-23 0:16 ` Junio C Hamano 0 siblings, 1 reply; 26+ messages in thread From: Phillip Wood @ 2022-11-22 14:31 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason, Johannes Schindelin via GitGitGadget Cc: git, Phillip Wood, Johannes Schindelin On 22/11/2022 14:01, Ævar Arnfjörð Bjarmason wrote: > > On Mon, Nov 21 2022, Johannes Schindelin via GitGitGadget wrote: > >> From: Johannes Schindelin <johannes.schindelin@gmx.de> >> >> +`os`:: >> + The data that follows this keyword is taken as the name of an >> + Operating System, e.g. `Linux` or `Windows`; If it matches the >> + current Operating System, the include condition is met. >> + >> A few more notes on matching via `gitdir` and `gitdir/i`: > > The reste of the "includeif" use glob matching and "/i" for icase. IOW > this is how this new feature would fit in: > > |--------+--------+----------+----------+------------------+----| > | | gitdir | gitdir/i | onbranch | hasconfig:remote | os | > |--------+--------+----------+----------+------------------+----| > | icase? | N | Y | N | N | Y | > | glob? | Y | Y | Y | Y | N | > | path? | Y | Y | Y | Y | N | > |--------+--------+----------+----------+------------------+----| > > I think at least flipping that "glob" to "Y" so you could match e.g. > "*BSD" would be useful, and easier to explain in context, rather than > why the rest use wildmatch() and this doesn't. Globbing could be useful for the BSDs. One other thing I thought of is will users know "Darwin" means MacOS? > For matching the uname the case doesn't really matter, but for > consistency of the interface I think making it case-sensitive or adding > an "os/i" would make sense. I.e. let's consistently use "/i" if & when > something's case-insensitive. All the other items listed in your table such as branch names are case sensitive. The os name is not so it is of no benefit at all to the user to match it case sensitively. Let's consistently test case sensitive keys cases sensitively and case insensitive keys case insensitively. Best Wishes Phillip >> +test_expect_success '[includeIf "os:..."]' ' >> + test_config x.y 0 && >> + echo "[x] y = z" >.git/xyz && >> + >> + if test_have_prereq MINGW >> + then >> + uname_s=Windows >> + else >> + uname_s="$(uname -s)" >> + fi && >> + test_config "includeIf.os:not-$uname_s.path" xyz && >> + test 0 = "$(git config x.y)" && >> + test_config "includeIf.os:$uname_s.path" xyz && >> + test z = "$(git config x.y)" >> +' > > As I pointed out in the v1, this still: > > * Hides segfaults in "git config", let's check the exit code. > * Doesn't test the "icase" semantics you're introducing. Let's do that > if it's intentional. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-22 14:31 ` Phillip Wood @ 2022-11-23 0:16 ` Junio C Hamano 2022-11-23 15:07 ` Phillip Wood 0 siblings, 1 reply; 26+ messages in thread From: Junio C Hamano @ 2022-11-23 0:16 UTC (permalink / raw) To: Phillip Wood Cc: Ævar Arnfjörð Bjarmason, Johannes Schindelin via GitGitGadget, git, Johannes Schindelin Phillip Wood <phillip.wood123@gmail.com> writes: > All the other items listed in your table such as branch names are case > sensitive. The os name is not so it is of no benefit at all to the You keep saying that you consider the OS name is case insensitive, but I doubt that is the case, not in the sense that MacOS and macOS are two different operating systems, but in the sense that OS publishers have a single preferred way to spell their ware (which is shown in "uname -s" output), and we should respect that. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-23 0:16 ` Junio C Hamano @ 2022-11-23 15:07 ` Phillip Wood 2022-11-23 23:51 ` Junio C Hamano 0 siblings, 1 reply; 26+ messages in thread From: Phillip Wood @ 2022-11-23 15:07 UTC (permalink / raw) To: Junio C Hamano, Phillip Wood Cc: Ævar Arnfjörð Bjarmason, Johannes Schindelin via GitGitGadget, git, Johannes Schindelin Hi Junio Welcome back, I hope you enjoyed your time away from the list. On 23/11/2022 00:16, Junio C Hamano wrote: > Phillip Wood <phillip.wood123@gmail.com> writes: > >> All the other items listed in your table such as branch names are case >> sensitive. The os name is not so it is of no benefit at all to the > > You keep saying that you consider the OS name is case insensitive, > but I doubt that is the case, not in the sense that MacOS and macOS > are two different operating systems, but in the sense that OS > publishers have a single preferred way to spell their ware (which is > shown in "uname -s" output), and we should respect that. I can see that we would want to respect the preferred spelling in our documentation but it seems a bit mean to penalize users who write [IncludeIf "os:windows"] rather than [IncludeIf "os:Windows"] Best Wishes Phillip ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-23 15:07 ` Phillip Wood @ 2022-11-23 23:51 ` Junio C Hamano 0 siblings, 0 replies; 26+ messages in thread From: Junio C Hamano @ 2022-11-23 23:51 UTC (permalink / raw) To: Phillip Wood Cc: Ævar Arnfjörð Bjarmason, Johannes Schindelin via GitGitGadget, git, Johannes Schindelin Phillip Wood <phillip.wood123@gmail.com> writes: > I can see that we would want to respect the preferred spelling in our > documentation but it seems a bit mean to penalize users who write > > [IncludeIf "os:windows"] > > rather than > > [IncludeIf "os:Windows"] I do not think "uname-s/i:windows" is out of question. I am saying that the default should be case sensitive for consistency with others. Also, as I said already, I do not think we should squat on a good name "os" with this "uname -s" feature that may not be a good differenciator for two OSes for some cases (e.g. telling Debian and Fedora apart was a good example raised upthread already). ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 19:19 ` [PATCH v2] " Johannes Schindelin via GitGitGadget 2022-11-21 23:32 ` Jeff King 2022-11-22 14:01 ` Ævar Arnfjörð Bjarmason @ 2022-11-22 18:40 ` Philippe Blain 2022-11-23 10:40 ` Philip Oakley 3 siblings, 0 replies; 26+ messages in thread From: Philippe Blain @ 2022-11-22 18:40 UTC (permalink / raw) To: Johannes Schindelin via GitGitGadget, git Cc: Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin Hi Dscho, Le 2022-11-21 à 14:19, Johannes Schindelin via GitGitGadget a écrit : > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > It is relatively common for users to maintain identical `~/.gitconfig` > files across all of their setups, using the `includeIf` construct > liberally to adjust the settings to the respective setup as needed. > > In case of Operating System-specific adjustments, Here, as well as in the commit title, the rest of the message, and the changes to the doc in the patch, I would downcase "operating system". It's a common word that I don't think should be capitalized (in contrast to proper OS names like Windows and Linux). Cheers, Philippe. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 19:19 ` [PATCH v2] " Johannes Schindelin via GitGitGadget ` (2 preceding siblings ...) 2022-11-22 18:40 ` Philippe Blain @ 2022-11-23 10:40 ` Philip Oakley 2022-11-25 7:31 ` Junio C Hamano 3 siblings, 1 reply; 26+ messages in thread From: Philip Oakley @ 2022-11-23 10:40 UTC (permalink / raw) To: Johannes Schindelin via GitGitGadget, git Cc: Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin Hi Dscho, On 21/11/2022 19:19, Johannes Schindelin via GitGitGadget wrote: > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > It is relatively common for users to maintain identical `~/.gitconfig` > files across all of their setups, using the `includeIf` construct > liberally to adjust the settings to the respective setup as needed. > > In case of Operating System-specific adjustments, Git currently offers > no support to the users and they typically use a work-around like this: > > [includeIf "gitdir:/home/"] > path = ~/.gitconfig-linux > [includeIf "gitdir:/Users/"] > path = ~/.gitconfig-mac > [includeIf "gitdir:C:"] > path = ~/.gitconfig-windows > > However, this is fragile, as it would not even allow to discern between > Operating Systems that happen to host their home directories in > `/home/`, such as Linux and the BSDs. > > Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the > system name, i.e. the output of `uname -s`. This `uname -s` doesn't work well on Git-for-Windows (GfW) / Windows because GfW has its own internal compatibility code to spoof the result. Internally GfW sets it to "Windows" (see https://github.com/git/git/blob/master/compat/mingw.c#L3084-L3095). If I ask for `uname -s` on the GfW bash, for me it returns `MINGW64_NT-10.0-19045`, both on the normal GfW install, and the GfW-SDK. If I (as dumb user) try the CMD window prompt it's 'uname' is not recognized as an internal or external command, operable program or batch file. The Windows PowerShell also doesn't recognise the uname command. My WSL reports `Linux`, though I haven't played with that for a while (do all *nix variants report that?). Thus we'll need some way of assisting the users in determining the internal system name that their local Git will find. It maybe that the man page just needs to be explicit about using "Windows" for the Git-for-Windows implementation. Or less helpful, maybe a `git-uname` command to disambiguate any other systems with a compat::uname() variant. Or just drop the mentions of "<uname-s>" in this commit message and rename it 'sysname' to match the field of the struct utsname? > > This addresses https://github.com/git-for-windows/git/issues/4125 > > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> > --- > config: introduce an Operating System-specific includeIf condition > > I was about to write up guidelines how to write this patch, but it > turned out that it was much faster to write the patch instead. > > Changes since v1: > > * The documentation now avoids mentioning uname -s and clarifies what > it means by offering examples. > * Replaced a double space in the test case with a single one. > > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1429%2Fdscho%2Finclude-if-os-v2 > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1429/dscho/include-if-os-v2 > Pull-Request: https://github.com/gitgitgadget/git/pull/1429 > > Range-diff vs v1: > > 1: a7eb4a9d438 ! 1: 45231533883 config: introduce an Operating System-specific `includeIf` condition > @@ Documentation/config.txt: As for the naming of this keyword, it is for forwards > > +`os`:: > + The data that follows this keyword is taken as the name of an > -+ Operating System; If it matches the output of `uname -s`, the > -+ include condition is met. > ++ Operating System, e.g. `Linux` or `Windows`; If it matches the > ++ current Operating System, the include condition is met. > + > A few more notes on matching via `gitdir` and `gitdir/i`: > > @@ t/t1309-early-config.sh: test_expect_success 'onbranch config outside of git rep > + uname_s="$(uname -s)" > + fi && > + test_config "includeIf.os:not-$uname_s.path" xyz && > -+ test 0 = "$(git config x.y)" && > ++ test 0 = "$(git config x.y)" && > + test_config "includeIf.os:$uname_s.path" xyz && > + test z = "$(git config x.y)" > +' > > > Documentation/config.txt | 5 +++++ > config.c | 11 +++++++++++ > t/t1309-early-config.sh | 16 ++++++++++++++++ > 3 files changed, 32 insertions(+) > > diff --git a/Documentation/config.txt b/Documentation/config.txt > index e376d547ce0..b90bcd8ecfe 100644 > --- a/Documentation/config.txt > +++ b/Documentation/config.txt > @@ -186,6 +186,11 @@ As for the naming of this keyword, it is for forwards compatibiliy with > a naming scheme that supports more variable-based include conditions, > but currently Git only supports the exact keyword described above. > > +`os`:: > + The data that follows this keyword is taken as the name of an > + Operating System, e.g. `Linux` or `Windows`; If it matches the > + current Operating System Is 'matches' the appropriate way to indicate that we compare just the characters from the data string and ignore any trailing chars in the uname.sysname field? > , the include condition is met. > + > A few more notes on matching via `gitdir` and `gitdir/i`: > > * Symlinks in `$GIT_DIR` are not resolved before matching. > diff --git a/config.c b/config.c > index 9b0e9c93285..9ab311ae99b 100644 > --- a/config.c > +++ b/config.c > @@ -394,6 +394,15 @@ static int include_by_remote_url(struct config_include_data *inc, > inc->remote_urls); > } > > +static int include_by_os(const char *cond, size_t cond_len) > +{ > + struct utsname uname_info; > + > + return !uname(&uname_info) && > + !strncasecmp(uname_info.sysname, cond, cond_len) && > + !uname_info.sysname[cond_len]; > +} > + > static int include_condition_is_true(struct config_include_data *inc, > const char *cond, size_t cond_len) > { > @@ -408,6 +417,8 @@ static int include_condition_is_true(struct config_include_data *inc, > else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond, > &cond_len)) > return include_by_remote_url(inc, cond, cond_len); > + else if (skip_prefix_mem(cond, cond_len, "os:", &cond, &cond_len)) > + return include_by_os(cond, cond_len); (as above) We compare only on the basis of the few/many characters in the config file so, IIUC, we could use `Win`, or `Lin` as the os: string. Should this be noted in the man text? I'm thinking of users who may be confused by having to change Win10 to Windows, but are happy to shorten to `Win`. > > /* unknown conditionals are always false */ > return 0; > diff --git a/t/t1309-early-config.sh b/t/t1309-early-config.sh > index 537435b90ae..b36afe1a528 100755 > --- a/t/t1309-early-config.sh > +++ b/t/t1309-early-config.sh > @@ -100,4 +100,20 @@ test_expect_success 'onbranch config outside of git repo' ' > nongit git help > ' > > +test_expect_success '[includeIf "os:..."]' ' > + test_config x.y 0 && > + echo "[x] y = z" >.git/xyz && > + > + if test_have_prereq MINGW > + then > + uname_s=Windows This (correctly) copies/follows the compat code (https://github.com/git/git/blob/master/compat/mingw.c#L3088), but isn't what a GfW user sees if `uname-s` is run in their bash. Maybe change uname_s to sysname, as noted above. > + else > + uname_s="$(uname -s)" > + fi && > + test_config "includeIf.os:not-$uname_s.path" xyz && > + test 0 = "$(git config x.y)" && > + test_config "includeIf.os:$uname_s.path" xyz && > + test z = "$(git config x.y)" > +' > + > test_done > > base-commit: e4a4b31577c7419497ac30cebe30d755b97752c5 -- Philip ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-23 10:40 ` Philip Oakley @ 2022-11-25 7:31 ` Junio C Hamano 2023-04-17 7:04 ` Samuel Ferencik 0 siblings, 1 reply; 26+ messages in thread From: Junio C Hamano @ 2022-11-25 7:31 UTC (permalink / raw) To: Philip Oakley Cc: Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin Philip Oakley <philipoakley@iee.email> writes: >> Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the >> system name, i.e. the output of `uname -s`. > > This `uname -s` doesn't work well on Git-for-Windows (GfW) / Windows > because GfW has its own internal compatibility code to spoof the result. > ... > Or just drop the mentions of "<uname-s>" in this commit message and > rename it 'sysname' to match the field of the struct utsname? FWIW I do not mind "sysname". It is much better to say [includeIf "sysname:Linux"] path = ... than "os:Linux", as "sysname" informs us the granularity used to identify the system better than "os". ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2022-11-25 7:31 ` Junio C Hamano @ 2023-04-17 7:04 ` Samuel Ferencik 2023-04-17 18:46 ` Junio C Hamano 0 siblings, 1 reply; 26+ messages in thread From: Samuel Ferencik @ 2023-04-17 7:04 UTC (permalink / raw) To: Junio C Hamano Cc: Philip Oakley, Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin >>> Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the >>> system name, i.e. the output of `uname -s`. The discussion about https://github.com/gitgitgadget/git/pull/1429 seems to have stalled on several points. I'll try to summarise; let's see if we can move forward. (I am the reporter of https://github.com/git-for-windows/git/issues/4125, which led to this PR. I am vested in making progress here.) 1. name of the setting (`os` vs `uname-s` vs `sysname`) * dscho@ suggested `os`; Phillip and Philip suggested `uname-s` and `sysname`, respectively * I vote for `os`; I'm afraid perfect is the enemy of good here as * `man uname` says `-s` gives "the name of the operating system implementation"; no other `uname` switch comes closer to whatever concept "OS" represents * this is also correct on Windows (the "Windows" string) - see below * I find it extremely unlikely a future unforeseen git feature would have a better use for `includeIf os` (in parallel with `includeIf sysname`), i.e. I don't worry that we're squatting on a good name for a poor use-case 2. casing (use of `/i`) * dscho@ implemented case-insensitive comparison but without test coverage, documentation, and it's inconsistent with the other `includeIf` options that support the `/i` switch. * I propose that we compare case-sensitively because * no user can reasonably complain about this if the documentation is clear; the OS names are definitive and stable and it's not a big deal getting the case right for "Linux" * without the case insensitivity being documented, the users who [discover the insensitivity and] rely on it are risking breakage; plus the git maintainers are exposing themselves to the effects of Hyrum's law (https://xkcd.com/1172) - it's a disservice for both sides * this still allows us to add support for `/i` later (should a use-case emerge) * it is consistent with the other settings * it requires less code (incl. tests) and shorter documentation 3. handling Windows (MinGW, WSL) * As implemented currently, `includeIf "os:Windows"` would work in git-for-Windows. I think that's desirable, and no-one suggested otherwise. * In contrast, Philip points out `includeIf "os:Linux"` would be the way to match on WSL. Is that an issue? Do we want WSL to match "os:Windows" or "os:WSL"? As a Windows user, when I switch to WSL I do expect a "proper" Linux experience (unlike when I run "Git bash" on Windows, which is more like a port of utilities, but still Windows). I think this treating WLS as Linux is OK-ish, and we may get away with not discerning WSL. Thoughts? 4. documentation (w.r.t. the details in 1. - 3.) * We should document all of 1. - 3. I'm happy to give it a go if we can reach consensus. * Specifically, the documentation should mention that the OS string equals "Windows" in Git-for-Windows, and `$(uname -s)` otherwise; it should list examples, incl. "Linux" and "Darwin"; it should mention the case sensitivity. 5. tests (potential segfaults) * Johannes points out the tests hide segfaults. I haven't looked at this closely but hopefully Johannes's suggestion ("use test_cmp or test_cmp_config") is a clear enough pointer. I can try to fix this. 6. what's the use-case? * As the reporter of https://github.com/git-for-windows/git/issues/4125, here are my use-cases, i.e. settings that I currently set conditionally per OS (using `includeIf gitdir`): * different `difftool.path`, `mergetool.path` per OS (e.g. paths containing `C:\Program Files\...\...exe` vs Unix file paths) * different `merge.tool` per OS (I have a BeyondCompare license for Linux only) * different `core.autocrlf`: `true` on Windows, `input` otherwise * `core.whitespace` set to `cr-at-eol` on Windows * `core.editor` set to `gvim` on Windows * Note all of the use-cases above would cope with WSL reporting "Linux", except of `merge.tool`. I hope this revives the discussion; I know it's been a while but I would appreciate your input. If possible, please refer to the numbered points (1 - 6) for clarity. I'm happy to iterate on dscho@'s PR if we can reach consensus. On Fri, 14 Apr 2023 at 01:44, Junio C Hamano <gitster@pobox.com> wrote: > > Philip Oakley <philipoakley@iee.email> writes: > > >> Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the > >> system name, i.e. the output of `uname -s`. > > > > This `uname -s` doesn't work well on Git-for-Windows (GfW) / Windows > > because GfW has its own internal compatibility code to spoof the result. > > ... > > Or just drop the mentions of "<uname-s>" in this commit message and > > rename it 'sysname' to match the field of the struct utsname? > > FWIW I do not mind "sysname". It is much better to say > > [includeIf "sysname:Linux"] path = ... > > than "os:Linux", as "sysname" informs us the granularity used to > identify the system better than "os". > > > ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2023-04-17 7:04 ` Samuel Ferencik @ 2023-04-17 18:46 ` Junio C Hamano 2023-04-18 2:04 ` Felipe Contreras 2023-04-19 12:22 ` Johannes Schindelin 0 siblings, 2 replies; 26+ messages in thread From: Junio C Hamano @ 2023-04-17 18:46 UTC (permalink / raw) To: Samuel Ferencik Cc: Philip Oakley, Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin Samuel Ferencik <sferencik@gmail.com> writes: >>>> Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the >>>> system name, i.e. the output of `uname -s`. > > The discussion about https://github.com/gitgitgadget/git/pull/1429 seems to > have stalled on several points. I'll try to summarise; let's see if we can move > forward. > > (I am the reporter of https://github.com/git-for-windows/git/issues/4125, which > led to this PR. I am vested in making progress here.) > > 1. name of the setting (`os` vs `uname-s` vs `sysname`) I do not think it is a good idea to squat on too generic a name like 'os', especially when there are multiple layers people will care about. But I think the original thread discussed this to death, and I do not see a point bringing it up again as the first bullet point. > 2. casing (use of `/i`) My preference is to do this case sensitively (in other words, start stupid) and if somebody wants to use "/i", add it later after the dust settles. > 3. handling Windows (MinGW, WSL) This comes back to the reason why "os" is a horrible choice. Is WSL a Windows? Is WSL a Linux? The same question can be asked for Cygwin. The answer depends on which layer you care about. The underlying kernel and system may be Windows, and some characteristics of the underlying system may seep through the abstraction, but these systems aim to give user experience of something like GNU/Linux. And this is not limited to Windows. There may be similar issue for systems like PacBSD. Is it a Linux? Is it a BSD? > 6. what's the use-case? I think that this is the most important question to ask, and from here, we'd see how #3 above should be resolved (I suspect that you may want to have at least two layers to allow WSL to be grouped together with MinGW and Cygwin at one level, and at the same time allow it to be grouped together with Ubuntu at a different level). And after we figure that out, we'll have a clear and intuitive answer to #1. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2023-04-17 18:46 ` Junio C Hamano @ 2023-04-18 2:04 ` Felipe Contreras 2023-04-19 12:22 ` Johannes Schindelin 1 sibling, 0 replies; 26+ messages in thread From: Felipe Contreras @ 2023-04-18 2:04 UTC (permalink / raw) To: Junio C Hamano, Samuel Ferencik Cc: Philip Oakley, Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood, Johannes Schindelin Junio C Hamano wrote: > Samuel Ferencik <sferencik@gmail.com> writes: > > >>>> Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the > >>>> system name, i.e. the output of `uname -s`. > > > > The discussion about https://github.com/gitgitgadget/git/pull/1429 seems to > > have stalled on several points. I'll try to summarise; let's see if we can move > > forward. > > > > (I am the reporter of https://github.com/git-for-windows/git/issues/4125, which > > led to this PR. I am vested in making progress here.) > > > > 1. name of the setting (`os` vs `uname-s` vs `sysname`) > > I do not think it is a good idea to squat on too generic a name like > 'os', especially when there are multiple layers people will care > about. But I think the original thread discussed this to death, and > I do not see a point bringing it up again as the first bullet point. "platform" is the term I've seen to be less OS-centric. -- Felipe Contreras ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2023-04-17 18:46 ` Junio C Hamano 2023-04-18 2:04 ` Felipe Contreras @ 2023-04-19 12:22 ` Johannes Schindelin 2023-04-19 14:26 ` Chris Torek ` (3 more replies) 1 sibling, 4 replies; 26+ messages in thread From: Johannes Schindelin @ 2023-04-19 12:22 UTC (permalink / raw) To: Junio C Hamano Cc: Samuel Ferencik, Philip Oakley, Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood Hi Junio, On Mon, 17 Apr 2023, Junio C Hamano wrote: > Samuel Ferencik <sferencik@gmail.com> writes: > > >>>> Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the > >>>> system name, i.e. the output of `uname -s`. > > > > The discussion about https://github.com/gitgitgadget/git/pull/1429 seems to > > have stalled on several points. I'll try to summarise; let's see if we can move > > forward. > > > > (I am the reporter of https://github.com/git-for-windows/git/issues/4125, which > > led to this PR. I am vested in making progress here.) > > > > 1. name of the setting (`os` vs `uname-s` vs `sysname`) > > I do not think it is a good idea to squat on too generic a name like > 'os', especially when there are multiple layers people will care > about. But I think the original thread discussed this to death, and > I do not see a point bringing it up again as the first bullet point. Given what you said about "Operating System", i.e. that both "Ubuntu" and "Linux" should be able to match at the same time, I kind of concur, but in the other direction: rather than forcing the current patch series to use a less intuitive (i.e. user-unfriendlier) name than `os`, I would want to modify the patch series so that it _can_ match "Ubuntu" and "Linux". > > 2. casing (use of `/i`) > > My preference is to do this case sensitively (in other words, start > stupid) and if somebody wants to use "/i", add it later after the > dust settles. I strongly disagree with this. This feature is meant for Git users, who I must assume based on my experience would expect the value to be case-insensitive. I.e. they would expect both `linux` and `Linux` to match. Let's not make this feature harder to use than necessary! > > 3. handling Windows (MinGW, WSL) > > This comes back to the reason why "os" is a horrible choice. Is WSL > a Windows? Is WSL a Linux? The same question can be asked for Cygwin. These questions actually have pretty obvious answers, with the exception of WSL1 (which nobody should use anymore): WSL is a Linux, Cygwin is not an Operating System by itself but runs on Windows. But of course that's not helpful to help configure Git specifically in a Cygwin setup. > The answer depends on which layer you care about. Yes, this is the crucial bit. > The underlying kernel and system may be Windows, and some > characteristics of the underlying system may seep through the > abstraction, but these systems aim to give user experience of something > like GNU/Linux. > > And this is not limited to Windows. There may be similar issue for > systems like PacBSD. Is it a Linux? Is it a BSD? > > > 6. what's the use-case? > > I think that this is the most important question to ask, and from > here, we'd see how #3 above should be resolved (I suspect that you > may want to have at least two layers to allow WSL to be grouped > together with MinGW and Cygwin at one level, and at the same time > allow it to be grouped together with Ubuntu at a different level). > And after we figure that out, we'll have a clear and intuitive > answer to #1. This is probably the most valuable feedback in this entire thread: What is the problem we're trying to solve here? The original report (which this patch tries to address) asks for a way to have a user-wide ("global") Git configuration that can be shared across machines and that allows for adapting to the various environments. The rationale is motivated well e.g. in https://medium.com/doing-things-right/platform-specific-gitconfigs-and-the-wonderful-includeif-7376cd44994d where platform-specific credential managers, editors, diff highlighters that work only in certain setups, and work vs personal environments are mentioned. So as long as Git offers ways to discern between the mentioned environments by including environment-specific configuration files, we solve the problem. Bonus points if we can do that without getting ever deeper into a pretty contentious discussion about naming. The strategy chosen in above-mentioned article uses the presence of certain directories as tell-tales for the Operating System in which Git is called: Linux, macOS or Windows. Concretely, it suggests this: [includeIf "gitdir:/Users"] path = ~/.gitconfig-macos [includeIf "gitdir:C:"] path = ~/.gitconfig-windows [includeIf "gitdir:/home"] path = ~/.gitconfig-linux Now, the presence of directories like `/home/` might work well to discern Linux from macOS, but this is not the correct way to identify Linux in general (a `/home/` directory exists in many Unices, too). And it only works when the _gitdir_ is in those directories, too. That's why I thought that Git could do better. In many cases, though, the presence of directories is probably "good enough" to address the need described in above-mentioned article. What triggered me to write this here patch was the report that those `/home/` and `/Users` paths in the Git config ran into the warning that Git for Windows no longer treats paths starting with a slash as relative to the runtime prefix. This warning was introduced when the `%(prefix)/` feature was upstreamed, superseding Git for Windows' original handling of paths starting with a slash. The warning was introduced in November '21 (virtually together with Git for Windows v2.34.0): https://github.com/git-for-windows/git/commit/28fdfd8a41836f49666c65e82d92de9befea2e69 So while I still think that something like `includeIf.os:<name>` would make for a better way to address the concern in question, I realize that the path of least resistance is simply to drop the now-deprecated feature from Git for Windows (including the warning that was the reason for the original report): https://github.com/git-for-windows/git/pull/4389 This still leaves Git in the somewhat unsatisfying state where there is no better way to discern between Operating Systems than to work around by detecting the presence of certain directories. But I do not see any viable way to reach consensus about the `includeIf.os:<name>` patch, so I'll leave it at that. Ciao, Johannes ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2023-04-19 12:22 ` Johannes Schindelin @ 2023-04-19 14:26 ` Chris Torek 2023-04-19 14:32 ` Samuel Ferencik 2023-04-19 15:21 ` rsbecker ` (2 subsequent siblings) 3 siblings, 1 reply; 26+ messages in thread From: Chris Torek @ 2023-04-19 14:26 UTC (permalink / raw) To: Johannes Schindelin Cc: Junio C Hamano, Samuel Ferencik, Philip Oakley, Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood Note: I'm going to mix two things here (maybe not the best idea) and change the order. On Wed, Apr 19, 2023 at 5:28 AM Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote: > This is probably the most valuable feedback in this entire thread: What is > the problem we're trying to solve here? > > The original report (which this patch tries to address) asks for a way to > have a user-wide ("global") Git configuration that can be shared across > machines and that allows for adapting to the various environments. The > rationale is motivated well e.g. in > https://medium.com/doing-things-right/platform-specific-gitconfigs-and-the-wonderful-includeif-7376cd44994d > where platform-specific credential managers, editors, diff highlighters > that work only in certain setups, and work vs personal environments are > mentioned. Why not allow use of environment variables? Perhaps a simple: git config include.env.USER_VAR and/or: git config include.ifexists.env.DIR (feel free to invent better names!) or similar. The user can then export DIR=whatever in some outside-of-Git setup. On a separate note: > ... This feature is meant for Git users, who I > must assume based on my experience would expect the value to be > case-insensitive. I.e. they would expect both `linux` and `Linux` to > match. I'm not at all sure about this: we already see a lot of confusion from people who don't understand why, if Git is case-sensitive about branch names (which it is), Git isn't case-sensitive about branch names *sometimes* on Windows and macOS. (In any case, using an env var sidesteps this question.) Chris ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2023-04-19 14:26 ` Chris Torek @ 2023-04-19 14:32 ` Samuel Ferencik 0 siblings, 0 replies; 26+ messages in thread From: Samuel Ferencik @ 2023-04-19 14:32 UTC (permalink / raw) To: Chris Torek Cc: Johannes Schindelin, Junio C Hamano, Philip Oakley, Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood [resending my previous response, which I had sent only to the PR, not the mailing list; composed before dscho@'s last email] > > 2. casing (use of `/i`) > > My preference is to do this case sensitively (in other words, start > stupid) and if somebody wants to use "/i", add it later after the > dust settles. Fantastic. > > 6. what's the use-case? > > * Note all of the use-cases above would cope with WSL reporting "Linux", > > except of `merge.tool`. > > I think that this is the most important question to ask, and from > here, we'd see how #3 above should be resolved (I suspect that you > may want to have at least two layers to allow WSL to be grouped > together with MinGW and Cygwin at one level, and at the same time > allow it to be grouped together with Ubuntu at a different level). Actually, I take that back: I can install the Linux version of BeyondCompare into WSL, use my license, and I'm fine with WSL reporting that it's Linux. (This is just to correct my previous claim. More below.) > > 3. handling Windows (MinGW, WSL) > > The answer depends on which layer you care about. The underlying > kernel and system may be Windows, and some characteristics of the > underlying system may seep through the abstraction, but these > systems aim to give user experience of something like GNU/Linux. Fair point. I think we only care about the top-most layer (the one nearest to the user). The "seeping through" aspect means things often aren't clear-cut, but I also think we can make practical decisions. The closer the top layer approximates an OS, the more we can say it *is* that OS without compromising correctness. For example, a Linux container on Windows should report (uname) it's a Linux, and `includeIf` should go by this. So should WSL2, I think, because it provides a Linux kernel. Maybe there is a use-case for git config (`includeIf`) to behave differently in WSL because the host OS is Windows, but I'm not aware of such a use-case. In contrast, "Git bash" and Cygwin report something other than "Linux" (`MINGW64_NT-<version>`, `CYGWIN_NT-<version>`) because they are not Linuxes, and that's also fine. Interestingly, though, they don't report the host OS (Windows) either. So I propose that we limit ourselves to the top-most layer. Can we come up with a name (`os` or another) that would capture this concept? - Felipe proposed `platform`. I'm afraid this may be confused with the hardware platform (as reported by `uname -m`). - Phillip proposed `uname-s`. It's self-documenting in a way, but it's also wrong on Windows and describes the tool rather than the concept. - Philip proposed `sysname`. It's slightly better but still very much a pointer to `utsname.sysname`. - dscho@ proposed `os`. I like it for its obviousness. The issues with the name are marginal (not bigger than with any other name) and can be sufficiently addressed by good documentation. If we can agree on the name, I can help fix up the documentation, the tests, and remove the case insensitivity. Thoughts? ^ permalink raw reply [flat|nested] 26+ messages in thread
* RE: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2023-04-19 12:22 ` Johannes Schindelin 2023-04-19 14:26 ` Chris Torek @ 2023-04-19 15:21 ` rsbecker 2023-04-19 16:07 ` Junio C Hamano 2023-04-19 16:14 ` Junio C Hamano 3 siblings, 0 replies; 26+ messages in thread From: rsbecker @ 2023-04-19 15:21 UTC (permalink / raw) To: 'Johannes Schindelin', 'Junio C Hamano' Cc: 'Samuel Ferencik', 'Philip Oakley', 'Johannes Schindelin via GitGitGadget', git, 'Ævar Arnfjörð Bjarmason', 'Phillip Wood' On Wednesday, April 19, 2023 8:23 AM, Johannes Schindelin wrote: >On Mon, 17 Apr 2023, Junio C Hamano wrote: > >> Samuel Ferencik <sferencik@gmail.com> writes: >> >> >>>> Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` >> >>>> is the system name, i.e. the output of `uname -s`. >> > >> > The discussion about https://github.com/gitgitgadget/git/pull/1429 >> > seems to have stalled on several points. I'll try to summarise; >> > let's see if we can move forward. >> > >> > (I am the reporter of >> > https://github.com/git-for-windows/git/issues/4125, which led to >> > this PR. I am vested in making progress here.) >> > >> > 1. name of the setting (`os` vs `uname-s` vs `sysname`) >> >> I do not think it is a good idea to squat on too generic a name like >> 'os', especially when there are multiple layers people will care >> about. But I think the original thread discussed this to death, and I >> do not see a point bringing it up again as the first bullet point. > >Given what you said about "Operating System", i.e. that both "Ubuntu" and "Linux" >should be able to match at the same time, I kind of concur, but in the other direction: >rather than forcing the current patch series to use a less intuitive (i.e. user- >unfriendlier) name than `os`, I would want to modify the patch series so that it _can_ >match "Ubuntu" and "Linux". > >> > 2. casing (use of `/i`) >> >> My preference is to do this case sensitively (in other words, start >> stupid) and if somebody wants to use "/i", add it later after the dust >> settles. > >I strongly disagree with this. This feature is meant for Git users, who I must assume >based on my experience would expect the value to be case-insensitive. I.e. they >would expect both `linux` and `Linux` to match. Let's not make this feature harder to >use than necessary! > >> > 3. handling Windows (MinGW, WSL) >> >> This comes back to the reason why "os" is a horrible choice. Is WSL a >> Windows? Is WSL a Linux? The same question can be asked for Cygwin. > >These questions actually have pretty obvious answers, with the exception of WSL1 >(which nobody should use anymore): WSL is a Linux, Cygwin is not an Operating >System by itself but runs on Windows. But of course that's not helpful to help >configure Git specifically in a Cygwin setup. > >> The answer depends on which layer you care about. > >Yes, this is the crucial bit. > >> The underlying kernel and system may be Windows, and some >> characteristics of the underlying system may seep through the >> abstraction, but these systems aim to give user experience of >> something like GNU/Linux. >> >> And this is not limited to Windows. There may be similar issue for >> systems like PacBSD. Is it a Linux? Is it a BSD? >> >> > 6. what's the use-case? >> >> I think that this is the most important question to ask, and from >> here, we'd see how #3 above should be resolved (I suspect that you may >> want to have at least two layers to allow WSL to be grouped together >> with MinGW and Cygwin at one level, and at the same time allow it to >> be grouped together with Ubuntu at a different level). >> And after we figure that out, we'll have a clear and intuitive answer >> to #1. > >This is probably the most valuable feedback in this entire thread: What is the problem >we're trying to solve here? > >The original report (which this patch tries to address) asks for a way to have a user- >wide ("global") Git configuration that can be shared across machines and that allows >for adapting to the various environments. The rationale is motivated well e.g. in >https://medium.com/doing-things-right/platform-specific-gitconfigs-and-the- >wonderful-includeif-7376cd44994d >where platform-specific credential managers, editors, diff highlighters that work only >in certain setups, and work vs personal environments are mentioned. > >So as long as Git offers ways to discern between the mentioned environments by >including environment-specific configuration files, we solve the problem. I would suggest using match of uname arguments. But there are variants. The OS release should also be included here as something like NONSTOP_KERNEL is not a sufficient answer. We should have at the very least, or encode the includeif string accordingly: uname -r = the release n (e.g., J06) uname -n = the node name (e.g., hpitug) uname -s = the OS (e.g., NONSTOP_KERNEL We use these in config.mak.uname (except for -n). Regards, Randall ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2023-04-19 12:22 ` Johannes Schindelin 2023-04-19 14:26 ` Chris Torek 2023-04-19 15:21 ` rsbecker @ 2023-04-19 16:07 ` Junio C Hamano 2023-04-19 16:14 ` Junio C Hamano 3 siblings, 0 replies; 26+ messages in thread From: Junio C Hamano @ 2023-04-19 16:07 UTC (permalink / raw) To: Johannes Schindelin Cc: Samuel Ferencik, Philip Oakley, Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: >> > 2. casing (use of `/i`) >> >> My preference is to do this case sensitively (in other words, start >> stupid) and if somebody wants to use "/i", add it later after the >> dust settles. > > I strongly disagree with this. This feature is meant for Git users, who I > must assume based on my experience would expect the value to be > case-insensitive. I.e. they would expect both `linux` and `Linux` to > match. Let's not make this feature harder to use than necessary! [jc: Read below with 'os' replaced with 'uname-s' or any of your favorite. This message does not take any position on that part of the discussion.] I am OK with the above position, if we make sure that all other includeIf conditions are compared case insensitively, and if we make sure there is no existing "/i" includeIf conditions. Then those who want to differentiate can later add "/casesensitive" option. But I do not want to see a system where some of the conditions are compared case insensitively while some other conditions are compared case sensitively. The end-users will then be forced to remember "the condition 'os' can be spelled in any case permutation, but the condition 'xyzzy' needs to be spelled in the right case". It would not be obvious to end users when they need to use "/i" variant in such a system. Unlike 'gitdir' whose value is arbitrarily chosen by the users and the projects (where folks use both FooBar and foobar and want them to mean different things), the vocabulary of "os" is limited and I agree with you that it is very likely for any user to expect that any case permutations of "linux" would mean the same thing. But spelling "windows" and have it match even when the official name of the system may be "Windows" should be the choice made by the end user, and the "/i" suffix in "os/i" is a way for them to express it. You might be able to talk me into adding only "os/i" added without adding "os", though. I do not see much point in doing so, other than that we can say "we do not take any position on what case permutation is the right and official way to spell the name of each system". Thanks. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2] config: introduce an Operating System-specific `includeIf` condition 2023-04-19 12:22 ` Johannes Schindelin ` (2 preceding siblings ...) 2023-04-19 16:07 ` Junio C Hamano @ 2023-04-19 16:14 ` Junio C Hamano 3 siblings, 0 replies; 26+ messages in thread From: Junio C Hamano @ 2023-04-19 16:14 UTC (permalink / raw) To: Johannes Schindelin Cc: Samuel Ferencik, Philip Oakley, Johannes Schindelin via GitGitGadget, git, Ævar Arnfjörð Bjarmason, Phillip Wood Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: > The original report (which this patch tries to address) asks for a way to > have a user-wide ("global") Git configuration that can be shared across > machines and that allows for adapting to the various environments. > ... > So as long as Git offers ways to discern between the mentioned > environments by including environment-specific configuration files, we > solve the problem. Perhaps [includeIf "ifExists:/path/to/foo-credential-manager.exe"] path = /path/to/config/needed/for/using/foo-credential-manager is being called for? "os" being "LiNuX" does not tell much about the environment differences the end users would care about, like what desktop environment is in use, which leads to the availability and default choice of GUI tools, to help them auto-configure. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] config: introduce an Operating System-specific `includeIf` condition 2022-11-21 13:39 [PATCH] config: introduce an Operating System-specific `includeIf` condition Johannes Schindelin via GitGitGadget 2022-11-21 13:51 ` Ævar Arnfjörð Bjarmason 2022-11-21 19:19 ` [PATCH v2] " Johannes Schindelin via GitGitGadget @ 2022-11-22 0:03 ` Junio C Hamano 2 siblings, 0 replies; 26+ messages in thread From: Junio C Hamano @ 2022-11-22 0:03 UTC (permalink / raw) To: Johannes Schindelin via GitGitGadget; +Cc: git, Johannes Schindelin "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > It is relatively common for users to maintain identical `~/.gitconfig` > files across all of their setups, using the `includeIf` construct > liberally to adjust the settings to the respective setup as needed. > > In case of Operating System-specific adjustments, Git currently offers > no support to the users and they typically use a work-around like this: > > [includeIf "gitdir:/home/"] > path = ~/.gitconfig-linux > [includeIf "gitdir:/Users/"] > path = ~/.gitconfig-mac > [includeIf "gitdir:C:"] > path = ~/.gitconfig-windows > > However, this is fragile, as it would not even allow to discern between > Operating Systems that happen to host their home directories in > `/home/`, such as Linux and the BSDs. > > Let's introduce a new condition: `os:<uname-s>` where `<uname-s>` is the > system name, i.e. the output of `uname -s`. As I am not confident enough that we made the best choice that would last forever with the initial attempt when we picked "uname -s" as the way to switch on "OS", I wouldn't call it "OS". Perhaps [includeIf "uname-s:Linux"] path = ... would be what I would pick. Other than that, the feature makes quite a lot of sense. ^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2023-04-19 16:14 UTC | newest] Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-11-21 13:39 [PATCH] config: introduce an Operating System-specific `includeIf` condition Johannes Schindelin via GitGitGadget 2022-11-21 13:51 ` Ævar Arnfjörð Bjarmason 2022-11-21 15:51 ` Phillip Wood 2022-11-21 19:18 ` Johannes Schindelin 2022-11-21 19:19 ` [PATCH v2] " Johannes Schindelin via GitGitGadget 2022-11-21 23:32 ` Jeff King 2022-11-23 11:54 ` Đoàn Trần Công Danh 2022-11-24 0:56 ` Jeff King 2022-11-22 14:01 ` Ævar Arnfjörð Bjarmason 2022-11-22 14:31 ` Phillip Wood 2022-11-23 0:16 ` Junio C Hamano 2022-11-23 15:07 ` Phillip Wood 2022-11-23 23:51 ` Junio C Hamano 2022-11-22 18:40 ` Philippe Blain 2022-11-23 10:40 ` Philip Oakley 2022-11-25 7:31 ` Junio C Hamano 2023-04-17 7:04 ` Samuel Ferencik 2023-04-17 18:46 ` Junio C Hamano 2023-04-18 2:04 ` Felipe Contreras 2023-04-19 12:22 ` Johannes Schindelin 2023-04-19 14:26 ` Chris Torek 2023-04-19 14:32 ` Samuel Ferencik 2023-04-19 15:21 ` rsbecker 2023-04-19 16:07 ` Junio C Hamano 2023-04-19 16:14 ` Junio C Hamano 2022-11-22 0:03 ` [PATCH] " Junio C Hamano
Code repositories for project(s) associated with this public inbox https://80x24.org/mirrors/git.git 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 read-only IMAP folder(s) and NNTP newsgroup(s).