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

[PATCH v3 0/2] Add hostname condition to includeIf

From
IEIgnacio Encinas <ignacio@iencinas.com>
Date
Mar 19, 2024, 18:37 UTC
Message-ID
<20240319183722.211300-1-ignacio@iencinas.com>
In-Reply-To
<20240309181828.45496-1-ignacio@iencinas.com>

Extend includeIf to take hostname into account. Motivating request can be found here [1].

[1] https://github.com/gitgitgadget/git/issues/1665
A lot of feedback was given to the v2 of this patch.
It was pointed out that it wasn't particularly obvious what it was meant by 
  "If the current hostname matches the pattern, the include condition is met."

which is definitely true. Despite this, to my knowledge, there isn't a way to precisely define what we mean by "hostname" other than saying that we mean whatever is returned by gethostname(2).

In my opinion, terms like "short hostname" can be confusing in some cases, and I'm not even sure we can rely on $hostname to agree with gethostname(2) in every platform.

I still think the documentation isn't great, but I don't see a way to improve it further.

Thanks everyone for the feedback!
Changes since v2:
* Expose the result of xgethostname through test-tool
* Rewrite test to rely on test-tool xgethostname rather than using
  $hostname
* Clarify documentation, specifying that by "hostname" we mean output of
  gethostname(2)
Changes since v1:
* Add blank line between declarations and code in `include_by_branch`.
* Rewrite "echo"s used in tests to make them more readable. 
Ignacio Encinas (2):
  t: add a test helper for getting hostname
  config: learn the "hostname:" includeIf condition
 Documentation/config.txt     | 10 +++++++++
 Makefile                     |  1 +
 config.c                     | 17 +++++++++++++++
 t/helper/test-tool.c         |  1 +
 t/helper/test-tool.h         |  1 +
 t/helper/test-xgethostname.c | 12 +++++++++++
 t/t1305-config-include.sh    | 42 ++++++++++++++++++++++++++++++++++++
 t/t6500-gc.sh                |  3 +--
 8 files changed, 85 insertions(+), 2 deletions(-)
 create mode 100644 t/helper/test-xgethostname.c
Range-diff against v2:
-:  ------------ > 1:  ee1f9b1da037 t: add a test helper for getting hostname
1:  cf175154109e ! 2:  dec622c38916 config: learn the "hostname:" includeIf condition
    @@ Documentation/config.txt: As for the naming of this keyword, it is for forwards
     +`hostname`::
     +	The data that follows the keyword `hostname:` is taken to be a
     +	pattern with standard globbing wildcards. If the current
    -+	hostname matches the pattern, the include condition is met.
    ++	hostname (output of gethostname(2)) matches the
    ++	pattern, the include condition is met.
     +
      A few more notes on matching via `gitdir` and `gitdir/i`:
      
    @@ t/t1305-config-include.sh: test_expect_success 'include cycles are detected' '
      
     +test_expect_success 'conditional include, hostname' '
     +	cat >>.git/config <<-EOF &&
    -+	[includeIf "hostname:$(hostname)a"]
    ++	[includeIf "hostname:$(test-tool xgethostname)a"]
     +		path = bar12
     +	EOF
     +	cat >>.git/bar12 <<-EOF &&
    @@ t/t1305-config-include.sh: test_expect_success 'include cycles are detected' '
     +	test_must_fail git config test.twelve &&
     +
     +	cat >>.git/config <<-EOF &&
    -+	[includeIf "hostname:$(hostname)"]
    ++	[includeIf "hostname:$(test-tool xgethostname)"]
     +		path = bar12
     +	EOF
     +	echo 12 >expect &&
    @@ t/t1305-config-include.sh: test_expect_success 'include cycles are detected' '
     +
     +test_expect_success 'conditional include, hostname, wildcard' '
     +	cat >>.git/config <<-EOF &&
    -+	[includeIf "hostname:$(hostname)a*"]
    ++	[includeIf "hostname:$(test-tool xgethostname)a*"]
     +		path = bar13
     +	EOF
     +	cat >>.git/bar13 <<-EOF &&
    @@ t/t1305-config-include.sh: test_expect_success 'include cycles are detected' '
     +	test_must_fail git config test.thirteen &&
     +
     +	cat >>.git/config <<-EOF &&
    -+	[includeIf "hostname:$(hostname)*"]
    ++	[includeIf "hostname:$(test-tool xgethostname)*"]
     +		path = bar13
     +	EOF
     +	echo 13 >expect &&
