github / git-sizer

Compute various size metrics for a Git repository, flagging those that might cause problems
MIT License
3.48k stars 139 forks source link

Cope with `safe.bare repository=explicit` #116

Closed dscho closed 10 months ago

dscho commented 10 months ago

Since Git v2.38.0, safe.bareRepository is a thing. When a user configures this with the value explicit, Git invocations will fail on bare repositories unless GIT_DIR is set (either explicitly or via --git-dir).

The tests of git sizer will currently fail in such a scenario because they invoke Git inside bare repositories without setting GIT_DIR.

A more subtle issue arises when calling git sizer in a non-bare repository while safe.bareRepository=explicit is in effect: The call to git rev-parse --git-path shallow is not performed in the worktree but in the Git directory. For reasons, Git treats that situation identically to being called in a bare repository, and refuses to perform the operation.

Let's fix both of these issues so that the tests pass and so that git sizer works as expected in user setups that have safe.bareRepository set to explicit.

mhagger commented 10 months ago

When reviewing this PR I found a bunch of things about repository initialization that were gratuitously confusing. What would you think of #117, which does some cleanup and then fixes this issue, instead?

dscho commented 10 months ago

Do I understand correctly that the first git invocation in NewRepository, i.e.

git -C $path rev-parse --git-dir

would still be expected to fail if

1. the user has `safe.bareRepository=explicit` set,

2. `path` is within a **bare** repository, and

3. the user hasn't set `GIT_PATH` before running `git-sizer`

? If so, I think that correctly reflects what the user would expect given that they made that config setting.

This matches my understanding.