Skip to content

Commit

Permalink
Allow bad dates, but only for imports and only when it's specifically…
Browse files Browse the repository at this point in the history
… requested

In general, it's better if customers rewrite their repos to remove the
bad dates because bad dates aren't guaranteed to work with all of our
systems and APIs. But, sometimes there are bad dates in a corner of a
repo where they're unlikely to cause problems, and the cost of rewriting
the repo is too high to be worth it.
  • Loading branch information
spraints committed Nov 14, 2024
1 parent adecdda commit 07b8ffc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
30 changes: 30 additions & 0 deletions internal/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ committer Spokes Receive Pack <[email protected]> 1234567890 +0000
This commit object intentionally broken
`

var suiteDir string = func() string {
pwd, err := os.Getwd()
if err != nil {
panic(err)
}
return pwd
}()

type SpokesReceivePackTestSuite struct {
suite.Suite
localRepo, remoteRepo string
Expand Down Expand Up @@ -181,6 +189,28 @@ func (suite *SpokesReceivePackTestSuite) TestSpokesReceivePackHiddenRefs() {
"should partially fail")
}

func (suite *SpokesReceivePackTestSuite) TestBadDate() {
cmd := exec.Command("git", "-C", filepath.Join(suiteDir, "testdata/bad-date/sha1.git"),
"push", "--receive-pack=spokes-receive-pack-wrapper", suite.remoteRepo, "main")
out, err := cmd.CombinedOutput()
suite.T().Logf("$ git %s\n%s", strings.Join(cmd.Args, " "), out)
assert.Error(suite.T(), err, "expect an error a repo with a malformed committer line in a commit")
assert.Contains(suite.T(), string(out), " badDate:", "should complain about a bad date")
}

func (suite *SpokesReceivePackTestSuite) TestBadDateAllowedWithOverride() {
cmd := exec.Command("git", "-C", filepath.Join(suiteDir, "testdata/bad-date/sha1.git"),
"push", "--receive-pack=spokes-receive-pack-wrapper", suite.remoteRepo, "main")
cmd.Env = append(os.Environ(),
"GIT_SOCKSTAT_VAR_is_importing=bool:true",
"GIT_SOCKSTAT_VAR_allow_baddate_in_import=bool:true",
)
out, err := cmd.CombinedOutput()
suite.T().Logf("$ git %s\n%s", strings.Join(cmd.Args, " "), out)
assert.NoError(suite.T(), err, "expect the push to succeed")
assert.Contains(suite.T(), string(out), " badDate:", "should still complain about a bad date")
}

func (suite *SpokesReceivePackTestSuite) TestWithGovernor() {
started := make(chan any)
govSock, msgs, cleanup := startFakeGovernor(suite.T(), started, nil)
Expand Down
18 changes: 16 additions & 2 deletions internal/spokes/spokes.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,13 @@ func (r *spokesReceivePack) readPack(ctx context.Context, commands []command, ca
// mimic https://github.com/git/git/blob/950264636c68591989456e3ba0a5442f93152c1a/builtin/receive-pack.c#L2252-L2273
// and https://github.com/github/git/blob/d4a224977e032f93b1b8fd3201201f098d4f6757/builtin/receive-pack.c#L2362-L2386

args := []string{"index-pack", "--stdin"}
var args []string

if allowBadDate() {
args = append(args, "-c", "receive.fsck.badDate=warn")
}

args = append(args, "index-pack", "--stdin")

// FIXME? add --pack_header similar to git's push_header_arg

Expand Down Expand Up @@ -950,7 +956,7 @@ func (r *spokesReceivePack) isFsckConfigEnabled() bool {
}

func (r *spokesReceivePack) getMaxInputSize() (int, error) {
if sockstat.GetBool("is_importing") {
if isImporting() {
return 80 * 1024 * 1024 * 1024, nil /* 80 GB */
}

Expand Down Expand Up @@ -1225,6 +1231,14 @@ func isQuiet(c pktline.Capabilities) bool {
return c.IsDefined(pktline.Quiet)
}

func isImporting() bool {
return sockstat.GetBool("is_importing")
}

func allowBadDate() bool {
return isImporting() && sockstat.GetBool("allow_baddate_in_import")
}

func useSideBand(c pktline.Capabilities) bool {
return c.IsDefined(pktline.SideBand) || c.IsDefined(pktline.SideBand64k)
}
Expand Down

0 comments on commit 07b8ffc

Please sign in to comment.