Skip to content

fix(gitextractor): pass --git-dir so bare clones work with safe.bareRepository=explicit - #9399

Open
DoDiODev wants to merge 1 commit into
apache:mainfrom
DoDiODev:pr/gitextractor-safe-bare-repo
Open

DoDiODev wants to merge 1 commit into
apache:mainfrom
DoDiODev:pr/gitextractor-safe-bare-repo

Conversation

@DoDiODev

Copy link
Copy Markdown
Contributor

⚠️ Pre Checklist

Please complete ALL items in this checklist, and remove before submitting

  • I have read through the Contributing Documentation.
  • I have added relevant tests.
  • I have added relevant documentation. (N/A)
  • I will add labels to the PR, such as pr-type/bug-fix, pr-type/feature-development, etc.

Summary

With safe.bareRepository=explicit (git 2.38+), git refuses to use a bare
repository that it finds from the working directory. Hardened hosts, some CI
runners and agent shells set this option, for example through
GIT_CONFIG_COUNT/GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n, and the server
inherits it.

gitextractor always clones into a bare repository and then runs git with
cmd.Dir set to that clone. With the option set, an incremental clone fails
at git repack -d:

git cmd [git repack -d] in /tmp/gitextractor… failed: fatal: cannot use bare repository '/tmp/gitextractor…' (safe.bareRepository is 'explicit')

and the collector would fail the same way on git rev-parse --git-dir.

This PR passes --git-dir=<clone> explicitly:

  • GitcliCloner.gitCommand adds it whenever a directory is given (git clone
    still runs without one).
  • gitRunner.command, used by the collector, always adds it.

The test helpers that run git inside bare repositories (runGit,
hasObject, blameAtHEAD) do the same, so the test suite also passes on
machines with the option set. A new test,
TestCloneAndCollectWithSafeBareRepositoryExplicit, sets the option and runs
an incremental clone and the collector against a bare clone.

Does this close any open issues?

No.

Screenshots

N/A

Other Information

  • go test ./plugins/gitextractor/... passes with and without
    safe.bareRepository=explicit in the environment; the new test fails without
    the fix with the error above.
  • golangci-lint run ./plugins/gitextractor/... reports no issues.
  • With older git (< 2.38) the option is unknown and ignored, and --git-dir
    behaves exactly like discovering the repository from the working directory.

…epository=explicit

With safe.bareRepository=explicit (git 2.38+), git refuses to use a bare
repository found from the working directory. The cloner and the collector
ran git with cmd.Dir set to the bare clone, so the clone failed at
`git repack -d` with "cannot use bare repository". Pass --git-dir
explicitly, and do the same in the test helpers that run git in bare repos.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant