Skip to content

Commit

Permalink
Merge branch 'kl/allow-working-in-dot-git-in-non-bare-repository'
Browse files Browse the repository at this point in the history
The "disable repository discovery of a bare repository" check,
triggered by setting safe.bareRepository configuration variable to
'explicit', has been loosened to exclude the ".git/" directory inside
a non-bare repository from the check.  So you can do "cd .git &&
git cmd" to run a Git command that works on a bare repository without
explicitly specifying $GIT_DIR now.

* kl/allow-working-in-dot-git-in-non-bare-repository:
  setup: allow cwd=.git w/ bareRepository=explicit
  • Loading branch information
gitster committed Jan 30, 2024
2 parents fa50e7a + 45bb916 commit a8bf3c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,8 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,

if (is_git_directory(dir->buf)) {
trace2_data_string("setup", NULL, "implicit-bare-repository", dir->buf);
if (get_allowed_bare_repo() == ALLOWED_BARE_REPO_EXPLICIT)
if (get_allowed_bare_repo() == ALLOWED_BARE_REPO_EXPLICIT &&
!ends_with_path_components(dir->buf, ".git"))
return GIT_DIR_DISALLOWED_BARE;
if (!ensure_valid_ownership(NULL, NULL, dir->buf, report))
return GIT_DIR_INVALID_OWNERSHIP;
Expand Down
8 changes: 8 additions & 0 deletions t/t0035-safe-bare-repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ test_expect_success 'no trace when GIT_DIR is explicitly provided' '
expect_accepted_explicit "$pwd/outer-repo/bare-repo"
'

test_expect_success 'no trace when "bare repository" is .git' '
expect_accepted_implicit -C outer-repo/.git
'

test_expect_success 'no trace when "bare repository" is a subdir of .git' '
expect_accepted_implicit -C outer-repo/.git/objects
'

test_done

0 comments on commit a8bf3c0

Please sign in to comment.