git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ignacio Encinas <ignacio@iencinas.com>
To: git@vger.kernel.org
Cc: Ignacio Encinas <ignacio@iencinas.com>, Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>, Taylor Blau <me@ttaylorr.com>,
	rsbecker@nexbridge.com
Subject: [PATCH v3 0/2] Add hostname condition to includeIf
Date: Tue, 19 Mar 2024 19:37:20 +0100	[thread overview]
Message-ID: <20240319183722.211300-1-ignacio@iencinas.com> (raw)
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


  parent reply	other threads:[~2024-03-19 18:38 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 20:50 [RFC PATCH 0/1] Add hostname condition to includeIf Ignacio Encinas
2024-03-07 20:50 ` [RFC PATCH 1/1] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-07 21:40   ` Junio C Hamano
2024-03-09 10:47     ` Ignacio Encinas Rubio
2024-03-09 17:38       ` Junio C Hamano
2024-03-09 18:18 ` [PATCH v2 0/1] Add hostname condition to includeIf Ignacio Encinas
2024-03-09 18:18   ` [PATCH v2 1/1] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-10 16:59     ` Junio C Hamano
2024-03-10 18:46       ` Ignacio Encinas Rubio
2024-03-11 17:39         ` Junio C Hamano
2024-03-13 21:53           ` Ignacio Encinas Rubio
2024-03-16  6:57     ` Jeff King
2024-03-16 11:19       ` Ignacio Encinas Rubio
2024-03-16 16:00         ` Taylor Blau
2024-03-16 16:46           ` Ignacio Encinas Rubio
2024-03-16 17:02       ` Junio C Hamano
2024-03-16 17:41         ` rsbecker
2024-03-16 18:05           ` Ignacio Encinas Rubio
2024-03-16 18:49             ` rsbecker
2024-03-18  8:17         ` Jeff King
2024-03-16 16:01     ` Taylor Blau
2024-03-16 16:50       ` Ignacio Encinas Rubio
2024-03-19 18:37   ` Ignacio Encinas [this message]
2024-03-19 18:37     ` [PATCH v3 1/2] t: add a test helper for getting hostname Ignacio Encinas
2024-03-19 20:31       ` Junio C Hamano
2024-03-19 20:57         ` Jeff King
2024-03-19 21:00           ` Junio C Hamano
2024-03-19 21:11             ` Jeff King
2024-03-19 21:44               ` Junio C Hamano
2024-03-21  0:11                 ` Chris Torek
2024-03-19 20:56       ` Jeff King
2024-03-19 18:37     ` [PATCH v3 2/2] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-19 20:53       ` Junio C Hamano
2024-03-19 21:04       ` Jeff King
2024-03-19 21:32         ` Ignacio Encinas Rubio
2024-03-19 20:55     ` [PATCH v3 0/2] Add hostname condition to includeIf Eric Sunshine
2024-03-19 21:12       ` Junio C Hamano
2024-03-19 21:13         ` Eric Sunshine
2024-03-20  0:19           ` Jeff King
2024-03-20  2:49             ` Eric Sunshine
2024-03-20  3:07               ` Eric Sunshine
2024-03-20 14:34                 ` Chris Torek
2024-03-20 16:37                   ` Eric Sunshine
2024-03-20 20:51                     ` Jeff King
2024-03-20 16:49                   ` Junio C Hamano
2024-03-19 21:36         ` Dirk Gouders
2024-03-19 22:03           ` rsbecker
2024-03-19 22:26             ` Dirk Gouders
2024-03-19 22:31               ` rsbecker
2024-03-19 22:59                 ` Junio C Hamano
2024-03-19 21:22       ` Ignacio Encinas Rubio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240319183722.211300-1-ignacio@iencinas.com \
    --to=ignacio@iencinas.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    --cc=rsbecker@nexbridge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).