git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Phillip Wood <phillip.wood123@gmail.com>
Subject: [PATCH v2 0/3] safe.directory clean-up
Date: Mon, 22 Jul 2024 19:18:57 -0700	[thread overview]
Message-ID: <20240723021900.388020-1-gitster@pobox.com> (raw)
In-Reply-To: <20240720220915.2933266-1-gitster@pobox.com>

Changes since v1:

 - two "extra" patches for optimization that are unnecessary have
   been dropped.
 - a patch to add test for safe.directory="." use case has been
   added. 

Recently we discussed what we should do when either the path
configured in the safe.directory configuration or coming from
the caller of ensure_valid_ownership() function as a result of
repository discovery is not normalized and textual equality check is
not sufficient.  See the thread the contains

  https://lore.kernel.org/git/6d5b75a6-639d-429b-bd37-232fc6f475af@gmail.com/

Here are three patches that implement the comparison between
normalized path and configuration value.

Imagine that you have a repository at /mnt/disk4/repos/frotz
directory but in order to make it simpler to manage and use, you
have your users use /projects/frotz to access the repository.  A
symlink /projects/frotz pointing at /mnt/disk4/repos/frotz directory
allows you to do so.

 - The first patch normalizes the path to the directory that we
   suspect is a usable repository, before comparing it with the
   safe.directory configuration variable.  The safe.directory may
   say /mnt/disk4/repos/frotz or /mnt/disk4/repos/*, but the path to
   the repository for the users may be /mnt/disk4/repos/frotz or
   /projects/frotz, depending on where they come from and what their
   $PWD makes getcwd() to say.

 - The second patch normalizes the value of the safe.directory
   variable.  This allows safe.directory to say /projects/frotz
   or /projects/* and have them match /mnt/disk4/repos/frotz (which
   is how the first patch normalizes the repository path to).

 - The third patch only adds a test to illustrate what happens when
   the safe.directory configuration is set to ".", which was a
   plausible setting for those who run "git daemon".  The
   normalization done by the first two patches is sufficient to make
   this just work.

Junio C Hamano (3):
  safe.directory: normalize the checked path
  safe.directory: normalize the configured path
  safe.directory: setting safe.directory="." allows the "current"
    directory

 setup.c                   |  28 ++++++--
 t/t0033-safe-directory.sh | 146 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 170 insertions(+), 4 deletions(-)

Range-diff against v1:
1:  20e1160946 ! 1:  86d5c83ee7 safe.directory: normalize the checked path
    @@ t/t0033-safe-directory.sh: test_expect_success 'local clone of unowned repo acce
     +		sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
     +		git config --global safe.directory "$(pwd)/repository"
     +	) &&
    -+	git -C repository/ for-each-ref >/dev/null &&
    -+	git -C repo/ for-each-ref
    ++	git -C repository for-each-ref &&
    ++	git -C repository/ for-each-ref &&
    ++	git -C repo for-each-ref &&
    ++	git -C repo/ for-each-ref &&
    ++	test_must_fail git -C repository/.git for-each-ref &&
    ++	test_must_fail git -C repository/.git/ for-each-ref &&
    ++	test_must_fail git -C repo/.git for-each-ref &&
    ++	test_must_fail git -C repo/.git/ for-each-ref
     +'
     +
     +test_expect_success SYMLINKS 'checked leading paths are normalized' '
    @@ t/t0033-safe-directory.sh: test_expect_success 'local clone of unowned repo acce
     +		sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
     +		git config --global safe.directory "$(pwd)/repository/*"
     +	) &&
    -+	git -C repository/s for-each-ref >/dev/null &&
    -+	git -C repo/s for-each-ref
    ++	git -C repository/s for-each-ref &&
    ++	git -C repository/s/ for-each-ref &&
    ++	git -C repo/s for-each-ref &&
    ++	git -C repo/s/ for-each-ref &&
    ++	git -C repository/s/.git for-each-ref &&
    ++	git -C repository/s/.git/ for-each-ref &&
    ++	git -C repo/s/.git for-each-ref &&
    ++	git -C repo/s/.git/ for-each-ref
     +'
     +
      test_done
2:  06de9038b7 ! 2:  c4998076da safe.directory: normalize the configured path
    @@ setup.c: static int safe_directory_cb(const char *key, const char *value,
     
      ## t/t0033-safe-directory.sh ##
     @@ t/t0033-safe-directory.sh: test_expect_success SYMLINKS 'checked leading paths are normalized' '
    - 	git -C repo/s for-each-ref
    + 	git -C repo/s/.git/ for-each-ref
      '
      
     +test_expect_success SYMLINKS 'configured paths are normalized' '
    @@ t/t0033-safe-directory.sh: test_expect_success SYMLINKS 'checked leading paths a
     +		sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
     +		git config --global safe.directory "$(pwd)/repo"
     +	) &&
    -+	git -C repository/ for-each-ref >/dev/null &&
    -+	git -C repo/ for-each-ref
    ++	git -C repository for-each-ref &&
    ++	git -C repository/ for-each-ref &&
    ++	git -C repo for-each-ref &&
    ++	git -C repo/ for-each-ref &&
    ++	test_must_fail git -C repository/.git for-each-ref &&
    ++	test_must_fail git -C repository/.git/ for-each-ref &&
    ++	test_must_fail git -C repo/.git for-each-ref &&
    ++	test_must_fail git -C repo/.git/ for-each-ref
     +'
     +
     +test_expect_success SYMLINKS 'configured leading paths are normalized' '
    @@ t/t0033-safe-directory.sh: test_expect_success SYMLINKS 'checked leading paths a
     +	git init repository/s &&
     +	ln -s repository repo &&
     +	(
    -+		cd repository &&
    ++		cd repository/s &&
     +		sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
     +		test_commit sample
     +	) &&
    @@ t/t0033-safe-directory.sh: test_expect_success SYMLINKS 'checked leading paths a
     +		sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
     +		git config --global safe.directory "$(pwd)/repo/*"
     +	) &&
    -+	git -C repository/s for-each-ref >/dev/null &&
    -+	git -C repo/s for-each-ref
    ++	git -C repository/s for-each-ref &&
    ++	git -C repository/s/ for-each-ref &&
    ++	git -C repository/s/.git for-each-ref &&
    ++	git -C repository/s/.git/ for-each-ref &&
    ++	git -C repo/s for-each-ref &&
    ++	git -C repo/s/ for-each-ref &&
    ++	git -C repo/s/.git for-each-ref &&
    ++	git -C repo/s/.git/ for-each-ref
     +'
     +
      test_done
-:  ---------- > 3:  ffc3f7364e safe.directory: setting safe.directory="." allows the "current" directory
-- 
2.46.0-rc1-52-gda884b23f2


  parent reply	other threads:[~2024-07-23  2:19 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-20 22:09 [PATCH 0/2] safe.directory clean-up Junio C Hamano
2024-07-20 22:09 ` [PATCH 1/2] safe.directory: normalize the checked path Junio C Hamano
2024-07-20 22:09 ` [PATCH 2/2] safe.directory: normalize the configured path Junio C Hamano
2024-07-20 22:09 ` [PATCH 3/2] setup: use a single return path in setup_git_directory*() Junio C Hamano
2024-07-20 22:09 ` [PATCH 4/2] setup: cache normalized safe.directory configuration Junio C Hamano
2024-07-23  2:18 ` Junio C Hamano [this message]
2024-07-23  2:18   ` [PATCH v2 1/3] safe.directory: normalize the checked path Junio C Hamano
2024-07-23  2:18   ` [PATCH v2 2/3] safe.directory: normalize the configured path Junio C Hamano
2024-07-25  9:45     ` Phillip Wood
2024-07-25 16:11       ` Junio C Hamano
2024-08-14 13:20         ` Phillip Wood
2024-08-14 17:15           ` Junio C Hamano
2024-08-15  9:51             ` Phillip Wood
2024-08-15 14:43               ` Junio C Hamano
2024-07-26  5:02     ` Jeff King
2024-07-26 15:02       ` Junio C Hamano
2024-07-27 22:05         ` Jeff King
2024-07-23  2:19   ` [PATCH v2 3/3] safe.directory: setting safe.directory="." allows the "current" directory Junio C Hamano
2024-07-25  9:45     ` Phillip Wood
2024-07-25 16:12       ` Junio C Hamano
2024-07-25  9:45   ` [PATCH v2 0/3] safe.directory clean-up Phillip Wood
2024-07-25 16:14     ` Junio C Hamano
2024-07-30  1:10 ` [PATCH v3 " Junio C Hamano
2024-07-30  1:10   ` [PATCH v3 1/3] safe.directory: normalize the checked path Junio C Hamano
2024-07-30  1:10   ` [PATCH v3 2/3] safe.directory: normalize the configured path Junio C Hamano
2024-07-30  7:31     ` Jeff King
2024-07-30 16:03       ` Junio C Hamano
2024-07-30 20:08         ` Jeff King
2024-07-30  7:43     ` Jeff King
2024-07-30 16:22       ` Junio C Hamano
2024-07-30 17:56         ` safe.directory: preliminary clean-up Junio C Hamano
2024-07-30 20:13           ` Jeff King
2024-07-30 20:10         ` [PATCH v3 2/3] safe.directory: normalize the configured path Jeff King
2024-07-30  1:10   ` [PATCH v3 3/3] safe.directory: setting safe.directory="." allows the "current" directory Junio C Hamano
2024-07-30 18:43 ` [PATCH v4 0/4] safe.directory clean-up Junio C Hamano
2024-07-30 18:43   ` [PATCH v4 1/4] safe.directory: preliminary clean-up Junio C Hamano
2024-07-30 18:43   ` [PATCH v4 2/4] safe.directory: normalize the checked path Junio C Hamano
2024-07-30 18:43   ` [PATCH v4 3/4] safe.directory: normalize the configured path Junio C Hamano
2024-07-30 18:43   ` [PATCH v4 4/4] safe.directory: setting safe.directory="." allows the "current" directory Junio C Hamano

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=20240723021900.388020-1-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood123@gmail.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).