Git designed for AI agents.
graft-resolve: bench mine skips merges of unrelated histories
Federico Elia332e30f9d99a
diff --git a/tools/graft-agents/resolve/bench/bench_test.go b/tools/graft-agents/resolve/bench/bench_test.goindex b3e1096..ee6024d 100644--- a/tools/graft-agents/resolve/bench/bench_test.go+++ b/tools/graft-agents/resolve/bench/bench_test.go@@ -151,6 +151,35 @@ func TestMineKeepsRealResolutions(t *testing.T) {}}+// TestMineSkipsUnrelatedHistories mines a repository that absorbed another one with a merge of+// unrelated histories, which git merge-tree refuses: the merge is skipped and counted, and the+// conflicting merge after it is still mined.+func TestMineSkipsUnrelatedHistories(t *testing.T) {+ f := newFixture(t)+ f.commit("base", map[string]string{"a.go": "package a\n\nvar x = 1\n"})+ f.git("checkout", "-q", "--orphan", "other")+ f.git("rm", "-q", "-r", "--cached", ".")+ f.commit("other root", map[string]string{"b.py": "y = 1\n"})+ f.git("checkout", "-q", "-f", "main")+ f.git("merge", "-q", "--no-ff", "--allow-unrelated-histories", "-m", "absorb other", "other")++ f.git("checkout", "-q", "-b", "feature")+ f.commit("three", map[string]string{"a.go": "package a\n\nvar x = 3\n"})+ f.git("checkout", "-q", "main")+ f.commit("two", map[string]string{"a.go": "package a\n\nvar x = 2\n"})+ f.conflictMerge("feature", map[string]string{"a.go": "package a\n\nvar x = 2 + 3\n"})+ head := f.git("rev-parse", "HEAD")++ cases, stats, err := Mine(context.Background(), Repo{Name: "fixture", Commit: head, License: "MIT"}, f.dir, MineOptions{})+ if err != nil {+ t.Fatal(err)+ }+ want := MineStats{Merges: 2, ConflictingMerges: 1, SkippedMergeBases: 1, ConflictingFiles: 1, Kept: 1}+ if stats != want || len(cases) != 1 {+ t.Fatalf("stats %+v (%d cases), want %+v and 1 case", stats, len(cases), want)+ }+}+// fixedStrategy answers every file with content, or fails with err.type fixedStrategy struct {content []bytediff --git a/tools/graft-agents/resolve/bench/mine.go b/tools/graft-agents/resolve/bench/mine.goindex 75dca47..530a762 100644--- a/tools/graft-agents/resolve/bench/mine.go+++ b/tools/graft-agents/resolve/bench/mine.go@@ -23,7 +23,8 @@ type MineStats struct {Merges int `json:"merges"`ConflictingMerges int `json:"conflicting_merges"`// SkippedMergeBases counts merges whose parents have no single merge base (criss-cross or- // unrelated histories): the resolver is given one base.+ // unrelated histories): the resolver is given one base. Merges of unrelated histories are+ // counted here whether they conflict or not, since git merge-tree refuses to replay them.SkippedMergeBases int `json:"skipped_merge_bases"`ConflictingFiles int `json:"conflicting_files"`// OtherFamily counts conflicting files of no benchmark family.@@ -65,6 +66,13 @@ func Mine(ctx context.Context, repo Repo, dir string, opts MineOptions) ([]Case,paths, err := g.conflicts(ctx, ours, theirs)if err != nil {+ // git merge-tree refuses unrelated histories (a repository that absorbed another+ // one): the merge is skipped when its parents have no merge base, and the error+ // stands otherwise.+ if bases, baseErr := g.mergeBases(ctx, ours, theirs); baseErr == nil && len(bases) == 0 {+ stats.SkippedMergeBases+++ continue+ }return nil, stats, fmt.Errorf("merge %s: %w", merge, err)}if len(paths) == 0 {