DoDiODev opened a new pull request, #9399:
URL: https://github.com/apache/devlake/pull/9399

   
   ### ⚠️ Pre Checklist
   
   > Please complete _ALL_ items in this checklist, and remove before submitting
   
   - [x] I have read through the [Contributing 
Documentation](https://devlake.apache.org/community/).
   - [x] I have added relevant tests.
   - [ ] I have added relevant documentation. (N/A)
   - [x] 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to