Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cope with safe.bare repository=explicit #116

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func NewRepository(path string) (*Repository, error) {
gitDir := smartJoin(path, string(bytes.TrimSpace(out)))

//nolint:gosec // `gitBin` is chosen carefully.
cmd = exec.Command(gitBin, "rev-parse", "--git-path", "shallow")
cmd.Dir = gitDir
cmd = exec.Command(gitBin, "--git-dir", gitDir, "rev-parse", "--git-path", "shallow")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, it is no longer correct to call shallow := smartJoin(...) below, because git rev-parse --git-path is documented to return the path to the file relative to the current directory. Therefore, I think that the line below should be changed to shallow := string(bytes.TrimSpace(out)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. But since you offer a much improved solution with #117 that basically supersedes this here PR, I will simply close this PR instead ;-)

out, err = cmd.Output()
if err != nil {
return nil, fmt.Errorf(
Expand Down
7 changes: 7 additions & 0 deletions git_sizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import (
"github.com/github/git-sizer/sizes"
)

func TestMain(m *testing.M) {
// Allow Git to access the bare repositories of these tests, even if
// the user configured `safe.bareRepository=explicit` globally.
os.Setenv("GIT_CONFIG_PARAMETERS", "'safe.bareRepository=all'")
os.Exit(m.Run())
}

func sizerExe(t *testing.T) string {
t.Helper()

Expand Down
Loading