Git designed for AI agents.
operations: the proposals of a land are written into a quarantine of their own
Federico Elia7e2383ce3061
diff --git a/internal/gitaly/service/operations/fanout_removal_test.go b/internal/gitaly/service/operations/fanout_removal_test.goindex c026bec..933db7a 100644--- a/internal/gitaly/service/operations/fanout_removal_test.go+++ b/internal/gitaly/service/operations/fanout_removal_test.go@@ -136,3 +136,45 @@ func TestUserMergeToRef_fanOutDirectoryRemoved(t *testing.T) {require.Equal(t, []string{ours.String(), theirs.String()}, merged.GetParentIds())gittest.Exec(t, cfg, "-C", repoPath, "fsck", "--strict")}++// The proposals that UserLand keeps of a resolver's answer are written outside the land's+// quarantine, which a failed land discards, but in a quarantine of their own.+func TestUserLand_proposalsFanOutDirectoryRemoved(t *testing.T) {+ t.Parallel()++ ctx := testhelper.Context(t)+ cfg := testcfg.Build(t)+ factory := gittest.NewFanOutRemovingCommandFactory(t, ctx, cfg)++ dir, argv := resolverScript(t, "")+ writeAnswer(t, dir, modelAnswer())+ fx := newResolveFixtureOn(t, cfg, config.Graft{Land: config.GraftLand{Resolver: enabledResolver(argv)}},+ []gittest.TreeEntry{+ {Mode: "100644", Path: "a", Content: "base\n"},+ {Mode: "100644", Path: "b", Content: "base\n"},+ },+ []gittest.TreeEntry{+ {Mode: "100644", Path: "a", Content: "ours\n"},+ {Mode: "100644", Path: "b", Content: "ours\n"},+ },+ []gittest.TreeEntry{+ {Mode: "100644", Path: "a", Content: "theirs\n"},+ {Mode: "100644", Path: "b", Content: "theirs\n"},+ },+ testserver.WithGitCommandFactory(factory),+ )+ gittest.Exec(t, fx.cfg, "-C", fx.repoPath, "update-ref", "refs/heads/landed", fx.commit.String())+ packWithoutFanOut(t, fx.cfg, fx.repoPath)++ _, err := fx.client.UserLand(fx.ctx, fx.request("Land"))+ requireMergeConflict(t, err)+ pkg := landConflictDetail(err)+ require.NotNil(t, pkg)++ target := proposalRefTarget(t, fx)+ require.NotEmpty(t, target, "the proposal reference exists")+ for _, p := range []string{"a", "b"} {+ require.Equal(t, "merged-"+p+"\n", string(gittest.Exec(t, fx.cfg, "-C", fx.repoPath, "cat-file", "blob", packageFile(t, pkg, p).GetProposal().GetOid())))+ }+ gittest.Exec(t, fx.cfg, "-C", fx.repoPath, "fsck", "--strict")+}diff --git a/internal/gitaly/service/operations/land_proposals.go b/internal/gitaly/service/operations/land_proposals.goindex 20050b2..96cee4f 100644--- a/internal/gitaly/service/operations/land_proposals.go+++ b/internal/gitaly/service/operations/land_proposals.go@@ -120,11 +120,13 @@ func landProposalExplanation(f resolver.ResponseFile, explanation string) string// landWriteProposals keeps the resolver's answer for the agent: the written contents as blobs, a// commit whose tree holds them by path (its parents the tip and the landed commit), and the// proposal reference of (branch, commit) pointing at it, replacing an older one. The objects are-// written into the repository itself, not the quarantine of the land, which a failed land discards,-// and the reference is updated through the reference transaction (and so the voter in-// authoritative storage mode). It sets the proposal of every file of the listing and returns the-// reference. The branch's older proposals are pruned after; a failed pruning is logged and-// counted, and fails nothing.+// written into a quarantine of their own, not the quarantine of the land, which a failed land+// discards, and migrated into the repository before the reference update: a loose object written+// straight into the repository would race housekeeping's removal of empty loose object+// directories, which the migration survives. The reference is updated through the reference+// transaction (and so the voter in authoritative storage mode). It sets the proposal of every+// file of the listing and returns the reference. The branch's older proposals are pruned after; a+// failed pruning is logged and counted, and fails nothing.func (s *Server) landWriteProposals(ctx context.Context, in *gitalypb.UserLandRequest, l landListing, answer *resolver.Response, committer git.Signature) (git.ReferenceName, error) {// Who caused the proposals is in their commit, the trace of the reference: the update itself// is the server's (landUpdateProposalRefs).@@ -134,12 +136,17 @@ func (s *Server) landWriteProposals(ctx context.Context, in *gitalypb.UserLandRenow := time.Now()start := nowrepo := s.localRepoFactory.Build(in.GetRepository())+ quarantineDir, quarantineRepo, cleanup, err := s.quarantinedRepo(ctx, in.GetRepository())+ if err != nil {+ return "", err+ }+ defer cleanup()tree := &localrepo.TreeEntry{Type: localrepo.Tree, Mode: "040000"}byPath := make(map[string]*gitalypb.LandConflictProposal, len(answer.Files))for _, f := range answer.Files {p := &gitalypb.LandConflictProposal{Action: f.Action, Resolver: answer.Resolver, Explanation: landProposalExplanation(f, answer.Explanation)}if f.Action == resolver.ActionWrite {- blob, err := repo.WriteBlob(ctx, bytes.NewReader(f.Content), localrepo.WriteBlobConfig{Path: f.Path})+ blob, err := quarantineRepo.WriteBlob(ctx, bytes.NewReader(f.Content), localrepo.WriteBlobConfig{Path: f.Path})if err != nil {return "", fmt.Errorf("writing the proposal of %q: %w", f.Path, err)}@@ -151,10 +158,10 @@ func (s *Server) landWriteProposals(ctx context.Context, in *gitalypb.UserLandRe}byPath[f.Path] = p}- if err := tree.Write(ctx, repo); err != nil {+ if err := tree.Write(ctx, quarantineRepo); err != nil {return "", fmt.Errorf("writing the tree of the proposals: %w", err)}- commit, err := repo.WriteCommit(ctx, localrepo.WriteCommitConfig{+ commit, err := quarantineRepo.WriteCommit(ctx, localrepo.WriteCommitConfig{TreeID: tree.OID,Message: fmt.Sprintf("graft: proposals for landing %s onto %s\n\nResolver: %s\nRequested-By: %s\n", l.commitID, l.tip, landTrailerValueOrQuoted(answer.Resolver), landTrailerValueOrQuoted(actor)),Parents: []git.ObjectID{l.tip, l.commitID},@@ -186,6 +193,9 @@ func (s *Server) landWriteProposals(ctx context.Context, in *gitalypb.UserLandReif oldOID == "" {oldOID = objectHash.ZeroOID}+ if err := quarantineDir.Migrate(ctx); err != nil {+ return "", fmt.Errorf("migrating the proposals: %w", err)+ }if err := proposals.Update(ctx, repo, []proposals.Op{{Name: ref, NewOID: commit, OldOID: oldOID}}); err != nil {return "", err}diff --git a/internal/gitaly/service/operations/land_resolve_test.go b/internal/gitaly/service/operations/land_resolve_test.goindex 9ed69fd..acd62b7 100644--- a/internal/gitaly/service/operations/land_resolve_test.go+++ b/internal/gitaly/service/operations/land_resolve_test.go@@ -30,6 +30,7 @@ import ("github.com/feder-cr/git-ai/internal/graft/resolver""github.com/feder-cr/git-ai/internal/testhelper""github.com/feder-cr/git-ai/internal/testhelper/testcfg"+ "github.com/feder-cr/git-ai/internal/testhelper/testserver""github.com/feder-cr/git-ai/proto/go/gitalypb""github.com/prometheus/client_golang/prometheus")@@ -204,7 +205,14 @@ func newResolveFixtureWith(t *testing.T, rcfg config.GraftResolver, baseEntries,func newResolveFixtureIn(t *testing.T, graft config.Graft, baseEntries, tipEntries, commitEntries []gittest.TreeEntry) resolveFixture {t.Helper()- cfg := testcfg.Build(t)+ return newResolveFixtureOn(t, testcfg.Build(t), graft, baseEntries, tipEntries, commitEntries)+}++// newResolveFixtureOn is newResolveFixtureIn on the configuration cfg, with the options of the+// server.+func newResolveFixtureOn(t *testing.T, cfg config.Cfg, graft config.Graft, baseEntries, tipEntries, commitEntries []gittest.TreeEntry, options ...testserver.GitalyServerOpt) resolveFixture {+ t.Helper()+cfg.Graft = graftvar lanes *landlane.Sharedif graft.Standalone {@@ -215,7 +223,7 @@ func newResolveFixtureIn(t *testing.T, graft config.Graft, baseEntries, tipEntri}testcfg.BuildGitalySSH(t, cfg)testcfg.BuildGitalyHooks(t, cfg)- cfg.SocketPath = runOperationServiceServerWithLanes(t, cfg, lanes)+ cfg.SocketPath = runOperationServiceServerWithLanes(t, cfg, lanes, options...)client, conn := newOperationClient(t, cfg.SocketPath)t.Cleanup(func() { conn.Close() })ctx := testhelper.MergeOutgoingMetadata(testhelper.Context(t), testcfg.GitalyServersMetadataFromCfg(t, cfg))@@ -268,10 +276,12 @@ func (fx resolveFixture) server(t *testing.T, rcfg config.GraftResolver) *Serverif rcfg.Verify.Enabled {pool = resolver.NewVerifyPool(rcfg)}+ locator := config.NewLocator(fx.cfg)return &Server{logger: testhelper.NewLogger(t), gitConfig: fx.cfg.Git, resolveCfg: rcfg, conflictResolver: client, verifyPool: pool,catfileCache: cache,- localRepoFactory: localrepo.NewFactory(testhelper.NewLogger(t), config.NewLocator(fx.cfg), gittest.NewCommandFactory(t, fx.cfg), cache),+ locator: locator,+ localRepoFactory: localrepo.NewFactory(testhelper.NewLogger(t), locator, gittest.NewCommandFactory(t, fx.cfg), cache),}}