Skip to content

Commit

Permalink
spokes.go : Add support for parsing recieve.fsck.* config for strict …
Browse files Browse the repository at this point in the history
…args

This change adds support for parsing the receive.fsck.* config options.
Adds a test for checking if the receive.fsck.* args are respected.

Signed-off-by: Ridhwaan Ahmed <ridhwaandev@github.com>
  • Loading branch information
RidhwaanDev committed May 10, 2024
1 parent d92db4b commit a7f1e35
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/config/git_test.go
Expand Up @@ -97,12 +97,14 @@ func TestGetPrefixParsesArgs(t *testing.T) {
assert.NoError(t, cmd("git", "config", "user.name", "spokes-receive-pack").Run())
assert.NoError(t, cmd("git", "config", "receive.fsck.missingEmail", "ignore").Run())
assert.NoError(t, cmd("git", "config", "receive.fsck.badTagName", "ignore").Run())
assert.NoError(t, cmd("git", "config","--add", "receive.fsck.badTagName", "error").Run())

config, _ := GetConfig(localRepo)
prefix := config.GetPrefix("receive.fsck.")

assert.Equal(t, prefix["missingemail"][0], "ignore")
assert.Equal(t, prefix["badtagname"][0], "ignore")
assert.Equal(t, prefix["badtagname"][1], "error")
}


Expand Down
33 changes: 33 additions & 0 deletions internal/integration/integration_test.go
Expand Up @@ -378,6 +378,39 @@ func (suite *SpokesReceivePackTestSuite) TestSpokesReceivePackWrongObjectSucceed
})
}


func (suite *SpokesReceivePackTestSuite) TestSpokesReceivePackIgnoreArgsSucceed() {
assert.NoError(suite.T(), chdir(suite.T(), suite.remoteRepo), "unable to chdir into our remote Git repo")
require.NoError(suite.T(), exec.Command("git", "config", "receive.fsckObjects", "true").Run())
require.NoError(suite.T(), exec.Command("git", "config", "receive.fsck.missingEmail", "ignore").Run())
require.NoError(suite.T(), exec.Command("git", "config", "receive.fsck.badTagName", "ignore").Run())

assert.NoError(suite.T(), chdir(suite.T(), suite.localRepo), "unable to chdir into our local Git repo")

createBogusObjectAndPush(suite, func(suite *SpokesReceivePackTestSuite, err error, _ []byte) {
assert.NoError(
suite.T(),
err,
"unexpected error running the push with the custom spokes-receive-pack program; it should have succeeded since fsck args are ignored")
})
}

func (suite *SpokesReceivePackTestSuite) TestSpokesReceivePackMissingArgsFails() {
assert.NoError(suite.T(), chdir(suite.T(), suite.remoteRepo), "unable to chdir into our remote Git repo")
require.NoError(suite.T(), exec.Command("git", "config", "receive.fsckObjects", "true").Run())
require.NoError(suite.T(), exec.Command("git", "config", "receive.fsck.missingEmail", "error").Run())
require.NoError(suite.T(), exec.Command("git", "config", "receive.fsck.badTagName", "error").Run())

assert.NoError(suite.T(), chdir(suite.T(), suite.localRepo), "unable to chdir into our local Git repo")

createBogusObjectAndPush(suite, func(suite *SpokesReceivePackTestSuite, err error, _ []byte) {
assert.Error(
suite.T(),
err,
"unexpected success running the push with the custom spokes-receive-pack program; it should have failed due to missing fsck args")
})
}

func (suite *SpokesReceivePackTestSuite) TestSpokesReceivePackPushFromShallowClone() {
var cmd *exec.Cmd

Expand Down
15 changes: 14 additions & 1 deletion internal/spokes/spokes.go
Expand Up @@ -823,7 +823,20 @@ func (r *spokesReceivePack) readPack(ctx context.Context, commands []command, ca
args = append(args, "--fix-thin")

if r.isFsckConfigEnabled() {
args = append(args, "--strict")
prefix := r.config.GetPrefix("receive.fsck.")
if len(prefix) > 0 {
var result string
for key, values := range prefix {
for _, value := range values {
result += key + "=" + value + ","
}
}
result = strings.TrimSuffix(result, ",")
result = "--strict=" + result
args = append(args, result)
} else {
args = append(args, "--strict")
}
}

maxSize, err := r.getMaxInputSize()
Expand Down

0 comments on commit a7f1e35

Please sign in to comment.