base-commit: e09f1254c54329773904fe25d7c545a1fb4fa920
-- 
2.44.0
Previous: Ignacio Encinas RubioNext: Ignacio Encinas
Message 23 of 51 in “Add hostname condition to includeIf”
  1. 0/1 Add hostname condition to includeIfIgnacio Encinas, Mar 7, 2024
  2. 1/1 config: learn the "hostname:" includeIf conditionIgnacio Encinas, Mar 7, 2024
  3. Junio C HamanoMar 7, 2024
  4. Ignacio Encinas RubioMar 9, 2024
  5. Junio C HamanoMar 9, 2024
  6. 0/1 Add hostname condition to includeIfIgnacio Encinas, Mar 9, 2024
  7. 1/1 config: learn the "hostname:" includeIf conditionIgnacio Encinas, Mar 9, 2024
  8. Junio C HamanoMar 10, 2024
  9. Ignacio Encinas RubioMar 10, 2024
  10. Junio C HamanoMar 11, 2024
  11. Ignacio Encinas RubioMar 13, 2024
  12. Jeff KingMar 16, 2024
  13. Ignacio Encinas RubioMar 16, 2024
  14. Taylor BlauMar 16, 2024
  15. Ignacio Encinas RubioMar 16, 2024
  16. Junio C HamanoMar 16, 2024
  17. rsbecker@nexbridge.comMar 16, 2024
  18. Ignacio Encinas RubioMar 16, 2024
  19. rsbecker@nexbridge.comMar 16, 2024
  20. Jeff KingMar 18, 2024
  21. Taylor BlauMar 16, 2024
  22. Ignacio Encinas RubioMar 16, 2024
  23. 0/2 Add hostname condition to includeIfIgnacio Encinas, Mar 19, 2024
  24. 1/2 t: add a test helper for getting hostnameIgnacio Encinas, Mar 19, 2024
  25. Junio C HamanoMar 19, 2024
  26. Jeff KingMar 19, 2024
  27. Junio C HamanoMar 19, 2024
  28. Jeff KingMar 19, 2024
  29. Junio C HamanoMar 19, 2024
  30. Chris TorekMar 21, 2024
  31. Jeff KingMar 19, 2024
  32. 2/2 config: learn the "hostname:" includeIf conditionIgnacio Encinas, Mar 19, 2024
  33. Junio C HamanoMar 19, 2024
  34. Jeff KingMar 19, 2024
  35. Ignacio Encinas RubioMar 19, 2024
  36. Eric SunshineMar 19, 2024
  37. Junio C HamanoMar 19, 2024
  38. Eric SunshineMar 19, 2024
  39. Jeff KingMar 20, 2024
  40. Eric SunshineMar 20, 2024
  41. Eric SunshineMar 20, 2024
  42. Chris TorekMar 20, 2024
  43. Eric SunshineMar 20, 2024
  44. Jeff KingMar 20, 2024
  45. Junio C HamanoMar 20, 2024
  46. Dirk GoudersMar 19, 2024
  47. rsbecker@nexbridge.comMar 19, 2024
  48. Dirk GoudersMar 19, 2024
  49. rsbecker@nexbridge.comMar 19, 2024
  50. Junio C HamanoMar 19, 2024
  51. Ignacio Encinas RubioMar 19, 2024

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

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