Skip to content

Git designed for AI agents.

gitai land: fixes of the review of WP5/WP6 (c1)

Federico Elia54189d1bbe19
diff --git a/cmd/graft/commands.go b/cmd/graft/commands.go
index d53cb64..9da6439 100644
--- a/cmd/graft/commands.go
+++ b/cmd/graft/commands.go
@@ -192,7 +192,7 @@ func cmdLand(ctx context.Context, out io.Writer, o *options, args []string) erro
if pkg, ok := sdk.LandConflict(err); ok {
printConflict(out, pkg)
if o.conflictsDir != "" {
- if werr := writeConflicts(ctx, ws, pkg, o.conflictsDir); werr != nil {
+ if werr := writeConflicts(ctx, ws, pkg, o.conflictsDir, out); werr != nil {
return fmt.Errorf("%w (and writing the conflicts failed: %v)", err, werr)
}
fmt.Fprintf(out, "wrote the conflicts to %s: edit the files, then run graft land --resolved %s\n", o.conflictsDir, o.conflictsDir)
diff --git a/cmd/graft/conflicts.go b/cmd/graft/conflicts.go
index 332c2bb..d5bca6b 100644
--- a/cmd/graft/conflicts.go
+++ b/cmd/graft/conflicts.go
@@ -22,25 +22,33 @@ import (
// The conflicts directory of graft land --conflicts-dir DIR holds, for every conflicting path:
//
// DIR/files/<path> the file as the merge leaves it, with git's diff3 conflict markers
-// around each conflict (or the tip's side when the file is not text,
-// or a side is absent)
-// DIR/sides/<path>.base the three sides
-// DIR/sides/<path>.ours
-// DIR/sides/<path>.theirs
+// around each conflict (or the side there is when the file is not
+// text, or a side is absent or cannot be read)
+// DIR/sides/base/<path> the three sides; a side that is absent or cannot be read has no file
+// DIR/sides/ours/<path>
+// DIR/sides/theirs/<path>
// DIR/conflict.json the conflict package
//
-// The files to edit and the sides live under separate directories, so that no repository path,
-// whatever its name, can collide with a side or with the package. graft land --resolved DIR lands
-// the files of DIR/files as the resolution: a path whose file is present is written, one whose
-// file is absent is deleted.
+// Each directory mirrors the tree of the merge, so that no repository path, whatever its name, can
+// collide with a side, with another path's side, or with the package. graft land --resolved DIR
+// lands the files of DIR/files as the resolution: a path whose file is present is written, one
+// whose file is absent is deleted.
const (
conflictsFilesDir = "files"
conflictsSidesDir = "sides"
conflictsPackage = "conflict.json"
)
-// printConflict describes a conflict package: the reason the server gave, and each file with its
-// outcome. The paths and reasons come from the server and are escaped with displayText.
+// conflictSides are the sides of a conflicting file, in the order of the package.
+var conflictSides = []string{"base", "ours", "theirs"}
+
+// conflictsUnreadable is the content of the file to edit when no side of the file can be read: a
+// conflict that the marker rule of the server rejects until the agent writes the resolution.
+const conflictsUnreadable = "<<<<<<< ours (the branch tip): cannot be read, see conflict.json\n=======\n>>>>>>> theirs (the change): cannot be read, see conflict.json\n"
+
+// printConflict describes a conflict package: the reason the server gave, each file with its
+// outcome and what it lacks, and the merge's messages. The paths, reasons and messages come from
+// the server and are escaped with displayText.
func printConflict(out io.Writer, c *gitalypb.LandConflict) {
fmt.Fprintf(out, "the land did not resolve %d conflicting files (tip %s, commit %s)\n", len(c.GetFiles()), shortOID(c.GetTip()), shortOID(c.GetCommit()))
if c.GetReason() != "" {
@@ -53,44 +61,67 @@ func printConflict(out io.Writer, c *gitalypb.LandConflict) {
line += ": " + displayText(f.GetReason())
}
fmt.Fprintln(out, line)
+ for i, s := range []*gitalypb.LandConflictSide{f.GetBase(), f.GetOurs(), f.GetTheirs()} {
+ if s.GetUnavailable() != "" {
+ fmt.Fprintf(out, " %s side unavailable: %s\n", conflictSides[i], displayText(s.GetUnavailable()))
+ }
+ }
+ if f.GetHunksOmitted() != "" {
+ fmt.Fprintf(out, " hunks: %s\n", displayText(f.GetHunksOmitted()))
+ }
+ }
+ for _, m := range c.GetMessages() {
+ fmt.Fprintf(out, " merge: %s\n", displayText(m.GetMessage()))
}
}
-// conflictPath returns the file under sub of the conflicts directory for a conflicting path,
-// refusing a path that would leave it.
+// conflictPath returns the file under sub of the conflicts directory for a conflicting path. It
+// refuses a path that would leave the directory or that this system cannot hold as a file name
+// under it: an absolute or unclean path, a backslash or a colon (a separator or a drive or stream
+// on Windows), a NUL, and any path filepath.IsLocal rejects once in the system's form (such as a
+// reserved name like NUL or COM1 on Windows).
func conflictPath(dir, sub, p string) (string, error) {
- if p == "" || path.IsAbs(p) || path.Clean(p) != p || p == ".." || strings.HasPrefix(p, "../") {
- return "", fmt.Errorf("conflicting path %q cannot be written into the conflicts directory", p)
+ local := filepath.FromSlash(p)
+ if p == "" || path.IsAbs(p) || path.Clean(p) != p || strings.ContainsAny(p, "\\:\x00") || !filepath.IsLocal(local) {
+ return "", fmt.Errorf("conflicting path %q cannot be written into the conflicts directory on this system", p)
}
- return filepath.Join(dir, sub, filepath.FromSlash(p)), nil
+ return filepath.Join(dir, sub, local), nil
}
-// writeConflicts writes the conflicts directory of a conflict package (see the layout above).
-func writeConflicts(ctx context.Context, ws *workspace.Workspace, c *gitalypb.LandConflict, dir string) error {
- var oids []string
- for _, f := range c.GetFiles() {
- for _, s := range []*gitalypb.LandConflictSide{f.GetBase(), f.GetOurs(), f.GetTheirs()} {
- if s != nil {
- oids = append(oids, s.GetOid())
- }
+// writeConflicts writes the conflicts directory of a conflict package (see the layout above) into
+// dir, which must not hold one yet: the files of an earlier package, which the agent may be
+// editing, are never overwritten. A side that has no object ID in the package (unavailable) or that
+// the server cannot return is left out, and said so; it fails neither its file nor the directory.
+// Two paths that this file system takes for the same file (such as names that differ in case on a
+// case-insensitive one) are an error, since one would overwrite the other.
+func writeConflicts(ctx context.Context, ws *workspace.Workspace, c *gitalypb.LandConflict, dir string, out io.Writer) error {
+ for _, sub := range []string{conflictsFilesDir, conflictsSidesDir, conflictsPackage} {
+ if _, err := os.Lstat(filepath.Join(dir, sub)); err == nil {
+ return fmt.Errorf("%s already holds a conflicts directory (%s): land it with --resolved, or remove it", dir, sub)
+ } else if !errors.Is(err, fs.ErrNotExist) {
+ return err
}
}
- blobs, err := ws.GetObjects(ctx, oids)
- if err != nil {
- return fmt.Errorf("reading the sides of the conflict: %w", err)
- }
- side := func(s *gitalypb.LandConflictSide) ([]byte, error) {
- if s == nil {
- return nil, nil
+
+ blobs, missing := fetchSides(ctx, ws, c)
+ written := map[string]string{}
+ create := func(target, p string, data []byte) error {
+ if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil {
+ return fmt.Errorf("%s: %w", p, err)
}
- b, ok := blobs[s.GetOid()]
- if !ok {
- return nil, fmt.Errorf("side %s is missing from the server", s.GetOid())
+ f, err := os.OpenFile(target, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o644)
+ if errors.Is(err, fs.ErrExist) {
+ return fmt.Errorf("conflicting paths %q and %q are the same file on this file system (names that differ only in case or Unicode normalization): resolve this conflict on a case-sensitive file system", written[target], p)
}
- if b == nil {
- b = []byte{}
+ if err != nil {
+ return fmt.Errorf("%s: %w", p, err)
+ }
+ written[target] = p
+ if _, err := f.Write(data); err != nil {
+ _ = f.Close()
+ return fmt.Errorf("%s: %w", p, err)
}
- return b, nil
+ return f.Close()
}
for _, f := range c.GetFiles() {
@@ -99,25 +130,48 @@ func writeConflicts(ctx context.Context, ws *workspace.Workspace, c *gitalypb.La
if err != nil {
return err
}
- sideBase, err := conflictPath(dir, conflictsSidesDir, p)
- if err != nil {
- return err
- }
var contents [3][]byte
+ readable := true
for i, s := range []*gitalypb.LandConflictSide{f.GetBase(), f.GetOurs(), f.GetTheirs()} {
- if contents[i], err = side(s); err != nil {
- return fmt.Errorf("%s: %w", p, err)
+ if s == nil {
+ continue
}
- }
- for i, ext := range []string{"base", "ours", "theirs"} {
- if contents[i] == nil {
+ b, ok := blobs[s.GetOid()]
+ switch {
+ case s.GetOid() == "":
+ readable = false
+ continue
+ case !ok:
+ readable = false
+ fmt.Fprintf(out, " %s: the %s side %s cannot be read: %s\n", displayText(p), conflictSides[i], shortOID(s.GetOid()), displayText(missing[s.GetOid()]))
continue
}
- if err := writeFileAll(sideBase+"."+ext, contents[i]); err != nil {
+ if b == nil {
+ b = []byte{}
+ }
+ contents[i] = b
+ sideFile, err := conflictPath(dir, filepath.Join(conflictsSidesDir, conflictSides[i]), p)
+ if err != nil {
return err
}
+ if err := create(sideFile, p, b); err != nil {
+ return err
+ }
+ }
+ content := conflictFileContent(contents)
+ if !readable {
+ // Without every side there is no three-way merge: the file to edit is a side that
+ // can be read, or a conflict the agent must resolve.
+ switch {
+ case contents[1] != nil:
+ content = contents[1]
+ case contents[2] != nil:
+ content = contents[2]
+ default:
+ content = []byte(conflictsUnreadable)
+ }
}
- if err := writeFileAll(target, conflictFileContent(contents)); err != nil {
+ if err := create(target, p, content); err != nil {
return err
}
}
@@ -126,7 +180,46 @@ func writeConflicts(ctx context.Context, ws *workspace.Workspace, c *gitalypb.La
if err != nil {
return err
}
- return writeFileAll(filepath.Join(dir, conflictsPackage), append(raw, '\n'))
+ return create(filepath.Join(dir, conflictsPackage), conflictsPackage, append(raw, '\n'))
+}
+
+// fetchSides reads the sides of the package that have an object ID, all at once. When the server
+// cannot return them all, it reads them one by one, so that a side it cannot return costs only that
+// side: missing gives the error of each side that could not be read.
+func fetchSides(ctx context.Context, ws *workspace.Workspace, c *gitalypb.LandConflict) (map[string][]byte, map[string]string) {
+ var oids []string
+ seen := map[string]bool{}
+ for _, f := range c.GetFiles() {
+ for _, s := range []*gitalypb.LandConflictSide{f.GetBase(), f.GetOurs(), f.GetTheirs()} {
+ if oid := s.GetOid(); oid != "" && !seen[oid] {
+ seen[oid] = true
+ oids = append(oids, oid)
+ }
+ }
+ }
+ missing := map[string]string{}
+ blobs, err := ws.GetObjects(ctx, oids)
+ if err == nil {
+ for _, oid := range oids {
+ if _, ok := blobs[oid]; !ok {
+ missing[oid] = "the server did not return it"
+ }
+ }
+ return blobs, missing
+ }
+ blobs = map[string][]byte{}
+ for _, oid := range oids {
+ one, err := ws.GetObjects(ctx, []string{oid})
+ if b, ok := one[oid]; err == nil && ok {
+ blobs[oid] = b
+ continue
+ }
+ if err == nil {
+ err = errors.New("the server did not return it")
+ }
+ missing[oid] = err.Error()
+ }
+ return blobs, missing
}
// conflictFileContent is the file an agent edits: the merge with markers when both sides are text,
@@ -149,13 +242,6 @@ func isBinaryContent(b []byte) bool {
return bytes.IndexByte(b, 0) >= 0
}
-func writeFileAll(p string, data []byte) error {
- if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
- return err
- }
- return os.WriteFile(p, data, 0o644)
-}
-
// readResolution reads the resolution of a conflicts directory: the package's tip and commit, and
// for every conflicting path its file under DIR/files, or a deletion when the file is absent. The mode is the
// tip's side's, else the landed commit's.
diff --git a/cmd/graft/conflicts_server_test.go b/cmd/graft/conflicts_server_test.go
index ebdc0a5..eb3cf48 100644
--- a/cmd/graft/conflicts_server_test.go
+++ b/cmd/graft/conflicts_server_test.go
@@ -2,6 +2,7 @@ package main
import (
"encoding/json"
+ "fmt"
"os"
"path/filepath"
"testing"
@@ -44,7 +45,7 @@ func TestCLILandConflictsAndResolved(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "1\n<<<<<<< ours (the branch tip)\ntip\n||||||| base\nbase\n=======\nlocal\n>>>>>>> theirs (the change)\n3\n", string(marked))
for side, want := range map[string]string{"base": "1\nbase\n3\n", "ours": "1\ntip\n3\n", "theirs": "1\nlocal\n3\n"} {
- got, err := os.ReadFile(filepath.Join(conflicts, "sides", "x.txt."+side))
+ got, err := os.ReadFile(filepath.Join(conflicts, "sides", side, "x.txt"))
require.NoError(t, err)
require.Equal(t, want, string(got), side)
}
@@ -105,7 +106,7 @@ func TestCLILandConflictsDirectoryNamespacesAreDisjoint(t *testing.T) {
marked, err := os.ReadFile(filepath.Join(conflicts, "files", filepath.FromSlash(n)))
require.NoError(t, err, n)
require.Contains(t, string(marked), "local "+n, n)
- require.FileExists(t, filepath.Join(conflicts, "sides", filepath.FromSlash(n)+".theirs"), n)
+ require.FileExists(t, filepath.Join(conflicts, "sides", "theirs", filepath.FromSlash(n)), n)
require.NoError(t, os.WriteFile(filepath.Join(conflicts, "files", filepath.FromSlash(n)), []byte("resolved "+n+"\n"), 0o644))
}
require.FileExists(t, filepath.Join(conflicts, "conflict.json"))
@@ -129,3 +130,60 @@ func TestCLILandConflictFlagsAreChecked(t *testing.T) {
require.Equal(t, exitUsage, code)
require.Contains(t, stderr, "--resolved takes neither")
}
+
+// TestCLILandConflictsWithAnUnavailableSide: a side that the merge wrote for the conflict (the
+// content merge of a rename) is not kept by the server, so the package gives no object ID for it.
+// The conflicts directory is still written: that side is said to be unavailable and left out, the
+// file to edit is the side there is, and the resolution lands.
+func TestCLILandConflictsWithAnUnavailableSide(t *testing.T) {
+ lines := func(replace map[int]string) string {
+ out := ""
+ for i := 1; i <= 20; i++ {
+ if r, ok := replace[i]; ok {
+ out += r + "\n"
+ } else {
+ out += fmt.Sprintf("%d\n", i)
+ }
+ }
+ return out
+ }
+ env := startServer(t)
+ base := env.seedMain(t, map[string]string{"a.txt": lines(nil)})
+
+ dir := filepath.Join(t.TempDir(), "ws")
+ code, _, stderr := runCLI(t, "clone", "-storage", env.storage, env.addr, env.relPath, dir)
+ require.Equal(t, exitOK, code, stderr)
+
+ // Main renames a.txt to c.txt and changes line 19; the local change edits line 2 of a.txt and
+ // adds a c.txt of its own.
+ gittest.WriteCommit(t, env.cfg, env.repoPath,
+ gittest.WithTree(env.writeTree(t, map[string]string{"c.txt": lines(map[int]string{19: "nineteen-ours"})})),
+ gittest.WithParents(base), gittest.WithBranch("main"))
+ require.NoError(t, os.WriteFile(filepath.Join(dir, "a.txt"), []byte(lines(map[int]string{2: "two-theirs"})), 0o644))
+ require.NoError(t, os.WriteFile(filepath.Join(dir, "c.txt"), []byte("added by theirs\n"), 0o644))
+ code, _, stderr = runCLI(t, "commit", "-C", dir, "-author", "Dev <[email protected]>", "-m", "local")
+ require.Equal(t, exitOK, code, stderr)
+
+ conflicts := filepath.Join(t.TempDir(), "conflicts")
+ code, stdout, _ := runCLI(t, "land", "-C", dir, "-author", "Dev <[email protected]>", "-strategy", "merge", "-resolve", "-conflicts-dir", conflicts)
+ require.Equal(t, exitError, code, stdout)
+ require.Contains(t, stdout, "c.txt: not_attempted")
+ require.Contains(t, stdout, "ours side unavailable")
+ require.Contains(t, stdout, "wrote the conflicts to "+conflicts)
+
+ require.NoFileExists(t, filepath.Join(conflicts, "sides", "ours", "c.txt"))
+ theirs, err := os.ReadFile(filepath.Join(conflicts, "sides", "theirs", "c.txt"))
+ require.NoError(t, err)
+ require.Equal(t, "added by theirs\n", string(theirs))
+ edit, err := os.ReadFile(filepath.Join(conflicts, "files", "c.txt"))
+ require.NoError(t, err)
+ require.Equal(t, "added by theirs\n", string(edit), "without every side the file to edit is the side there is")
+
+ resolved := lines(map[int]string{2: "two-theirs", 19: "nineteen-ours"}) + "added by theirs\n"
+ require.NoError(t, os.WriteFile(filepath.Join(conflicts, "files", "c.txt"), []byte(resolved), 0o644))
+ code, _, stderr = runCLI(t, "land", "-C", dir, "-author", "Dev <[email protected]>", "-resolved", conflicts)
+ require.Equal(t, exitOK, code, stderr)
+ code, stdout, _ = runCLI(t, "cat", "-C", dir, "main:c.txt")
+ require.Equal(t, exitOK, code)
+ require.Equal(t, resolved, stdout)
+}
diff --git a/cmd/graft/conflicts_test.go b/cmd/graft/conflicts_test.go
new file mode 100644
index 0000000..303f59c
--- /dev/null
+++ b/cmd/graft/conflicts_test.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ "context"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/feder-cr/git-ai/proto/go/gitalypb"
+)
+
+func TestConflictPath(t *testing.T) {
+ t.Parallel()
+
+ dir := t.TempDir()
+ got, err := conflictPath(dir, conflictsFilesDir, "a/b.txt")
+ require.NoError(t, err)
+ require.Equal(t, filepath.Join(dir, "files", "a", "b.txt"), got)
+
+ for _, p := range []string{
+ "", "/etc/passwd", "../x", "a/../../x", "a//b", "a/./b", "a/",
+ // A separator, a drive or a stream on Windows, whatever the system the CLI runs on.
+ `a\b`, `..\x`, "c:x", "a:stream", "a\x00b",
+ } {
+ _, err := conflictPath(dir, conflictsFilesDir, p)
+ require.Error(t, err, "%q", p)
+ }
+}
+
+// TestWriteConflictsRefusesAnExistingDirectory: the files of an earlier package, which the agent
+// may be editing, are never overwritten.
+func TestWriteConflictsRefusesAnExistingDirectory(t *testing.T) {
+ t.Parallel()
+
+ dir := t.TempDir()
+ require.NoError(t, os.MkdirAll(filepath.Join(dir, "files"), 0o755))
+ err := writeConflicts(context.Background(), nil, &gitalypb.LandConflict{}, dir, nil)
+ require.ErrorContains(t, err, "already holds a conflicts directory")
+}
diff --git a/doc/graft/PLAN10.md b/doc/graft/PLAN10.md
index 765b873..5bb3218 100644
--- a/doc/graft/PLAN10.md
+++ b/doc/graft/PLAN10.md
@@ -122,7 +122,8 @@ error, whose size is limited.
conflict markers), resolved but not landed because another file was not, or not
attempted because the whole request was refused (too many files, actor not
allowed, resolution disabled), with the request-level reason. Reasons are cut to
- 512 bytes; the detail is bounded by `max_files`.
+ 512 bytes. The package lists every conflicting file, within its own bounds (see
+ "Review of WP5/WP6" in section 12).
* The agent reads the sides with `GetBlobs`, which its read access allows.
* **Re-land**: `UserLandRequest.resolution` (`LandResolution`) carries the tip and
the commit the resolution was made against and, per file, `write` (mode, content)
@@ -314,7 +315,7 @@ message LandConflict {
bytes commit_message = 5;
// messages_truncated is set when a message was cut.
bool messages_truncated = 6;
- // files are the conflicting files, at most max_files of them.
+ // files are all the conflicting files (see "Review of WP5/WP6" in section 12).
repeated LandConflictFile files = 7;
// reason is set when the server did not try to resolve the request at all, for
// example because it has too many files or the actor may not resolve; it is cut to
@@ -536,3 +537,34 @@ way.
resolver resolved in a failed request are wasted work for the agent. The package could
offer the resolver's resolved content to the agent (for example as blobs written to the
repository, referenced by OID), so that the agent re-lands with it where it agrees.
+* **Review of WP5/WP6** (independent review of f707b5b and ad68d37, PM: fix all). What
+ changed from the text above:
+ * A refusal is never written. Only an accepted answer is, and a refusal whose outcomes
+ mark every file resolved contradicts itself, so it is malformed (every file failed).
+ * Every `Graft-*` trailer is written by one function, which refuses any value that is
+ not one line of printable UTF-8. Such a path is never sent to a resolver, and the
+ re-land refuses it (`FailedPrecondition`).
+ * A side's blob OID is in the package only when the blob is in the tree of the merge
+ base, the tip or the landed commit. A blob that merge-tree wrote for the conflict (the
+ content merge of a rename) lives in the request's quarantine, which a failed land
+ discards. Such a side gets `unavailable` with the reason; the CLI leaves it out
+ without failing the other sides or files.
+ * `actors` gates only the requests for an AI resolution. An agent's re-land is allowed
+ for every actor that may land, and its `check` runs whatever the actor and covers all
+ its files. `max_files` bounds the AI request only. The package lists every
+ conflicting file, with bounds of its own: 1000 files (a refusal above), 1000 merge
+ messages, 4 MiB encoded, 256 hunks per file, 64 MiB of sides read and 64 Mi cells of
+ diff work for the hunks; `hunks_omitted` says why a file lacks hunks. The package is
+ built only when the land returns it.
+ * A merge that is unclean without a conflicting file (a directory rename split) gets a
+ package that describes it by git's messages (`messages`), which every package carries.
+ * Minors: a re-land with `STRATEGY_FF_ONLY` is `InvalidArgument`; a written mode must
+ be one of the modes of the sides; a symbolic link named like `.gitmodules`,
+ `.gitattributes`, `.gitignore` or `.mailmap` (in the ways HFS+ and NTFS fold names
+ too) is refused; a symbolic link answer has syntax `none`; the
+ `syntax_unchecked` metric counts once, on a successful land; merge3 writes CRLF
+ markers where git does; the CLI layout of the sides is `DIR/sides/<side>/<path>`
+ (`<path>.base` could collide with a directory named `<path>.base`), the CLI refuses
+ paths it cannot write on its system and paths the file system folds together, and
+ never overwrites a conflicts directory; the memory backend refuses a resolution for
+ another commit.
diff --git a/doc/graft/RESOLVE.md b/doc/graft/RESOLVE.md
index 1d48abc..c9e48ea 100644
--- a/doc/graft/RESOLVE.md
+++ b/doc/graft/RESOLVE.md
@@ -35,6 +35,9 @@ actors = ["builder", "planner"]
on stdin. `url` receives an HTTP POST with a bearer token read from
`token_file`.
- `timeout`, `max_files`, `max_file_bytes`: bounds for each resolver call.
+ `max_files` bounds a request for an AI resolution only: the conflict package
+ lists every conflicting file, and the check of an agent's resolution covers
+ all its files.
- `paths_allow`, `paths_deny`: glob lists with the same semantics as policy
refs (`**` as a suffix matches any depth). A conflict in a denied path, or
in a path that is not allowed, is not sent to the resolver. Apart from the
@@ -42,9 +45,12 @@ actors = ["builder", "planner"]
`*.lock` denies `go.lock` but not `sub/go.lock`, and `*.env` does not deny
`a/.env`. To deny a name at several depths, list one glob per depth
(`*.env`, `*/.env`, `*/*/.env`) or deny whole directories (`secrets/**`).
-- `actors`: globs of the actors that may request resolution. Other actors get
- the normal `merge_conflict` error. An empty list allows every caller that
- may land. The actor is the authenticated identity of the caller, which only
+- `actors`: globs of the actors that may request an AI resolution. Other
+ actors get the normal `merge_conflict` error, with the conflict package. An
+ empty list allows every caller that may land. `actors` gates only the
+ requests for an AI resolution (`resolve_conflicts`): an agent's re-land with
+ its own resolution is allowed for every actor that may land, and the
+ resolver's `check` runs on it whatever the actor. The actor is the authenticated identity of the caller, which only
agent authentication sets (see [AGENT-SECURITY](AGENT-SECURITY.md)):
- with `[[graft.agent]]` configured, the agent name of a caller with an
agent token, or `shared` for a caller with the shared `auth.token` (for
@@ -60,7 +66,8 @@ A client asks for resolution per call:
- SDK: `LandOptions.ResolveConflicts`, and `LandResult` reports the
resolved paths and the resolver name. On a conflict the server did not
resolve, `sdk.LandConflict(err)` returns the conflict package,
- `Repo.ConflictSides` reads the sides, and `LandOptions.Resolution`
+ `Repo.ConflictSides` reads the sides (a side that cannot be read is nil,
+ with its reason in `Unreadable`), and `LandOptions.Resolution`
(start from `sdk.ResolutionFor`) lands the agent's resolution. `Land`
refuses a resolution whose request exceeds `sdk.MaxLandRequestBytes`
(4 MiB) before sending it.
@@ -68,11 +75,21 @@ A client asks for resolution per call:
`graft land --resolve` prints the package when the land fails, and with
`--conflicts-dir DIR` writes it: `DIR/files/<path>` is the merge with git's
diff3 markers (the clean changes of both sides applied), the sides are in
- `DIR/sides/<path>.base|.ours|.theirs`, the package in `DIR/conflict.json`.
- The files and the sides live in separate directories, so no repository
- path can collide with a side or the package. Edit the files under
- `DIR/files`, then `graft land --resolved DIR` lands them: a present file is
- written (with the tip side's mode), an absent one is deleted.
+ `DIR/sides/base/<path>`, `DIR/sides/ours/<path>` and
+ `DIR/sides/theirs/<path>`, the package in `DIR/conflict.json`. Each
+ directory mirrors the tree of the merge, so no repository path can collide
+ with a side, another path's side or the package. A side the package gives no
+ object ID (see `unavailable` below), or that the server cannot return, is
+ left out and reported; it fails neither its file nor the directory. The
+ file to edit is then the side there is, or, when no side can be read, a
+ conflict that the marker rule refuses until it is resolved. `DIR` must not
+ hold a conflicts directory yet: one being edited is never overwritten. A
+ path that cannot be a file under `DIR` on this system (a backslash, a
+ colon, a name the system reserves) is an error, and so are two paths that
+ the file system takes for one file (names that differ only in case on a
+ case-insensitive file system). Edit the files under `DIR/files`, then
+ `graft land --resolved DIR` lands them: a present file is written (with the
+ tip side's mode), an absent one is deleted.
- RPC: `UserLandRequest.resolve_conflicts` (field 10). The response carries
`resolved_paths` (field 7) and `resolver` (field 8). The re-land is
`UserLandRequest.resolution` (field 11).
@@ -84,7 +101,9 @@ A client asks for resolution per call:
ours and theirs sides (merge base of the tip and the landed commit; blobs
and modes read through the object reader). The whole request is refused
when resolution is not enabled, the actor may not resolve, there are more
- than `max_files` files, or the history is criss-cross.
+ than `max_files` files, the history is criss-cross, or the merge is unclean
+ without a conflicting file (a directory rename split, say), which the
+ package then describes by the merge's messages.
3. It decides for each file whether it may be sent (see
[What is never sent](#what-is-never-sent)), sends the others to the
resolver in one request (protocol below), and validates the answer (see
@@ -210,7 +229,14 @@ The server accepts an answer only if all of these hold:
- `version` is 1.
- `resolver` is 1 to 128 bytes of printable, single-line UTF-8.
- Every conflicted path is answered exactly once, and no other path appears.
-- Modes are one of `100644`, `100755`, `120000`.
+- Modes are one of `100644`, `100755`, `120000`, and a written mode is one of
+ the modes of the file's sides: a merge does not turn a file into a symbolic
+ link or an executable that no side asked for. A file that breaks this is
+ `REJECTED`, and the land fails with the package.
+- No symbolic link is named `.gitmodules`, `.gitattributes`, `.gitignore` or
+ `.mailmap` in any directory, as git fsck and checkout require, nor any name
+ a file system takes for one of them (other case, the code points HFS+
+ ignores, NTFS trailing dots and spaces, streams and 8.3 short names).
- Every content is at most `max_file_bytes` after decoding.
- Text files contain no conflict marker lines. A marker line is one that
starts with `<<<<<<< ` or `>>>>>>> `, or one that is `=======` followed by
@@ -322,14 +348,29 @@ the error unchanged. The package holds:
- `tip`, `commit` and `merge_base` (empty when there is none);
- both commit messages, cut to 4 KiB each, with `messages_truncated`;
- `reason`, when the server did not attempt the request at all;
-- per file (at most `max_files`): the path, the kind, each side's blob OID and
- mode, the conflicting hunks, the outcome and its reason (cut to 512 bytes).
+- every conflicting file: the path, the kind, each side's mode and blob OID,
+ the conflicting hunks, the outcome and its reason (cut to 512 bytes);
+- `messages`: git's messages about the merge (the paths, the type such as
+ `CONFLICT (rename/delete)`, the text), which also describe a conflict that
+ has no conflicting file.
+
+A side has a blob OID only when the blob is in the tree of the merge base,
+the tip or the landed commit, which the repository keeps. A side that the
+merge wrote for the conflict alone (such as the content merge of a renamed
+file) is discarded with the failed land, so it has no OID and `unavailable`
+says why; its hunks are still given.
Each hunk gives line ranges of each side, 1-based and half-open (`[start,
end)`), each counting the lines of the side it names. An empty range is an
-insertion point before line `start`. A file whose diff is too large to
-compute (more than about 2800 changed lines on a side) has no hunks. The
-outcomes are:
+insertion point before line `start`. When a content or add/add conflict has
+no hunks or only some, `hunks_omitted` says why: a side over
+`max_file_bytes`, a binary side, a diff over the cost bound of one file (more
+than about 2800 changed lines on a side), more than 256 conflicting regions
+(the first 256 are listed), or a package bound below. The package is bounded:
+at most 1000 files (a merge with more gets a package without files, whose
+`reason` says it cannot be resolved through a land), 1000 messages, 64 MiB of
+sides read and 64 Mi cells of diff work for its hunks, and 4 MiB encoded
+(over it the hunks are left out, and then the files). The outcomes are:
| outcome | meaning |
|---|---|
@@ -344,17 +385,25 @@ lands again with `UserLandRequest.resolution` (field 11): the `tip` and
`commit` of the package and, for every conflicting path, `write` (mode and
content) or `delete`. The server accepts it only when:
-- `resolution.commit` equals `commit_id` (otherwise `InvalidArgument`);
+- `resolution.commit` equals `commit_id`, and the strategy is not
+ `STRATEGY_FF_ONLY`, since the resolution lands as a merge commit (otherwise
+ `InvalidArgument`);
- `resolution.tip` is the branch's current tip (otherwise the land fails
with a fresh package for the new tip);
- it resolves exactly the conflicting paths, each once;
- every file passes the acceptance rules of an answer (modes, size, conflict
- markers);
+ markers, no symbolic link named like a file git reads from the tree), and
+ writes a mode one of the conflict's sides has;
+- every conflicting path, and the actor, can be written in a commit trailer:
+ one line of printable UTF-8 (otherwise `FailedPrecondition`; such a path is
+ never sent to a resolver either, so its conflict cannot be resolved through
+ a land);
- when a resolver is configured, the files that may be sent to it pass its
`check`: the syntax check and the configured checks, as an `llm` answer.
A check that cannot run fails the land, with the reason in the package.
A file with a `syntax: unchecked` verdict lands, and is counted in
- `graft_land_resolution_syntax_unchecked_total` and the server log.
+ `graft_land_resolution_syntax_unchecked_total`, once, when the land
+ succeeds, and in the server log.
The merge commit has parents `[tip, commit]` and the trailers
`Graft-Resolved-By: agent/<actor>` (`agent` without an identity) and, when the
@@ -711,7 +760,9 @@ in blank lines only, and the accepted results that got no syntax verdict.
| verification run | 5 min, output kept 4 KiB | `verify.timeout` |
| request body read by `graft-resolve` | 128 MiB (`protocol.DefaultMaxRequestBytes`) | `--max-request-bytes` |
| land request with an agent's resolution | 4 MiB, the gRPC message limit | server; the SDK refuses larger ones |
-| package: files, reasons, messages | `max_files`; 512 bytes; 4 KiB each | server |
+| package: files, merge messages, encoded size | 1000; 1000; 4 MiB | server |
+| package: reasons and merge messages; commit messages | 512 bytes; 4 KiB each | server |
+| package hunks: per file; sides read; diff work | 256; 64 MiB; 64 Mi cells | server |
| land attempts | 20 | `max_attempts` of the land |
A resolver that hangs is killed at the timeout. Its stderr is kept in the
diff --git a/internal/gitaly/service/operations/land.go b/internal/gitaly/service/operations/land.go
index 1641f40..8342560 100644
--- a/internal/gitaly/service/operations/land.go
+++ b/internal/gitaly/service/operations/land.go
@@ -211,6 +211,7 @@ func (s *Server) landAttempt(ctx context.Context, in *gitalypb.UserLandRequest,
if step.resolution != nil {
resp.ResolvedPaths = step.resolution.resolvedPaths
resp.Resolver = step.resolution.resolver
+ step.resolution.landed()
}
return resp, nil
}
@@ -462,6 +463,12 @@ func validateUserLandRequest(ctx context.Context, locator storage.Locator, in *g
return fmt.Errorf("unknown strategy: %d", in.GetStrategy())
}
+ // A resolution lands as a merge commit of the tip and the change, which fast-forward only
+ // forbids: the request contradicts itself.
+ if in.GetResolution() != nil && in.GetStrategy() == gitalypb.UserLandRequest_STRATEGY_FF_ONLY {
+ return errors.New("a resolution lands as a merge commit, which STRATEGY_FF_ONLY does not allow")
+ }
+
if in.GetMaxAttempts() < 0 {
return errors.New("negative max attempts")
}
diff --git a/internal/gitaly/service/operations/land_attempt.go b/internal/gitaly/service/operations/land_attempt.go
index 2ecdc01..7009a5b 100644
--- a/internal/gitaly/service/operations/land_attempt.go
+++ b/internal/gitaly/service/operations/land_attempt.go
@@ -204,11 +204,13 @@ func (a *landingAttempt) decide(ctx context.Context, tip git.ObjectID, req *land
if err != nil {
var unresolved *landUnresolvedError
if errors.As(err, &unresolved) {
- paths := make([][]byte, 0, len(unresolved.pkg.GetFiles()))
- for _, f := range unresolved.pkg.GetFiles() {
- paths = append(paths, f.GetPath())
+ // The paths of UserLandError are bounded like the files of the package.
+ files := unresolved.listing.files[:min(len(unresolved.listing.files), landMaxPackageFiles)]
+ paths := make([][]byte, 0, len(files))
+ for _, f := range files {
+ paths = append(paths, []byte(f.conflict.path))
}
- return landStep{}, landWithPackage(landMergeConflictError(tip, commitID, paths, err), err)
+ return landStep{}, landWithPackage(ctx, landMergeConflictError(tip, commitID, paths, err), err)
}
return landStep{}, err
}
@@ -229,7 +231,7 @@ func (a *landingAttempt) decide(ctx context.Context, tip git.ObjectID, req *land
if resolveErr != nil {
a.server.logger.WithError(resolveErr).WithField("branch", string(in.GetBranch())).
Info("graft: conflict resolution of land failed")
- return landStep{}, landWithPackage(err, resolveErr)
+ return landStep{}, landWithPackage(ctx, err, resolveErr)
}
resolution = &res
diff --git a/internal/gitaly/service/operations/land_batch_server.go b/internal/gitaly/service/operations/land_batch_server.go
index 7435585..688acc8 100644
--- a/internal/gitaly/service/operations/land_batch_server.go
+++ b/internal/gitaly/service/operations/land_batch_server.go
@@ -207,6 +207,7 @@ func landBatchResult(outcome landBatchOutcome) landlane.Result[*gitalypb.UserLan
if outcome.Resolution != nil {
resp.ResolvedPaths = outcome.Resolution.resolvedPaths
resp.Resolver = outcome.Resolution.resolver
+ outcome.Resolution.landed()
}
return landlane.Result[*gitalypb.UserLandResponse]{Value: resp}
diff --git a/internal/gitaly/service/operations/land_batch_test.go b/internal/gitaly/service/operations/land_batch_test.go
index df1542a..a1b96a5 100644
--- a/internal/gitaly/service/operations/land_batch_test.go
+++ b/internal/gitaly/service/operations/land_batch_test.go
@@ -16,6 +16,7 @@ import (
"github.com/feder-cr/git-ai/internal/gitaly/service"
"github.com/feder-cr/git-ai/internal/graft/changelog"
"github.com/feder-cr/git-ai/internal/graft/landlane"
+ "github.com/feder-cr/git-ai/internal/graft/resolver"
"github.com/feder-cr/git-ai/internal/structerr"
"github.com/feder-cr/git-ai/internal/testhelper"
"github.com/feder-cr/git-ai/internal/testhelper/testcfg"
@@ -803,6 +804,75 @@ func testLandBatchResolveConflictsInsideBatch(t *testing.T, ctx context.Context)
require.Equal(t, "merged-a\n", string(gittest.Exec(t, cfg, "-C", repoPath, "show", "refs/heads/"+git.DefaultBranch+":a")))
}
+func TestLandBatch_refusalNeverWrites(t *testing.T) {
+ t.Parallel()
+
+ runLandBatchTest(t, testLandBatchRefusalNeverWrites)
+}
+
+// testLandBatchRefusalNeverWrites: a resolver that refuses but marks every file resolved (a
+// self-contradicting refusal) leads to no write: the request fails with the merge conflict and its
+// package, and the other member of the batch lands.
+func testLandBatchRefusalNeverWrites(t *testing.T, ctx context.Context) {
+ t.Parallel()
+
+ dir, argv := resolverScript(t, `cat "$DIR/answer.json"; exit 1`)
+ writeRawAnswer(t, dir, resolver.ErrorResponse{
+ Error: "refused",
+ Files: []resolver.FileOutcome{{Path: "a", Outcome: resolver.OutcomeResolved}, {Path: "b", Outcome: resolver.OutcomeResolved}},
+ })
+
+ graft := batchingGraft()
+ graft.Land.Resolver = enabledResolver(argv)
+ ctx, cfg, client := setupLandBatchService(t, ctx, graft)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg)
+
+ entries := func(a, b string) []gittest.TreeEntry {
+ return []gittest.TreeEntry{
+ {Mode: "100644", Path: "a", Content: a},
+ {Mode: "100644", Path: "b", Content: b},
+ }
+ }
+ base := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch(git.DefaultBranch), gittest.WithTreeEntries(entries("base", "base")...))
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(base), gittest.WithBranch(git.DefaultBranch), gittest.WithTreeEntries(entries("ours", "ours")...))
+ conflicting := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(base), gittest.WithTreeEntries(entries("theirs", "theirs")...))
+ independent := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(base),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "base"},
+ gittest.TreeEntry{Mode: "100644", Path: "b", Content: "base"},
+ gittest.TreeEntry{Mode: "100644", Path: "c", Content: "c"},
+ ),
+ )
+
+ var (
+ wg sync.WaitGroup
+ refusedErr error
+ independentResp *gitalypb.UserLandResponse
+ independentErr error
+ )
+ wg.Add(2)
+ go func() {
+ defer wg.Done()
+ req := landRequest(repoProto, git.DefaultBranch, conflicting)
+ req.ResolveConflicts = true
+ _, refusedErr = client.UserLand(ctx, req)
+ }()
+ go func() {
+ defer wg.Done()
+ independentResp, independentErr = client.UserLand(ctx, landRequest(repoProto, git.DefaultBranch, independent))
+ }()
+ wg.Wait()
+
+ requireMergeConflict(t, refusedErr)
+ pkg := landConflictDetail(refusedErr)
+ require.NotNil(t, pkg)
+ for _, f := range pkg.GetFiles() {
+ require.Equal(t, gitalypb.LandConflictFile_OUTCOME_FAILED, f.GetOutcome(), "a self-contradicting refusal is not trusted")
+ }
+ require.NoError(t, independentErr, "the other member of the batch is released")
+ require.Equal(t, "c", string(gittest.Exec(t, cfg, "-C", repoPath, "show", independentResp.GetLandedCommitId()+":c")))
+}
+
func TestLandBatch_externalWriterMovesBranch(t *testing.T) {
t.Parallel()
diff --git a/internal/gitaly/service/operations/land_hunks.go b/internal/gitaly/service/operations/land_hunks.go
index 894faf9..502d0fa 100644
--- a/internal/gitaly/service/operations/land_hunks.go
+++ b/internal/gitaly/service/operations/land_hunks.go
@@ -7,12 +7,12 @@ import (
// landConflictHunks returns the conflicting regions of a three-way merge of base, ours and theirs
// (merge3) as the hunks of the conflict package: line ranges of each side, 1-based and half-open,
-// each counting the lines of its own side. It returns nil when a diff exceeds merge3.MaxCells; the
+// each counting the lines of its own side. It returns false when a diff exceeds merge3.MaxCells; the
// agent still has the sides.
-func landConflictHunks(base, ours, theirs []byte) []*gitalypb.LandConflictHunk {
+func landConflictHunks(base, ours, theirs []byte) ([]*gitalypb.LandConflictHunk, bool) {
result, ok := merge3.Merge(base, ours, theirs)
if !ok {
- return nil
+ return nil, false
}
var hunks []*gitalypb.LandConflictHunk
for _, h := range result.Hunks() {
@@ -22,7 +22,7 @@ func landConflictHunks(base, ours, theirs []byte) []*gitalypb.LandConflictHunk {
Theirs: landRange(h.Theirs),
})
}
- return hunks
+ return hunks, true
}
// landRange returns the 1-based half-open range of the 0-based range r.
diff --git a/internal/gitaly/service/operations/land_package.go b/internal/gitaly/service/operations/land_package.go
index 03c9dba..5c011a8 100644
--- a/internal/gitaly/service/operations/land_package.go
+++ b/internal/gitaly/service/operations/land_package.go
@@ -8,9 +8,12 @@ import (
"strings"
"unicode/utf8"
+ "google.golang.org/protobuf/proto"
+
"github.com/feder-cr/git-ai/internal/git"
"github.com/feder-cr/git-ai/internal/git/gitcmd"
"github.com/feder-cr/git-ai/internal/git/localrepo"
+ "github.com/feder-cr/git-ai/internal/graft/merge3"
"github.com/feder-cr/git-ai/internal/graft/resolver"
"github.com/feder-cr/git-ai/internal/structerr"
"github.com/feder-cr/git-ai/proto/go/gitalypb"
@@ -23,14 +26,39 @@ import (
const (
// landPackageMessageBytes bounds each commit message of the package.
landPackageMessageBytes = 4 << 10
- // landPackageReasonBytes bounds every reason of the package.
+ // landPackageReasonBytes bounds every reason and merge message of the package.
landPackageReasonBytes = 512
+ // landMaxPackageFiles bounds the files of a package. A merge with more conflicting files gets
+ // a package without files whose reason says so: it cannot be resolved through a land.
+ landMaxPackageFiles = 1000
+ // landMaxPackageMessages bounds the merge messages of a package.
+ landMaxPackageMessages = 1000
+ // landMaxPackageBytes bounds the encoded package, which travels as a gRPC error detail. A
+ // package over it loses its hunks; one still over it loses its files, and its reason says so.
+ landMaxPackageBytes = 4 << 20
+ // landMaxHunksPerFile bounds the hunks of one file.
+ landMaxHunksPerFile = 256
+ // landMaxPackageReadBytes bounds the bytes of the sides that a package reads for its hunks,
+ // beyond those the resolver's classification read already.
+ landMaxPackageReadBytes = 64 << 20
+ // landMaxPackageCells bounds the line-diff work of the hunks of a package (merge3.Cost).
+ landMaxPackageCells = 64 << 20
+)
+
+// Reasons of hunks_omitted and of an unavailable side.
+const (
+ landHunksTooLarge = "a side is larger than max_file_bytes, so no diff is computed"
+ landHunksBinary = "a side is binary, which has no line hunks"
+ landHunksDiffCost = "the diff of the sides is over the cost bound of one file"
+ landHunksBudget = "the package's bound on the sides it reads and diffs is used up"
+ landHunksPackage = "the package would be over 4 MiB with its hunks"
+ landSideUnavailable = "the merge wrote this blob for the conflict (such as the content merge of a rename), and the repository does not keep it after the land fails"
)
// Reasons of the files the server does not send to the resolver, besides the content rules of
// resolver.SendRules.
const (
- landNotSentTrailerUnsafe = "the path holds a line break or a NUL byte, which a commit trailer cannot carry"
+ landNotSentTrailerUnsafe = "the path holds a line break or another non-printable character, which a commit trailer cannot carry"
landNotSentInvalidUTF8 = "the path is not valid UTF-8, which the resolver protocol cannot carry"
landNotSentDenied = "the path may not be sent to the resolver (paths_allow, paths_deny)"
landNotSentNotAFile = "a side is not a file (a submodule or a directory)"
@@ -50,6 +78,9 @@ type landFileState struct {
reason string
// syntaxUnchecked is set when a check accepted the file without a syntax verdict.
syntaxUnchecked bool
+ // hunks are the file's hunks in the package, and hunksOmitted why they are absent or cut.
+ hunks []*gitalypb.LandConflictHunk
+ hunksOmitted string
}
// sent reports whether the file is sent to the resolver.
@@ -76,11 +107,14 @@ func (f *landFileState) notSent(reason string) {
f.reason = reason
}
-// landUnresolvedError is a land whose conflicts the server did not resolve. It carries the conflict
-// package, which the caller attaches to the merge conflict error.
+// landUnresolvedError is a land whose conflicts the server did not resolve. It carries what the
+// conflict package is built from; the package itself, which reads sides for its hunks, is built
+// only when the caller attaches it to the merge conflict error (landWithPackage).
type landUnresolvedError struct {
- pkg *gitalypb.LandConflict
- cause string
+ listing landListing
+ // reason is the package's reason: set when the server did not try to resolve at all.
+ reason string
+ cause string
// err is the error of the resolver or of the check, when one caused the outcome, so that
// errors.Is and errors.As still see it.
err error
@@ -97,14 +131,19 @@ func (e *landUnresolvedError) Unwrap() error {
// landWithPackage adds the conflict package of resolveErr, when it carries one, to the merge
// conflict error of the land as a second detail, after UserLandError. Clients that know only
-// UserLandError see the error unchanged.
-func landWithPackage(mergeConflict, resolveErr error) error {
+// UserLandError see the error unchanged. A package that cannot be built (a side that cannot be
+// read) is an internal error: the merge conflict alone would hide it.
+func landWithPackage(ctx context.Context, mergeConflict, resolveErr error) error {
var unresolved *landUnresolvedError
var se structerr.Error
if !errors.As(resolveErr, &unresolved) || !errors.As(mergeConflict, &se) {
return mergeConflict
}
- return se.WithDetail(unresolved.pkg)
+ pkg, err := unresolved.listing.conflictPackage(ctx, unresolved.reason)
+ if err != nil {
+ return structerr.NewInternal("building the conflict package: %w", err)
+ }
+ return se.WithDetail(pkg)
}
// landKindOf classifies a conflicting file from the presence of its sides.
@@ -135,47 +174,212 @@ func landKindProto(kind string) gitalypb.LandConflictFile_Kind {
return gitalypb.LandConflictFile_KIND_UNSPECIFIED
}
-// landPackage returns the conflict package of the files, with reason set when the request was not
-// attempted at all. At most maxFiles files are listed.
-func landPackage(tip, commitID, base git.ObjectID, tipMessage, commitMessage string, files []*landFileState, maxFiles int, reason string) *gitalypb.LandConflict {
- tm, tipCut := landCut([]byte(tipMessage), landPackageMessageBytes)
- cm, commitCut := landCut([]byte(commitMessage), landPackageMessageBytes)
+// conflictPackage returns the conflict package of the listing: every conflicting file with its
+// sides, hunks and outcome, and the merge's messages, with reason set when the request was not
+// attempted at all. It reads the sides the hunks need (prepareHunks) and looks up whether each
+// side's blob is kept (sideKept). Its bounds: landMaxPackageFiles files, landMaxPackageMessages
+// messages, landMaxPackageBytes encoded; past them the package says what it left out.
+func (l landListing) conflictPackage(ctx context.Context, reason string) (*gitalypb.LandConflict, error) {
+ tm, tipCut := landCut([]byte(l.tipMessage), landPackageMessageBytes)
+ cm, commitCut := landCut([]byte(l.commitMessage), landPackageMessageBytes)
pkg := &gitalypb.LandConflict{
- Tip: tip.String(),
- Commit: commitID.String(),
- MergeBase: base.String(),
+ Tip: l.tip.String(),
+ Commit: l.commitID.String(),
+ MergeBase: l.base.String(),
TipMessage: tm,
CommitMessage: cm,
MessagesTruncated: tipCut || commitCut,
Reason: landCutString(reason, landPackageReasonBytes),
}
- for i, f := range files {
- if i == maxFiles {
+ for i, m := range l.messages {
+ if i == landMaxPackageMessages {
break
}
+ pm := &gitalypb.LandConflictMessage{Type: landCutString(m.kind, landPackageReasonBytes), Message: landCutString(m.message, landPackageReasonBytes)}
+ for _, p := range m.paths {
+ pm.Paths = append(pm.Paths, []byte(p))
+ }
+ pkg.Messages = append(pkg.Messages, pm)
+ }
+ if len(l.files) > landMaxPackageFiles {
+ pkg.Reason = landCutString(fmt.Sprintf("the merge has %d conflicting files, more than the %d that a conflict package lists: it cannot be resolved through a land", len(l.files), landMaxPackageFiles), landPackageReasonBytes)
+ return pkg, nil
+ }
+
+ if err := l.prepareHunks(ctx); err != nil {
+ return nil, err
+ }
+ listings := map[git.ObjectID]map[git.ObjectID][]string{}
+ for _, f := range l.files {
pf := &gitalypb.LandConflictFile{
Path: []byte(f.conflict.path),
Kind: landKindProto(f.kind),
- Base: landSideProto(f.conflict.base),
- Ours: landSideProto(f.conflict.ours),
- Theirs: landSideProto(f.conflict.theirs),
Outcome: f.outcome,
Reason: landCutString(f.reason, landPackageReasonBytes),
SyntaxUnchecked: f.syntaxUnchecked,
+ Hunks: f.hunks,
+ HunksOmitted: f.hunksOmitted,
}
- if f.textRead() && (f.kind == resolver.KindContent || f.kind == resolver.KindAddAdd) {
- pf.Hunks = landConflictHunks(f.sides[0], f.sides[1], f.sides[2])
+ for _, s := range []struct {
+ blob *landBlob
+ rev git.ObjectID
+ dst **gitalypb.LandConflictSide
+ }{{f.conflict.base, l.base, &pf.Base}, {f.conflict.ours, l.tip, &pf.Ours}, {f.conflict.theirs, l.commitID, &pf.Theirs}} {
+ if s.blob == nil {
+ continue
+ }
+ kept, err := l.sideKept(ctx, listings, s.blob.oid, f.conflict.path, s.rev)
+ if err != nil {
+ return nil, err
+ }
+ side := &gitalypb.LandConflictSide{Mode: s.blob.mode}
+ if kept {
+ side.Oid = s.blob.oid.String()
+ } else {
+ side.Unavailable = landSideUnavailable
+ }
+ *s.dst = side
}
pkg.Files = append(pkg.Files, pf)
}
- return pkg
+
+ if proto.Size(pkg) > landMaxPackageBytes {
+ for _, pf := range pkg.GetFiles() {
+ if len(pf.GetHunks()) > 0 {
+ pf.Hunks, pf.HunksOmitted = nil, landHunksPackage
+ }
+ }
+ }
+ if proto.Size(pkg) > landMaxPackageBytes {
+ pkg.Files = nil
+ pkg.Reason = landCutString(fmt.Sprintf("the conflict package of the %d conflicting files would be over %d bytes even without hunks: it cannot be resolved through a land", len(l.files), landMaxPackageBytes), landPackageReasonBytes)
+ }
+ return pkg, nil
}
-func landSideProto(b *landBlob) *gitalypb.LandConflictSide {
- if b == nil {
- return nil
+// prepareHunks computes the hunks of the content and add/add conflicts, reading the sides that
+// are not read yet, within the bounds of the package: a side over max_file_bytes is not read, the
+// sides read and the diff work of all files are bounded (landMaxPackageReadBytes,
+// landMaxPackageCells), and a file lists at most landMaxHunksPerFile hunks. Every file left without
+// all its hunks gets the reason in hunksOmitted.
+func (l landListing) prepareHunks(ctx context.Context) error {
+ readLeft, cellsLeft := int64(landMaxPackageReadBytes), landMaxPackageCells
+ for _, f := range l.files {
+ f.hunks, f.hunksOmitted = nil, ""
+ if f.kind != resolver.KindContent && f.kind != resolver.KindAddAdd {
+ continue
+ }
+ if !f.read {
+ reason, err := l.readSides(ctx, f, &readLeft)
+ if err != nil {
+ return err
+ }
+ if reason != "" {
+ f.hunksOmitted = reason
+ continue
+ }
+ }
+ if !f.textRead() {
+ f.hunksOmitted = landHunksBinary
+ continue
+ }
+ cost, fits := merge3.Cost(f.sides[0], f.sides[1], f.sides[2])
+ if !fits {
+ f.hunksOmitted = landHunksDiffCost
+ continue
+ }
+ if cost > cellsLeft {
+ f.hunksOmitted = landHunksBudget
+ continue
+ }
+ cellsLeft -= cost
+ hunks, ok := landConflictHunks(f.sides[0], f.sides[1], f.sides[2])
+ if !ok {
+ // Cost said both diffs fit, which is what Merge checks.
+ return fmt.Errorf("merge3 refused the sides of %q that fit its bound", f.conflict.path)
+ }
+ if len(hunks) > landMaxHunksPerFile {
+ f.hunksOmitted = fmt.Sprintf("the file has %d conflicting regions; the first %d are listed", len(hunks), landMaxHunksPerFile)
+ hunks = hunks[:landMaxHunksPerFile]
+ }
+ f.hunks = hunks
+ }
+ return nil
+}
+
+// readSides reads the sides of f for its hunks, and returns why it did not: a side over
+// max_file_bytes, or sides that would take the package past its reading bound (*readLeft, which it
+// lowers by what it reads).
+func (l landListing) readSides(ctx context.Context, f *landFileState, readLeft *int64) (string, error) {
+ blobs := []*landBlob{f.conflict.base, f.conflict.ours, f.conflict.theirs}
+ var size int64
+ for _, b := range blobs {
+ if b == nil {
+ continue
+ }
+ info, err := l.repo.ReadObjectInfo(ctx, b.oid.Revision())
+ if err != nil {
+ return "", fmt.Errorf("reading size of %q: %w", f.conflict.path, err)
+ }
+ if info.Size > l.maxFileBytes {
+ return landHunksTooLarge, nil
+ }
+ size += info.Size
+ }
+ if size > *readLeft {
+ return landHunksBudget, nil
+ }
+ *readLeft -= size
+ var sides [3][]byte
+ for i, b := range blobs {
+ if b == nil {
+ continue
+ }
+ content, err := l.repo.ReadObject(ctx, b.oid)
+ if err != nil {
+ return "", fmt.Errorf("reading blob of %q: %w", f.conflict.path, err)
+ }
+ sides[i] = content
+ }
+ f.sides, f.read = sides, true
+ return "", nil
+}
+
+// sideKept reports whether blob is in the tree of the merge base, the tip or the landed commit,
+// which the repository keeps whatever becomes of the land. merge-tree also writes blobs of its own
+// for a conflict, such as the content merge of a renamed file, into the quarantine of the request:
+// those are discarded when the land fails, so their object IDs must not reach the agent. own is
+// the commit the side comes from, looked up first at the conflict's path; the full listings of the
+// three trees are read only when that misses (a rename, a blob of the merge), once each.
+func (l landListing) sideKept(ctx context.Context, listings map[git.ObjectID]map[git.ObjectID][]string, blob git.ObjectID, p string, own git.ObjectID) (bool, error) {
+ if own != "" {
+ info, err := l.repo.ReadObjectInfo(ctx, git.Revision(own.String()+":"+p))
+ var notFound localrepo.InvalidObjectError
+ switch {
+ case err == nil && info.Oid == blob:
+ return true, nil
+ case err != nil && !errors.As(err, &notFound):
+ return false, fmt.Errorf("looking up %q in %s: %w", p, own, err)
+ }
+ }
+ revs := []git.ObjectID{l.tip, l.commitID}
+ if l.hasBase {
+ revs = append(revs, l.base)
+ }
+ for _, rev := range revs {
+ listing, ok := listings[rev]
+ if !ok {
+ var err error
+ if listing, err = landListTree(ctx, l.repo, rev); err != nil {
+ return false, err
+ }
+ listings[rev] = listing
+ }
+ if len(listing[blob]) > 0 {
+ return true, nil
+ }
}
- return &gitalypb.LandConflictSide{Oid: b.oid.String(), Mode: b.mode}
+ return false, nil
}
// landCut cuts b to at most n bytes on a UTF-8 boundary and reports whether it was cut.
diff --git a/internal/gitaly/service/operations/land_package_test.go b/internal/gitaly/service/operations/land_package_test.go
index d9b72b5..db7d0c5 100644
--- a/internal/gitaly/service/operations/land_package_test.go
+++ b/internal/gitaly/service/operations/land_package_test.go
@@ -1,13 +1,16 @@
package operations
import (
+ "context"
"encoding/json"
+ "fmt"
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/require"
+ "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/feder-cr/git-ai/internal/git"
@@ -69,7 +72,8 @@ func TestLandConflictHunks(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
- got := landConflictHunks([]byte(tc.base), []byte(tc.ours), []byte(tc.theirs))
+ got, ok := landConflictHunks([]byte(tc.base), []byte(tc.ours), []byte(tc.theirs))
+ require.True(t, ok)
require.Len(t, got, len(tc.want))
for i := range tc.want {
require.Equal(t, tc.want[i].String(), got[i].String(), "hunk %d", i)
@@ -88,6 +92,14 @@ func landConflictDetail(err error) *gitalypb.LandConflict {
return nil
}
+// builtPackage builds the conflict package of an unresolved land, as landWithPackage does.
+func builtPackage(t *testing.T, ctx context.Context, e *landUnresolvedError) *gitalypb.LandConflict {
+ t.Helper()
+ pkg, err := e.listing.conflictPackage(ctx, e.reason)
+ require.NoError(t, err)
+ return pkg
+}
+
// writeRawAnswer sets any JSON as the answer the resolver script of dir gives.
func writeRawAnswer(t *testing.T, dir string, answer any) {
t.Helper()
@@ -163,6 +175,28 @@ func TestUserLand_conflictPackage(t *testing.T) {
}
})
+ t.Run("a refusal that marks every file resolved never writes", func(t *testing.T) {
+ t.Parallel()
+
+ dir, argv := resolverScript(t, `cat "$DIR/answer.json"; exit 1`)
+ writeRawAnswer(t, dir, resolver.ErrorResponse{
+ Error: "refused",
+ Files: []resolver.FileOutcome{{Path: "a", Outcome: resolver.OutcomeResolved}, {Path: "b", Outcome: resolver.OutcomeResolved}},
+ })
+ fx := newResolveFixture(t, enabledResolver(argv))
+
+ _, err := fx.client.UserLand(fx.ctx, fx.request("Land"))
+ requireMergeConflict(t, err)
+ pkg := landConflictDetail(err)
+ require.NotNil(t, pkg)
+ for _, p := range []string{"a", "b"} {
+ f := packageFile(t, pkg, p)
+ require.Equal(t, gitalypb.LandConflictFile_OUTCOME_FAILED, f.GetOutcome(), p)
+ require.Contains(t, f.GetReason(), "refused", p)
+ }
+ requireBranchAt(t, fx.cfg, fx.repoPath, git.DefaultBranch, fx.tip)
+ })
+
t.Run("a lockfile is not sent, the other file is", func(t *testing.T) {
t.Parallel()
@@ -284,6 +318,50 @@ func TestUserLand_reland(t *testing.T) {
require.Equal(t, "agent-a\n", string(check.Resolution[0].Content))
})
+ t.Run("actors and max_files bound AI requests only: an actor they exclude re-lands, checked", func(t *testing.T) {
+ t.Parallel()
+
+ dir, argv := resolverScript(t, "")
+ writeRawAnswer(t, dir, resolver.CheckResponse{
+ Version: resolver.ProtocolVersion, Operation: resolver.OperationCheck, Resolver: "graft-resolve",
+ Files: []resolver.CheckFile{{Path: "a", OK: true, Syntax: resolver.SyntaxNone}, {Path: "b", OK: true, Syntax: resolver.SyntaxNone}},
+ })
+ rcfg := enabledResolver(argv)
+ rcfg.Actors = []string{"someone-else"}
+ rcfg.MaxFiles = 1
+ fx := newResolveFixture(t, rcfg)
+ req := fx.request("Land")
+ req.ResolveConflicts = false
+ req.Resolution = resolutionOf(fx, "agent-a\n", "agent-b\n")
+
+ resp, err := fx.client.UserLand(fx.ctx, req)
+ require.NoError(t, err)
+ commit, err := fx.repo.ReadCommit(fx.ctx, git.ObjectID(resp.GetLandedCommitId()).Revision())
+ require.NoError(t, err)
+ require.Contains(t, string(commit.GetBody()), "Graft-Checked-By: graft-resolve\n")
+ require.Equal(t, 1, resolverCalls(t, dir), "the check ran, on both files, whatever the actor and max_files")
+ require.Len(t, resolverRequest(t, dir, 1).Resolution, 2)
+ })
+
+ t.Run("a written mode that no side has is rejected", func(t *testing.T) {
+ t.Parallel()
+
+ fx := newResolveFixture(t, config.GraftResolver{})
+ req := fx.request("Land")
+ req.ResolveConflicts = false
+ req.Resolution = resolutionOf(fx, "agent-a\n", "agent-b\n")
+ req.Resolution.Files[0].Mode = "100755"
+
+ _, err := fx.client.UserLand(fx.ctx, req)
+ requireMergeConflict(t, err)
+ pkg := landConflictDetail(err)
+ require.NotNil(t, pkg)
+ a := packageFile(t, pkg, "a")
+ require.Equal(t, gitalypb.LandConflictFile_OUTCOME_REJECTED, a.GetOutcome())
+ require.Contains(t, a.GetReason(), "mode 100755, which is none of the modes of the sides (100644)")
+ requireBranchAt(t, fx.cfg, fx.repoPath, git.DefaultBranch, fx.tip)
+ })
+
t.Run("a failed check rejects the file", func(t *testing.T) {
t.Parallel()
@@ -390,4 +468,183 @@ func TestUserLand_reland(t *testing.T) {
_, err := fx.client.UserLand(fx.ctx, req)
require.Contains(t, err.Error(), "resolution is for commit")
})
+
+ t.Run("a conflicting path with a line break is refused before anything is written", func(t *testing.T) {
+ t.Parallel()
+
+ fx := newLineBreakPathFixture(t, config.GraftResolver{})
+ req := fx.request("Land")
+ req.ResolveConflicts = false
+ req.Resolution = &gitalypb.LandResolution{
+ Tip: fx.tip.String(),
+ Commit: fx.commit.String(),
+ Files: []*gitalypb.LandResolvedFile{
+ {Path: []byte(lineBreakPath), Action: gitalypb.LandResolvedFile_ACTION_WRITE, Mode: "100644", Content: []byte("agent\n")},
+ },
+ }
+
+ _, err := fx.client.UserLand(fx.ctx, req)
+ require.Equal(t, codes.FailedPrecondition, status.Code(err))
+ require.Contains(t, err.Error(), "Graft-Resolved-Path trailer")
+ requireBranchAt(t, fx.cfg, fx.repoPath, git.DefaultBranch, fx.tip)
+ })
+}
+
+// lineBreakPath is a path that would inject a trailer if it were written as one.
+const lineBreakPath = "a\nGraft-Resolved-By: evil"
+
+// newLineBreakPathFixture is a fixture whose only conflict is on lineBreakPath.
+func newLineBreakPathFixture(t *testing.T, rcfg config.GraftResolver) resolveFixture {
+ return newResolveFixtureWith(t, rcfg,
+ []gittest.TreeEntry{{Mode: "100644", Path: lineBreakPath, Content: "base\n"}},
+ []gittest.TreeEntry{{Mode: "100644", Path: lineBreakPath, Content: "ours\n"}},
+ []gittest.TreeEntry{{Mode: "100644", Path: lineBreakPath, Content: "theirs\n"}},
+ )
+}
+
+func TestUserLand_lineBreakPathIsNeverSent(t *testing.T) {
+ t.Parallel()
+
+ dir, argv := resolverScript(t, "")
+ writeAnswer(t, dir, validAnswer())
+ fx := newLineBreakPathFixture(t, enabledResolver(argv))
+
+ _, err := fx.client.UserLand(fx.ctx, fx.request("Land"))
+ requireMergeConflict(t, err)
+ pkg := landConflictDetail(err)
+ require.NotNil(t, pkg)
+ f := packageFile(t, pkg, lineBreakPath)
+ require.Equal(t, gitalypb.LandConflictFile_OUTCOME_NOT_SENT, f.GetOutcome())
+ require.Equal(t, landNotSentTrailerUnsafe, f.GetReason())
+ require.Equal(t, 0, resolverCalls(t, dir))
+ requireBranchAt(t, fx.cfg, fx.repoPath, git.DefaultBranch, fx.tip)
+}
+
+// seq returns the lines 1 to n, with the given lines replaced.
+func seq(n int, replace map[int]string) string {
+ var b strings.Builder
+ for i := 1; i <= n; i++ {
+ if r, ok := replace[i]; ok {
+ b.WriteString(r + "\n")
+ continue
+ }
+ fmt.Fprintf(&b, "%d\n", i)
+ }
+ return b.String()
+}
+
+// requirePackageOIDsKept checks that every object ID of the package is in the repository after the
+// land failed, so outside the quarantine of the request, and that a side without one says why.
+func requirePackageOIDsKept(t *testing.T, fx resolveFixture, pkg *gitalypb.LandConflict) {
+ t.Helper()
+ for _, f := range pkg.GetFiles() {
+ for _, s := range []*gitalypb.LandConflictSide{f.GetBase(), f.GetOurs(), f.GetTheirs()} {
+ if s == nil {
+ continue
+ }
+ if s.GetOid() == "" {
+ require.Equal(t, landSideUnavailable, s.GetUnavailable(), string(f.GetPath()))
+ continue
+ }
+ require.Empty(t, s.GetUnavailable())
+ gittest.Exec(t, fx.cfg, "-C", fx.repoPath, "cat-file", "-e", s.GetOid())
+ }
+ }
+}
+
+func TestUserLand_conflictPackageSidesAreKept(t *testing.T) {
+ t.Parallel()
+
+ t.Run("a rename whose content merge is a side of its own", func(t *testing.T) {
+ t.Parallel()
+
+ // The tip renames a.txt to c.txt and changes line 19; the change changes line 2 of a.txt
+ // and adds a c.txt of its own. merge-tree merges the rename (the base, the tip's c.txt
+ // and the change's a.txt) into a blob it writes for the conflict, the tip's side of the
+ // add/add conflict on c.txt. That blob is in no tree, and the failed land discards it.
+ fx := newResolveFixtureWith(t, config.GraftResolver{},
+ []gittest.TreeEntry{{Mode: "100644", Path: "a.txt", Content: seq(20, nil)}},
+ []gittest.TreeEntry{{Mode: "100644", Path: "c.txt", Content: seq(20, map[int]string{19: "nineteen-ours"})}},
+ []gittest.TreeEntry{
+ {Mode: "100644", Path: "a.txt", Content: seq(20, map[int]string{2: "two-theirs"})},
+ {Mode: "100644", Path: "c.txt", Content: "added by theirs\n"},
+ },
+ )
+
+ _, err := fx.client.UserLand(fx.ctx, fx.request("Land"))
+ requireMergeConflict(t, err)
+ pkg := landConflictDetail(err)
+ require.NotNil(t, pkg)
+ c := packageFile(t, pkg, "c.txt")
+ require.Empty(t, c.GetOurs().GetOid(), "the merged rename is not kept")
+ require.Equal(t, landSideUnavailable, c.GetOurs().GetUnavailable())
+ require.Equal(t, "100644", c.GetOurs().GetMode())
+ require.NotEmpty(t, c.GetTheirs().GetOid())
+ // The hunks were computed from the side while the request could still read it.
+ require.NotEmpty(t, c.GetHunks())
+ requirePackageOIDsKept(t, fx, pkg)
+ })
+
+ t.Run("a criss-cross history", func(t *testing.T) {
+ t.Parallel()
+
+ // A resolver is enabled, so the request gets as far as the merge bases; it is never called.
+ dir, argv := resolverScript(t, "")
+ writeAnswer(t, dir, validAnswer())
+ fx := newResolveFixture(t, enabledResolver(argv))
+ // Two branches merge each other: tip and commit have two merge bases, x and y, and both
+ // change a.
+ x := gittest.WriteCommit(t, fx.cfg, fx.repoPath, gittest.WithParents(fx.base), gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "x\n"}, gittest.TreeEntry{Mode: "100644", Path: "b", Content: "base\n"}))
+ y := gittest.WriteCommit(t, fx.cfg, fx.repoPath, gittest.WithParents(fx.base), gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "y\n"}, gittest.TreeEntry{Mode: "100644", Path: "b", Content: "base\n"}))
+ tip := gittest.WriteCommit(t, fx.cfg, fx.repoPath, gittest.WithParents(x, y), gittest.WithBranch(git.DefaultBranch), gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "tip\n"}, gittest.TreeEntry{Mode: "100644", Path: "b", Content: "base\n"}))
+ commit := gittest.WriteCommit(t, fx.cfg, fx.repoPath, gittest.WithParents(y, x), gittest.WithTreeEntries(
+ gittest.TreeEntry{Mode: "100644", Path: "a", Content: "commit\n"}, gittest.TreeEntry{Mode: "100644", Path: "b", Content: "base\n"}))
+ fx.tip, fx.commit = tip, commit
+
+ req := fx.request("Land")
+ req.Strategy = gitalypb.UserLandRequest_STRATEGY_MERGE
+ _, err := fx.client.UserLand(fx.ctx, req)
+ requireMergeConflict(t, err)
+ pkg := landConflictDetail(err)
+ require.NotNil(t, pkg)
+ require.Contains(t, pkg.GetReason(), "2 merge bases")
+ require.Len(t, pkg.GetFiles(), 1)
+ requirePackageOIDsKept(t, fx, pkg)
+ require.Equal(t, 0, resolverCalls(t, dir))
+ requireBranchAt(t, fx.cfg, fx.repoPath, git.DefaultBranch, tip)
+ })
+
+ t.Run("an unclean merge without a conflicting file", func(t *testing.T) {
+ t.Parallel()
+
+ // The tip moves d/a to x/a and d/b to y/b; the change adds d/new. Git cannot tell where
+ // the directory d went (a directory rename split): the merge is unclean, with no stage
+ // entry, and only the merge's message describes it.
+ fx := newResolveFixtureWith(t, config.GraftResolver{},
+ []gittest.TreeEntry{{Mode: "100644", Path: "d/a", Content: "1\n"}, {Mode: "100644", Path: "d/b", Content: "2\n"}},
+ []gittest.TreeEntry{{Mode: "100644", Path: "x/a", Content: "1\n"}, {Mode: "100644", Path: "y/b", Content: "2\n"}},
+ []gittest.TreeEntry{{Mode: "100644", Path: "d/a", Content: "1\n"}, {Mode: "100644", Path: "d/b", Content: "2\n"}, {Mode: "100644", Path: "d/new", Content: "new\n"}},
+ )
+ req := fx.request("Land")
+ req.Strategy = gitalypb.UserLandRequest_STRATEGY_MERGE
+ _, err := fx.client.UserLand(fx.ctx, req)
+ requireMergeConflict(t, err)
+ pkg := landConflictDetail(err)
+ require.NotNil(t, pkg)
+ require.Empty(t, pkg.GetFiles())
+ require.Equal(t, landNoConflictingFiles, pkg.GetReason())
+ var split bool
+ for _, m := range pkg.GetMessages() {
+ if m.GetType() == "CONFLICT(directory rename unclear split)" {
+ split = true
+ require.Equal(t, [][]byte{[]byte("d")}, m.GetPaths())
+ require.Contains(t, m.GetMessage(), "CONFLICT (directory rename split): Unclear where to rename d to")
+ }
+ }
+ require.True(t, split, "messages %v", pkg.GetMessages())
+ requireBranchAt(t, fx.cfg, fx.repoPath, git.DefaultBranch, fx.tip)
+ })
}
diff --git a/internal/gitaly/service/operations/land_reland.go b/internal/gitaly/service/operations/land_reland.go
index 0e8723c..0211f33 100644
--- a/internal/gitaly/service/operations/land_reland.go
+++ b/internal/gitaly/service/operations/land_reland.go
@@ -63,32 +63,50 @@ func (s *Server) landWithResolution(
if err != nil {
return landResolution{}, err
}
- maxFiles := s.resolveCfg.MaxFilesOrDefault()
+ if len(l.files) == 0 {
+ return landResolution{}, l.notAttempted(landNoConflictingFiles, nil)
+ }
if r.GetTip() != tip.String() {
- return landResolution{}, l.notAttempted(ctx, maxFiles, fmt.Sprintf("the branch tip moved from %s to %s since the resolution was made: resolve the conflicts of this package", r.GetTip(), tip), nil)
+ return landResolution{}, l.notAttempted(fmt.Sprintf("the branch tip moved from %s to %s since the resolution was made: resolve the conflicts of this package", r.GetTip(), tip), nil)
}
if l.bases > 1 {
- return landResolution{}, l.notAttempted(ctx, maxFiles, fmt.Sprintf("the change has %d merge bases (a criss-cross history), which are not resolved", l.bases), nil)
+ return landResolution{}, l.notAttempted(fmt.Sprintf("the change has %d merge bases (a criss-cross history), which are not resolved", l.bases), nil)
+ }
+
+ // The merge commit names the actor and every resolved path in its trailers: a value that cannot
+ // be one trailer line is refused before anything else, and resolving the path again cannot help.
+ actor := identity.Actor(ctx, "")
+ if !landTrailerValueValid(landAgentResolver(actor)) {
+ return landResolution{}, structerr.NewFailedPrecondition("the actor %q cannot be recorded in the %s trailer: it must be one line of printable UTF-8", actor, landTrailerResolvedBy)
+ }
+ for _, f := range l.files {
+ if !landTrailerValueValid(f.conflict.path) {
+ return landResolution{}, structerr.NewFailedPrecondition("the conflicting path %q cannot be recorded in the %s trailer: it must be one line of printable UTF-8, so its conflict cannot be resolved through a land", f.conflict.path, landTrailerResolvedPath)
+ }
}
resolved, reason := landResolutionFiles(r, l.files)
if reason != "" {
- return landResolution{}, l.notAttempted(ctx, maxFiles, reason, nil)
+ return landResolution{}, l.notAttempted(reason, nil)
}
maxBytes := s.resolveCfg.MaxFileBytesOrDefault()
rejected := false
for _, f := range l.files {
- if err := resolver.ValidateFile(resolved[f.conflict.path], maxBytes); err != nil {
+ rf := resolved[f.conflict.path]
+ err := resolver.ValidateFile(rf, maxBytes)
+ if err == nil {
+ err = landModeOfSides(f.conflict, rf)
+ }
+ if err != nil {
f.outcome, f.reason = gitalypb.LandConflictFile_OUTCOME_REJECTED, err.Error()
rejected = true
}
}
- actor := identity.Actor(ctx, "")
- checkedBy := ""
+ checkedBy, syntaxUnchecked := "", 0
if !rejected && s.conflictResolver != nil {
- if checkedBy, err = s.landCheckResolution(ctx, in, repo, l, actor, resolved); err != nil {
+ if checkedBy, syntaxUnchecked, err = s.landCheckResolution(ctx, in, repo, l, actor, resolved); err != nil {
return landResolution{}, err
}
}
@@ -103,7 +121,7 @@ func (s *Server) landWithResolution(
f.outcome, f.reason = gitalypb.LandConflictFile_OUTCOME_RESOLVED, ""
}
}
- return landResolution{}, l.unresolved(ctx, maxFiles, "", "the resolution was rejected: "+landUnresolvedCause(l.files), nil)
+ return landResolution{}, l.unresolved("", "the resolution was rejected: "+landUnresolvedCause(l.files), nil)
}
resp := &resolver.Response{Version: resolver.ProtocolVersion, Resolver: landAgentResolver(actor)}
@@ -111,7 +129,8 @@ func (s *Server) landWithResolution(
resp.Files = append(resp.Files, resolved[f.conflict.path])
}
res, err := s.landWriteResolution(ctx, in, repo, tip, commitID, l.mergedTree, committer, actor, resp, checkedBy)
- return res, l.verifyRejected(ctx, maxFiles, err)
+ res.syntaxUnchecked = syntaxUnchecked
+ return res, l.verifyRejected(err)
}
// landResolutionFiles maps the files of the resolution to the conflicting paths. It returns a
@@ -159,8 +178,8 @@ func landResolutionFiles(r *gitalypb.LandResolution, files []*landFileState) (ma
// landCheckResolution runs the resolver's checks on the files of the resolution that may be sent
// to the resolver (landClassify), and sets the outcome of each checked file that fails them to
// REJECTED. It returns the checker's name for the Graft-Checked-By trailer, or "" when no file
-// could be sent. The check fails closed: a check that cannot run is a *landUnresolvedError with a
-// fresh package.
+// could be sent, and the number of files accepted without a syntax verdict. The check fails
+// closed: a check that cannot run is a *landUnresolvedError with a fresh package.
func (s *Server) landCheckResolution(
ctx context.Context,
in *gitalypb.UserLandRequest,
@@ -168,9 +187,9 @@ func (s *Server) landCheckResolution(
l landListing,
actor string,
resolved map[string]resolver.ResponseFile,
-) (string, error) {
+) (string, int, error) {
if err := s.landClassify(ctx, repo, l.files, l.base, l.tip, l.commitID); err != nil {
- return "", err
+ return "", 0, err
}
req := resolver.Request{
@@ -202,18 +221,17 @@ func (s *Server) landCheckResolution(
}
if len(checked) == 0 {
s.logger.WithField("unchecked", unchecked).InfoContext(ctx, "graft: no file of the agent's resolution may be sent to the resolver's checks")
- return "", nil
+ return "", 0, nil
}
// Fail closed: a check that cannot run (an error, an answer that is no valid check response, a
// resolver that does not know the check operation) fails the land with a fresh package.
- maxFiles := s.resolveCfg.MaxFilesOrDefault()
resp, err := s.conflictResolver.Check(ctx, req)
if err != nil {
- return "", l.notAttempted(ctx, maxFiles, fmt.Sprintf("the resolution could not be checked: %v", err), err)
+ return "", 0, l.notAttempted(fmt.Sprintf("the resolution could not be checked: %v", err), err)
}
if !landResolverNameValid(resp.Resolver) {
- return "", l.notAttempted(ctx, maxFiles, fmt.Sprintf("the resolution could not be checked: the check names an invalid resolver %q", resp.Resolver), nil)
+ return "", 0, l.notAttempted(fmt.Sprintf("the resolution could not be checked: the check names an invalid resolver %q", resp.Resolver), nil)
}
syntaxUnchecked := 0
for i, v := range resp.Files {
@@ -227,14 +245,11 @@ func (s *Server) landCheckResolution(
syntaxUnchecked++
}
}
- if syntaxUnchecked > 0 {
- landResolutionSyntaxUncheckedTotal.Add(float64(syntaxUnchecked))
- }
s.logger.WithFields(log.Fields{
"checked_by": resp.Resolver,
"checked": len(checked),
"syntax_unchecked": syntaxUnchecked,
"not_checked": unchecked,
}).InfoContext(ctx, "graft: agent's resolution checked")
- return resp.Resolver, nil
+ return resp.Resolver, syntaxUnchecked, nil
}
diff --git a/internal/gitaly/service/operations/land_resolve.go b/internal/gitaly/service/operations/land_resolve.go
index c958f41..bd106cd 100644
--- a/internal/gitaly/service/operations/land_resolve.go
+++ b/internal/gitaly/service/operations/land_resolve.go
@@ -6,8 +6,9 @@ import (
"errors"
"fmt"
"path"
+ "slices"
+ "strconv"
"strings"
- "unicode"
"unicode/utf8"
"google.golang.org/grpc/status"
@@ -42,6 +43,18 @@ type landResolution struct {
commit git.ObjectID
resolvedPaths [][]byte
resolver string
+ // syntaxUnchecked is the number of files of an agent's resolution that the check accepted
+ // without a syntax verdict.
+ syntaxUnchecked int
+}
+
+// landed records a resolution whose land succeeded: the metric of files landed without a syntax
+// verdict counts them here, once per landed request, and not when they were checked, since the
+// land may still fail or be decided again.
+func (r *landResolution) landed() {
+ if r != nil && r.syntaxUnchecked > 0 {
+ landResolutionSyntaxUncheckedTotal.Add(float64(r.syntaxUnchecked))
+ }
}
// landBlob is one side of a conflicted file as merge-tree reports it: the mode and the blob.
@@ -84,8 +97,9 @@ func (s *Server) resolveLandConflicts(
}
base, hasBase, conflicts, files := l.base, l.hasBase, l.conflicts, l.files
tipMessage, commitMessage := l.tipMessage, l.commitMessage
+ // max_files bounds the request to the resolver only: the package lists every conflicting file.
maxFiles := s.resolveCfg.MaxFilesOrDefault()
- notAttempted := func(reason string) error { return l.notAttempted(ctx, maxFiles, reason, nil) }
+ notAttempted := func(reason string) error { return l.notAttempted(reason, nil) }
criss := l.bases
// The actor is the authenticated identity only. The name in the request is chosen by the
@@ -93,6 +107,8 @@ func (s *Server) resolveLandConflicts(
// only an actor list that is empty (allows everyone) admits the request.
actor := identity.Actor(ctx, "")
switch {
+ case len(files) == 0:
+ return landResolution{}, notAttempted(landNoConflictingFiles)
case s.conflictResolver == nil:
return landResolution{}, notAttempted("conflict resolution is not enabled on this server")
case !s.conflictResolver.ActorAllowed(actor):
@@ -114,7 +130,9 @@ func (s *Server) resolveLandConflicts(
}
}
- var resp *resolver.Response
+ // answer is the resolver's accepted answer, the only thing ever written. A refusal is never
+ // written, whatever its outcomes say: answer stays nil, and the land fails with the package.
+ var answer *resolver.Response
var resolveErr error
if len(sent) > 0 {
req := resolver.Request{
@@ -135,37 +153,44 @@ func (s *Server) resolveLandConflicts(
}
// The client applies the timeout, the request policy and the acceptance rules of the answer.
- resp, resolveErr = s.conflictResolver.Resolve(ctx, req)
+ resp, err := s.conflictResolver.Resolve(ctx, req)
+ resolveErr = err
switch {
- case resolveErr == nil && !landResolverNameValid(resp.Resolver):
+ case err != nil:
+ landRefusalOutcomes(files, err)
+ case !landResolverNameValid(resp.Resolver):
// The name is written into the commit trailers, so it must be a plain single-line name.
landFailSent(files, gitalypb.LandConflictFile_OUTCOME_FAILED, fmt.Sprintf("the resolver's answer names an invalid resolver %q", resp.Resolver))
- resp = nil
- case resolveErr != nil:
- landRefusalOutcomes(files, resolveErr)
default:
+ answer = resp
+ written := make(map[string]resolver.ResponseFile, len(resp.Files))
+ for _, rf := range resp.Files {
+ written[rf.Path] = rf
+ }
for _, f := range files {
- if f.sent() {
- f.outcome = gitalypb.LandConflictFile_OUTCOME_RESOLVED
+ if !f.sent() {
+ continue
+ }
+ f.outcome = gitalypb.LandConflictFile_OUTCOME_RESOLVED
+ if err := landModeOfSides(f.conflict, written[f.conflict.path]); err != nil {
+ f.outcome, f.reason = gitalypb.LandConflictFile_OUTCOME_REJECTED, err.Error()
}
}
}
}
- for _, f := range files {
- if f.outcome != gitalypb.LandConflictFile_OUTCOME_RESOLVED {
- return landResolution{}, l.unresolved(ctx, maxFiles, "", landUnresolvedCause(files), resolveErr)
- }
+ if answer == nil || !landAllResolved(files) {
+ return landResolution{}, l.unresolved("", landUnresolvedCause(files), resolveErr)
}
- res, err := s.landWriteResolution(ctx, in, repo, tip, commitID, l.mergedTree, committer, actor, resp, "")
- return res, l.verifyRejected(ctx, maxFiles, err)
+ res, err := s.landWriteResolution(ctx, in, repo, tip, commitID, l.mergedTree, committer, actor, answer, "")
+ return res, l.verifyRejected(err)
}
// verifyRejected turns a resolution that the verification rejected into the unresolved land with
// its package, every file rejected with the reason of the verification. Any other error is
// returned as is.
-func (l landListing) verifyRejected(ctx context.Context, maxFiles int, err error) error {
+func (l landListing) verifyRejected(err error) error {
var verifyErr *landVerifyError
if !errors.As(err, &verifyErr) {
return err
@@ -173,7 +198,7 @@ func (l landListing) verifyRejected(ctx context.Context, maxFiles int, err error
for _, f := range l.files {
f.outcome, f.reason = gitalypb.LandConflictFile_OUTCOME_REJECTED, verifyErr.Error()
}
- return l.unresolved(ctx, maxFiles, "", verifyErr.Error(), err)
+ return l.unresolved("", verifyErr.Error(), err)
}
// landListing is the conflicting files of the merge of a tip and a change, with what the conflict
@@ -190,10 +215,17 @@ type landListing struct {
conflicts []landFileConflict
files []*landFileState
tipMessage, commitMessage string
+ // messages are merge-tree's messages about the merge. A merge can be unclean without a
+ // conflicting file (a directory rename split): then files is empty and only messages
+ // describe it.
+ messages []landMergeMessage
}
+// landNoConflictingFiles is the reason of a merge that is unclean without a conflicting file.
+const landNoConflictingFiles = "the merge has conflicts without a conflicting file (see the messages of the package), which a resolution of files cannot resolve"
+
// errLandNoConflicts is the error of landListConflicts when the merge is clean.
-var errLandNoConflicts = errors.New("the merge of the tip and the change reports no conflicting files")
+var errLandNoConflicts = errors.New("the merge of the tip and the change is clean")
// landListConflicts lists the files that conflict between tip and commitID. A clean merge is an
// error: when rebasing, the conflict may come from an intermediate commit that a later commit of
@@ -205,10 +237,11 @@ func landListConflicts(ctx context.Context, repo *localrepo.Repo, tip, commitID
if l.base, l.hasBase, l.bases, err = landMergeBase(ctx, repo, tip, commitID); err != nil {
return l, err
}
- if l.mergedTree, l.conflicts, err = landMergeTree(ctx, repo, tip, commitID, l.base, l.hasBase); err != nil {
+ var clean bool
+ if l.mergedTree, l.conflicts, l.messages, clean, err = landMergeTree(ctx, repo, tip, commitID, l.base, l.hasBase); err != nil {
return l, err
}
- if len(l.conflicts) == 0 {
+ if clean {
return l, errLandNoConflicts
}
if l.tipMessage, err = landCommitBody(ctx, repo, tip); err != nil {
@@ -223,65 +256,52 @@ func landListConflicts(ctx context.Context, repo *localrepo.Repo, tip, commitID
return l, nil
}
-// unresolved returns the error of a land left unresolved, with its conflict package. err is the
-// error of the resolver or of the check that caused it, if any. The sides that the hunks of the
-// package need and that were not read yet are read here, whatever the outcome of the file.
-func (l landListing) unresolved(ctx context.Context, maxFiles int, reason, cause string, err error) error {
- if readErr := l.readForHunks(ctx, maxFiles); readErr != nil {
- return readErr
- }
- return &landUnresolvedError{
- pkg: landPackage(l.tip, l.commitID, l.base, l.tipMessage, l.commitMessage, l.files, maxFiles, reason),
- cause: cause,
- err: err,
+// unresolved returns the error of a land left unresolved, which carries what its conflict package
+// is built from (landWithPackage). reason is the package's reason, cause the error's. err is the
+// error of the resolver or of the check that caused it, if any.
+func (l landListing) unresolved(reason, cause string, err error) error {
+ return &landUnresolvedError{listing: l, reason: reason, cause: cause, err: err}
+}
+
+// notAttempted returns the error of a land the server did not try to resolve at all, every file
+// NOT_ATTEMPTED and the package carrying the reason.
+func (l landListing) notAttempted(reason string, err error) error {
+ for _, f := range l.files {
+ f.outcome, f.reason = gitalypb.LandConflictFile_OUTCOME_NOT_ATTEMPTED, ""
}
+ return l.unresolved(reason, reason, err)
}
-// readForHunks reads the sides of the content and add/add conflicts of the package that are not
-// read yet and fit max_file_bytes, so that the package has their hunks. A larger side is not read:
-// its file gets no hunks, as a diff of that size is not computed anyway.
-func (l landListing) readForHunks(ctx context.Context, maxFiles int) error {
- for i, f := range l.files {
- if i == maxFiles {
- break
- }
- if f.read || (f.kind != resolver.KindContent && f.kind != resolver.KindAddAdd) {
+// landModeOfSides refuses a written resolution whose mode is none of the modes of the conflict's
+// sides: a resolution merges the sides, and turning a file into a symbolic link or an executable
+// (or back) that no side asked for is not a merge. A deletion has no mode.
+func landModeOfSides(c landFileConflict, rf resolver.ResponseFile) error {
+ if rf.Action != resolver.ActionWrite {
+ return nil
+ }
+ var modes []string
+ for _, b := range []*landBlob{c.base, c.ours, c.theirs} {
+ if b == nil {
continue
}
- var sides [3][]byte
- fits := true
- for j, b := range []*landBlob{f.conflict.base, f.conflict.ours, f.conflict.theirs} {
- if b == nil {
- continue
- }
- info, err := l.repo.ReadObjectInfo(ctx, b.oid.Revision())
- if err != nil {
- return fmt.Errorf("reading size of %q: %w", f.conflict.path, err)
- }
- if info.Size > l.maxFileBytes {
- fits = false
- break
- }
- content, err := l.repo.ReadObject(ctx, b.oid)
- if err != nil {
- return fmt.Errorf("reading blob of %q: %w", f.conflict.path, err)
- }
- sides[j] = content
+ if b.mode == rf.Mode {
+ return nil
}
- if fits {
- f.sides, f.read = sides, true
+ if !slices.Contains(modes, b.mode) {
+ modes = append(modes, b.mode)
}
}
- return nil
+ return fmt.Errorf("the resolution writes mode %s, which is none of the modes of the sides (%s)", rf.Mode, strings.Join(modes, ", "))
}
-// notAttempted returns the error of a land the server did not try to resolve at all, every file
-// NOT_ATTEMPTED and the package carrying the reason.
-func (l landListing) notAttempted(ctx context.Context, maxFiles int, reason string, err error) error {
- for _, f := range l.files {
- f.outcome, f.reason = gitalypb.LandConflictFile_OUTCOME_NOT_ATTEMPTED, ""
+// landAllResolved reports whether every file of the land is resolved.
+func landAllResolved(files []*landFileState) bool {
+ for _, f := range files {
+ if f.outcome != gitalypb.LandConflictFile_OUTCOME_RESOLVED {
+ return false
+ }
}
- return l.unresolved(ctx, maxFiles, reason, reason, err)
+ return true
}
// landRequestFile is the file of the resolve request for a classified file that is sent.
@@ -368,6 +388,14 @@ func (s *Server) landWriteResolution(
paths := make([]string, 0, len(resp.Files))
for _, f := range resp.Files {
paths = append(paths, f.Path)
+ }
+ // The message comes first: a value that cannot be a trailer refuses the resolution before
+ // anything is written.
+ message, err := landResolveCommitMessage(in, commitID, resp.Resolver, checkedBy, paths)
+ if err != nil {
+ return landResolution{}, err
+ }
+ for _, f := range resp.Files {
if f.Action == resolver.ActionDelete {
if err := tree.Delete(f.Path); err != nil && !errors.Is(err, localrepo.ErrEntryNotFound) {
return landResolution{}, fmt.Errorf("deleting %q: %w", f.Path, err)
@@ -396,7 +424,7 @@ func (s *Server) landWriteResolution(
newTip, err := repo.WriteCommit(ctx, localrepo.WriteCommitConfig{
TreeID: tree.OID,
- Message: landResolveCommitMessage(in, commitID, resp.Resolver, checkedBy, paths),
+ Message: message,
Parents: []git.ObjectID{tip, commitID},
AuthorName: committer.Name,
AuthorEmail: committer.Email,
@@ -450,12 +478,12 @@ func (s *Server) landClassify(
for _, f := range files {
c := f.conflict
switch {
- case !landTrailerSafe(c.path):
- f.notSent(landNotSentTrailerUnsafe)
- continue
case !utf8.ValidString(c.path):
f.notSent(landNotSentInvalidUTF8)
continue
+ case !landTrailerValueValid(c.path):
+ f.notSent(landNotSentTrailerUnsafe)
+ continue
case !s.conflictResolver.PathAllowed(c.path):
f.notSent(landNotSentDenied)
continue
@@ -586,7 +614,7 @@ func (s *Server) landDeniedSource(
return fmt.Sprintf("a side is in no path of %s", side.rev), nil
}
for _, p := range sources {
- if !landTrailerSafe(p) || !s.conflictResolver.PathAllowed(p) {
+ if !landTrailerValueValid(p) || !s.conflictResolver.PathAllowed(p) {
return fmt.Sprintf("a side comes from path %q, which may not be sent to the resolver", p), nil
}
}
@@ -594,12 +622,6 @@ func (s *Server) landDeniedSource(
return "", nil
}
-// landTrailerSafe reports whether s can be written as a single line of a commit trailer: it must
-// hold no line break and no NUL byte.
-func landTrailerSafe(s string) bool {
- return !strings.ContainsAny(s, "\r\n\x00")
-}
-
// landTruncate returns s cut to at most n bytes, with a marker when it was cut. The result is
// valid UTF-8: a rune cut in half and any invalid byte are dropped.
func landTruncate(s string, n int) string {
@@ -611,18 +633,9 @@ func landTruncate(s string, n int) string {
// landResolverNameValid reports whether name can be the name of the resolver, which the answer
// chooses and which is written into a commit trailer and the response. It must be non-empty, at
-// most maxResolverNameBytes long, valid UTF-8 and printable: control characters such as tab or
-// escape sequences, and Unicode line or paragraph separators, are rejected.
+// most maxResolverNameBytes long, and a valid trailer value (landTrailerValueValid).
func landResolverNameValid(name string) bool {
- if name == "" || len(name) > maxResolverNameBytes || !utf8.ValidString(name) {
- return false
- }
- for _, r := range name {
- if !unicode.IsPrint(r) {
- return false
- }
- }
- return true
+ return len(name) <= maxResolverNameBytes && landTrailerValueValid(name)
}
// landSide is one present side of a conflicting file and the commit whose tree it comes from.
@@ -707,26 +720,19 @@ func landListTree(ctx context.Context, repo *localrepo.Repo, rev git.ObjectID) (
}
// landResolveCommitMessage returns the message of the resolution commit: the merge message or
-// the default one, followed by the Graft-Resolved trailers.
-func landResolveCommitMessage(in *gitalypb.UserLandRequest, commitID git.ObjectID, resolverName, checkedBy string, paths []string) string {
+// the default one, followed by the trailers of landResolutionTrailers. An agent's resolution
+// records in Graft-Checked-By whether the resolver's checks ran on it: without a resolver it got
+// only the marker rule and the server's structural validation.
+func landResolveCommitMessage(in *gitalypb.UserLandRequest, commitID git.ObjectID, resolverName, checkedBy string, paths []string) (string, error) {
+ trailers, err := landResolutionTrailers(resolverName, checkedBy, paths)
+ if err != nil {
+ return "", err
+ }
subject := strings.TrimRight(string(in.GetMergeMessage()), "\n")
if subject == "" {
subject = fmt.Sprintf("Merge %s into %s", landShortOID(commitID), string(in.GetBranch()))
}
-
- var b strings.Builder
- b.WriteString(subject)
- b.WriteString("\n\n")
- b.WriteString("Graft-Resolved-By: " + resolverName + "\n")
- // An agent's resolution records whether the resolver's checks ran on it: without a resolver
- // it got only the marker rule and the server's structural validation.
- if checkedBy != "" {
- b.WriteString("Graft-Checked-By: " + checkedBy + "\n")
- }
- for _, p := range paths {
- b.WriteString("Graft-Resolved-Path: " + p + "\n")
- }
- return b.String()
+ return subject + "\n\n" + trailers, nil
}
// landShortOID returns the abbreviated object ID used in default messages.
@@ -794,7 +800,7 @@ func landMergeTree(
repo *localrepo.Repo,
tip, commitID, base git.ObjectID,
hasBase bool,
-) (git.ObjectID, []landFileConflict, error) {
+) (git.ObjectID, []landFileConflict, []landMergeMessage, bool, error) {
flags := []gitcmd.Option{
gitcmd.Flag{Name: "-z"},
gitcmd.Flag{Name: "--write-tree"},
@@ -805,20 +811,22 @@ func landMergeTree(
}
var stdout, stderr bytes.Buffer
+ clean := true
if err := repo.ExecAndWait(ctx,
gitcmd.Command{Name: "merge-tree", Flags: flags, Args: []string{tip.String(), commitID.String()}},
gitcmd.WithStdout(&stdout),
gitcmd.WithStderr(&stderr),
); err != nil {
+ clean = false
// Exit status 1 means the merge has conflicts, and the tree is printed regardless.
if exitStatus, ok := command.ExitStatus(err); !ok || exitStatus != 1 {
- return "", nil, fmt.Errorf("merge-tree: %w, stderr: %q", err, stderr.String())
+ return "", nil, nil, false, fmt.Errorf("merge-tree: %w, stderr: %q", err, stderr.String())
}
}
objectHash, err := repo.ObjectHash(ctx)
if err != nil {
- return "", nil, fmt.Errorf("detecting object hash: %w", err)
+ return "", nil, nil, false, fmt.Errorf("detecting object hash: %w", err)
}
// The output is the tree OID, the conflicted file records and, after an empty field, the
@@ -826,12 +834,15 @@ func landMergeTree(
fields := strings.Split(stdout.String(), "\x00")
treeOID, err := objectHash.FromHex(fields[0])
if err != nil {
- return "", nil, fmt.Errorf("parsing merge tree: %w", err)
+ return "", nil, nil, false, fmt.Errorf("parsing merge tree: %w", err)
}
var conflicts []landFileConflict
index := map[string]int{}
- for _, record := range fields[1:] {
+ rest := fields[1:]
+ for len(rest) > 0 {
+ record := rest[0]
+ rest = rest[1:]
if record == "" {
break
}
@@ -839,12 +850,12 @@ func landMergeTree(
meta, p, ok := strings.Cut(record, "\t")
parts := strings.Fields(meta)
if !ok || p == "" || len(parts) != 3 {
- return "", nil, fmt.Errorf("unexpected conflicted file record %q", record)
+ return "", nil, nil, false, fmt.Errorf("unexpected conflicted file record %q", record)
}
oid, err := objectHash.FromHex(parts[1])
if err != nil {
- return "", nil, fmt.Errorf("parsing blob ID of %q: %w", p, err)
+ return "", nil, nil, false, fmt.Errorf("parsing blob ID of %q: %w", p, err)
}
i, found := index[p]
@@ -865,15 +876,47 @@ func landMergeTree(
case "3":
side = &c.theirs
default:
- return "", nil, fmt.Errorf("unexpected stage %q of conflicted path %q", parts[2], p)
+ return "", nil, nil, false, fmt.Errorf("unexpected stage %q of conflicted path %q", parts[2], p)
}
if *side != nil {
- return "", nil, fmt.Errorf("conflicted path %q has two entries of stage %s", p, parts[2])
+ return "", nil, nil, false, fmt.Errorf("conflicted path %q has two entries of stage %s", p, parts[2])
}
*side = &landBlob{mode: parts[0], oid: oid}
}
- return treeOID, conflicts, nil
+ messages, err := landMergeMessages(rest)
+ if err != nil {
+ return "", nil, nil, false, err
+ }
+ return treeOID, conflicts, messages, clean, nil
+}
+
+// landMergeMessage is one of merge-tree's messages about the merge.
+type landMergeMessage struct {
+ paths []string
+ kind string
+ message string
+}
+
+// landMergeMessages parses the informational messages of merge-tree -z, which follow the empty
+// field after the conflicted file records: each is the number of paths, the paths, the type (such
+// as "CONFLICT (rename/delete)" or "Auto-merging") and the message, NUL-terminated. The output ends
+// with a NUL, so the last field is empty.
+func landMergeMessages(fields []string) ([]landMergeMessage, error) {
+ var messages []landMergeMessage
+ for len(fields) > 0 && !(len(fields) == 1 && fields[0] == "") {
+ n, err := strconv.Atoi(fields[0])
+ if err != nil || n < 0 || len(fields) < n+3 {
+ return nil, fmt.Errorf("unexpected merge-tree message %q", fields)
+ }
+ messages = append(messages, landMergeMessage{
+ paths: slices.Clone(fields[1 : 1+n]),
+ kind: fields[1+n],
+ message: strings.TrimRight(fields[2+n], "\n"),
+ })
+ fields = fields[3+n:]
+ }
+ return messages, nil
}
// isLandMergeConflict reports whether a landing failed because the change does not apply cleanly
diff --git a/internal/gitaly/service/operations/land_resolve_rename_test.go b/internal/gitaly/service/operations/land_resolve_rename_test.go
index f5a71b1..645babf 100644
--- a/internal/gitaly/service/operations/land_resolve_rename_test.go
+++ b/internal/gitaly/service/operations/land_resolve_rename_test.go
@@ -186,7 +186,7 @@ func TestUserLand_renameFromDeniedPathIsNotResolved(t *testing.T) {
_, err := fx.server(t, rcfg).resolveLandConflicts(fx.ctx, fx.request("Land rename"), fx.repo, fx.tip, fx.commit, fx.committer())
var unresolved *landUnresolvedError
require.ErrorAs(t, err, &unresolved)
- k := packageFile(t, unresolved.pkg, "pub/k")
+ k := packageFile(t, builtPackage(t, fx.ctx, unresolved), "pub/k")
require.Equal(t, gitalypb.LandConflictFile_OUTCOME_NOT_SENT, k.GetOutcome())
require.Equal(t, `a side comes from path "secrets/k", which may not be sent to the resolver`, k.GetReason())
require.Equal(t, 0, resolverCalls(t, dir))
diff --git a/internal/gitaly/service/operations/land_resolve_test.go b/internal/gitaly/service/operations/land_resolve_test.go
index 6285d70..2a91896 100644
--- a/internal/gitaly/service/operations/land_resolve_test.go
+++ b/internal/gitaly/service/operations/land_resolve_test.go
@@ -512,10 +512,10 @@ func TestResolveLandConflicts_policy(t *testing.T) {
_, err := s.resolveLandConflicts(fx.ctx, fx.request("Land"), fx.repo, fx.tip, fx.commit, fx.committer())
var unresolved *landUnresolvedError
require.ErrorAs(t, err, &unresolved)
- a := packageFile(t, unresolved.pkg, "a")
+ a := packageFile(t, builtPackage(t, fx.ctx, unresolved), "a")
require.Equal(t, gitalypb.LandConflictFile_OUTCOME_NOT_SENT, a.GetOutcome())
require.Equal(t, landNotSentDenied, a.GetReason())
- require.Equal(t, gitalypb.LandConflictFile_OUTCOME_RESOLVED, packageFile(t, unresolved.pkg, "b").GetOutcome())
+ require.Equal(t, gitalypb.LandConflictFile_OUTCOME_RESOLVED, packageFile(t, builtPackage(t, fx.ctx, unresolved), "b").GetOutcome())
require.Equal(t, 1, resolverCalls(t, dir))
req := resolverRequest(t, dir, 1)
@@ -550,8 +550,10 @@ func TestResolveLandConflicts_policy(t *testing.T) {
_, err := s.resolveLandConflicts(fx.ctx, fx.request("Land"), fx.repo, fx.tip, fx.commit, fx.committer())
var unresolved *landUnresolvedError
require.ErrorAs(t, err, &unresolved)
- require.Contains(t, unresolved.pkg.GetReason(), tc.reason)
- for _, f := range unresolved.pkg.GetFiles() {
+ pkg := builtPackage(t, fx.ctx, unresolved)
+ require.Contains(t, pkg.GetReason(), tc.reason)
+ require.Len(t, pkg.GetFiles(), 2, "the package lists every conflicting file, whatever max_files")
+ for _, f := range pkg.GetFiles() {
require.Equal(t, gitalypb.LandConflictFile_OUTCOME_NOT_ATTEMPTED, f.GetOutcome())
}
require.Equal(t, 0, resolverCalls(t, dir))
@@ -656,13 +658,47 @@ func TestNewServer_warnsWhenResolverActorsMatchNobody(t *testing.T) {
}
}
-func TestLandTrailerSafe(t *testing.T) {
+func TestLandTrailerValueValid(t *testing.T) {
t.Parallel()
- require.True(t, landTrailerSafe("a/b c.go"))
- require.False(t, landTrailerSafe("a\nGraft-Resolved-By: evil"))
- require.False(t, landTrailerSafe("a\rb"))
- require.False(t, landTrailerSafe("a\x00b"))
+ require.True(t, landTrailerValueValid("a/b c.go"))
+ require.True(t, landTrailerValueValid("résumé.md"))
+ for _, v := range []string{
+ "",
+ "a\nGraft-Resolved-By: evil",
+ "a\rb",
+ "a\x00b",
+ "a\tb",
+ "a
b",
+ "a\u0085b",
+ "a\xffb",
+ } {
+ require.False(t, landTrailerValueValid(v), "%q", v)
+ }
+}
+
+func TestLandResolutionTrailers(t *testing.T) {
+ t.Parallel()
+
+ got, err := landResolutionTrailers("agent/a", "graft-resolve", []string{"a", "dir/b c"})
+ require.NoError(t, err)
+ require.Equal(t, "Graft-Resolved-By: agent/a\nGraft-Checked-By: graft-resolve\nGraft-Resolved-Path: a\nGraft-Resolved-Path: dir/b c\n", got)
+
+ for name, tc := range map[string]struct {
+ resolver, checkedBy string
+ paths []string
+ trailer string
+ }{
+ "resolver": {resolver: "agent/x\nGraft-Resolved-Path: evil", paths: []string{"a"}, trailer: landTrailerResolvedBy},
+ "no name": {resolver: "", paths: []string{"a"}, trailer: landTrailerResolvedBy},
+ "checked by": {resolver: "agent", checkedBy: "c\rd", paths: []string{"a"}, trailer: landTrailerCheckedBy},
+ "path": {resolver: "agent", paths: []string{"a", lineBreakPath}, trailer: landTrailerResolvedPath},
+ } {
+ _, err := landResolutionTrailers(tc.resolver, tc.checkedBy, tc.paths)
+ var unsafe *landTrailerUnsafeError
+ require.ErrorAs(t, err, &unsafe, name)
+ require.Equal(t, tc.trailer, unsafe.trailer, name)
+ }
}
func TestLandResolverNameValid(t *testing.T) {
@@ -703,18 +739,22 @@ func TestLandResolveCommitMessage(t *testing.T) {
t.Run("merge message", func(t *testing.T) {
in := &gitalypb.UserLandRequest{Branch: []byte("main"), MergeMessage: []byte("Custom\n\n")}
- require.Equal(t,
- "Custom\n\nGraft-Resolved-By: graft-resolve/x\nGraft-Resolved-Path: a\nGraft-Resolved-Path: dir/b c\n",
- landResolveCommitMessage(in, commit, "graft-resolve/x", "", []string{"a", "dir/b c"}),
- )
+ msg, err := landResolveCommitMessage(in, commit, "graft-resolve/x", "", []string{"a", "dir/b c"})
+ require.NoError(t, err)
+ require.Equal(t, "Custom\n\nGraft-Resolved-By: graft-resolve/x\nGraft-Resolved-Path: a\nGraft-Resolved-Path: dir/b c\n", msg)
})
t.Run("default message", func(t *testing.T) {
in := &gitalypb.UserLandRequest{Branch: []byte("main")}
- require.Equal(t,
- "Merge 1111111 into main\n\nGraft-Resolved-By: graft-resolve/x\nGraft-Resolved-Path: a\n",
- landResolveCommitMessage(in, commit, "graft-resolve/x", "", []string{"a"}),
- )
+ msg, err := landResolveCommitMessage(in, commit, "graft-resolve/x", "", []string{"a"})
+ require.NoError(t, err)
+ require.Equal(t, "Merge 1111111 into main\n\nGraft-Resolved-By: graft-resolve/x\nGraft-Resolved-Path: a\n", msg)
+ })
+
+ t.Run("a path that is no trailer line is refused", func(t *testing.T) {
+ in := &gitalypb.UserLandRequest{Branch: []byte("main")}
+ _, err := landResolveCommitMessage(in, commit, "graft-resolve/x", "", []string{lineBreakPath})
+ require.Error(t, err)
})
}
diff --git a/internal/gitaly/service/operations/land_test.go b/internal/gitaly/service/operations/land_test.go
index 7bbd01b..3f5a113 100644
--- a/internal/gitaly/service/operations/land_test.go
+++ b/internal/gitaly/service/operations/land_test.go
@@ -551,6 +551,10 @@ func TestUserLand_validation(t *testing.T) {
{desc: "empty commit ID", modify: func(r *gitalypb.UserLandRequest) { r.CommitId = "" }},
{desc: "unknown strategy", modify: func(r *gitalypb.UserLandRequest) { r.Strategy = gitalypb.UserLandRequest_Strategy(42) }},
{desc: "negative max attempts", modify: func(r *gitalypb.UserLandRequest) { r.MaxAttempts = -1 }},
+ {desc: "resolution with fast-forward only", modify: func(r *gitalypb.UserLandRequest) {
+ r.Strategy = gitalypb.UserLandRequest_STRATEGY_FF_ONLY
+ r.Resolution = &gitalypb.LandResolution{Tip: base.String(), Commit: child.String()}
+ }},
} {
t.Run(tc.desc, func(t *testing.T) {
request := landRequest(repoProto, git.DefaultBranch, child)
diff --git a/internal/gitaly/service/operations/land_trailers.go b/internal/gitaly/service/operations/land_trailers.go
new file mode 100644
index 0000000..ab7ad2c
--- /dev/null
+++ b/internal/gitaly/service/operations/land_trailers.go
@@ -0,0 +1,71 @@
+package operations
+
+import (
+ "fmt"
+ "strings"
+ "unicode"
+ "unicode/utf8"
+)
+
+// The Graft-* trailers of a resolution commit. graft-verify and superfan read them back, so every
+// value must stay one trailer line: landResolutionTrailers is the only place that writes them.
+const (
+ landTrailerResolvedBy = "Graft-Resolved-By"
+ landTrailerCheckedBy = "Graft-Checked-By"
+ landTrailerResolvedPath = "Graft-Resolved-Path"
+)
+
+// landTrailerValueValid reports whether v can be the value of a commit trailer as it is: non-empty,
+// valid UTF-8, and printable. unicode.IsPrint admits the ASCII space only, so line breaks (also
+// U+0085, U+2028 and U+2029), NUL, tab, escape sequences and format characters are all refused: a
+// value can never start another trailer or hide part of itself.
+func landTrailerValueValid(v string) bool {
+ if v == "" || !utf8.ValidString(v) {
+ return false
+ }
+ for _, r := range v {
+ if !unicode.IsPrint(r) {
+ return false
+ }
+ }
+ return true
+}
+
+// landTrailerUnsafeError is the refusal of a value that landTrailerValueValid rejects.
+type landTrailerUnsafeError struct {
+ trailer, value string
+}
+
+func (e *landTrailerUnsafeError) Error() string {
+ return fmt.Sprintf("%s %q cannot be written as a commit trailer: it must be one line of printable UTF-8", e.trailer, e.value)
+}
+
+// landResolutionTrailers returns the trailer block of a resolution commit: Graft-Resolved-By with
+// the resolver's name, Graft-Checked-By with the name of the resolver that checked an agent's
+// resolution (when one did), and one Graft-Resolved-Path per resolved path. It refuses, with a
+// *landTrailerUnsafeError, any value that landTrailerValueValid rejects; nothing is ever escaped.
+func landResolutionTrailers(resolverName, checkedBy string, paths []string) (string, error) {
+ var b strings.Builder
+ add := func(trailer, value string) error {
+ if !landTrailerValueValid(value) {
+ return &landTrailerUnsafeError{trailer: trailer, value: value}
+ }
+ b.WriteString(trailer + ": " + value + "\n")
+ return nil
+ }
+
+ if err := add(landTrailerResolvedBy, resolverName); err != nil {
+ return "", err
+ }
+ if checkedBy != "" {
+ if err := add(landTrailerCheckedBy, checkedBy); err != nil {
+ return "", err
+ }
+ }
+ for _, p := range paths {
+ if err := add(landTrailerResolvedPath, p); err != nil {
+ return "", err
+ }
+ }
+ return b.String(), nil
+}
diff --git a/internal/graft/merge3/merge3.go b/internal/graft/merge3/merge3.go
index 0c24f37..93a7ebf 100644
--- a/internal/graft/merge3/merge3.go
+++ b/internal/graft/merge3/merge3.go
@@ -133,10 +133,12 @@ type Labels struct {
// WithMarkers returns the merged text: the regions that only one side changed (or both the same
// way) take that change, and every conflicting region is written between git's diff3 conflict
// markers, "<<<<<<< ours", "||||||| base", "=======" and ">>>>>>> theirs", followed by the labels.
-// A side of a conflict that does not end with a newline gets one before the next marker.
+// A side of a conflict that does not end with a newline gets one before the next marker. The
+// markers and that newline end with CRLF when git's would (crlfNeeded), LF otherwise.
func (r *Result) WithMarkers(l Labels) []byte {
var out bytes.Buffer
pos := 0
+ eol := "\n"
write := func(lines [][]byte) {
for _, line := range lines {
out.Write(line)
@@ -145,7 +147,7 @@ func (r *Result) WithMarkers(l Labels) []byte {
writeSide := func(lines [][]byte) {
write(lines)
if out.Len() > 0 && out.Bytes()[out.Len()-1] != '\n' {
- out.WriteByte('\n')
+ out.WriteString(eol)
}
}
marker := func(m, label string) {
@@ -153,13 +155,17 @@ func (r *Result) WithMarkers(l Labels) []byte {
if label != "" {
out.WriteString(" " + label)
}
- out.WriteByte('\n')
+ out.WriteString(eol)
}
for _, reg := range r.regions {
write(r.base[pos:reg.base.Start])
pos = reg.base.End
switch {
case reg.conflict:
+ eol = "\n"
+ if r.crlfNeeded(reg) {
+ eol = "\r\n"
+ }
marker("<<<<<<<", l.Ours)
writeSide(r.ours[reg.ours.Start:reg.ours.End])
marker("|||||||", l.Base)
@@ -177,6 +183,52 @@ func (r *Result) WithMarkers(l Labels) []byte {
return out.Bytes()
}
+// crlfNeeded reports whether the markers of the conflicting region reg end with CRLF, as git's
+// do: the line of ours before the conflict (its first line when the conflict starts the file), the
+// same line of theirs, and the first line of the base must all end with CRLF. A side whose line
+// ending cannot be told (an empty side, or a single line without one) does not decide, but when
+// the base cannot tell, the markers end with LF.
+func (r *Result) crlfNeeded(reg region) bool {
+ before := func(start int) int { return max(start-1, 0) }
+ if lineEndingOf(r.ours, before(reg.ours.Start)) == endingLF {
+ return false
+ }
+ if lineEndingOf(r.theirs, before(reg.theirs.Start)) == endingLF {
+ return false
+ }
+ return lineEndingOf(r.base, 0) == endingCRLF
+}
+
+// lineEnding is the line ending of a line, for crlfNeeded.
+type lineEnding int
+
+const (
+ endingUnknown lineEnding = iota
+ endingLF
+ endingCRLF
+)
+
+// lineEndingOf returns the line ending of line i of lines. The last line of a file may have none:
+// its ending is then the one of the line before it, and unknown when there is none.
+func lineEndingOf(lines [][]byte, i int) lineEnding {
+ ending := func(line []byte) lineEnding {
+ if bytes.HasSuffix(line, []byte("\r\n")) {
+ return endingCRLF
+ }
+ return endingLF
+ }
+ switch {
+ case len(lines) == 0:
+ return endingUnknown
+ case i < len(lines)-1 || bytes.HasSuffix(lines[i], []byte("\n")):
+ return ending(lines[i])
+ case i == 0:
+ return endingUnknown
+ default:
+ return ending(lines[i-1])
+ }
+}
+
func sameLines(a, b [][]byte) bool {
if len(a) != len(b) {
return false
@@ -201,6 +253,39 @@ func SplitLines(b []byte) [][]byte {
return parts
}
+// Cost returns the cells of the two line-diff tables that Merge of base, ours and theirs fills, so
+// that a caller can bound the work of many merges, and whether both fit MaxCells: when one does
+// not, Merge fails at no cost, and cells is 0. Cost splits the lines and compares the common prefix
+// and suffix, which takes time linear in the size of the files.
+func Cost(base, ours, theirs []byte) (cells int, fits bool) {
+ b := SplitLines(base)
+ for _, side := range [][]byte{ours, theirs} {
+ s := SplitLines(side)
+ pre, suf := trim(b, s)
+ n, m := len(b)-pre-suf, len(s)-pre-suf
+ if n == 0 && m == 0 {
+ continue
+ }
+ if (n+1)*(m+1) > MaxCells {
+ return 0, false
+ }
+ cells += (n + 1) * (m + 1)
+ }
+ return cells, true
+}
+
+// trim returns the number of lines that a and b share at their start and, after those, at their
+// end.
+func trim(a, b [][]byte) (pre, suf int) {
+ for pre < len(a) && pre < len(b) && bytes.Equal(a[pre], b[pre]) {
+ pre++
+ }
+ for suf < len(a)-pre && suf < len(b)-pre && bytes.Equal(a[len(a)-1-suf], b[len(b)-1-suf]) {
+ suf++
+ }
+ return pre, suf
+}
+
// edit replaces the base lines [start, end) with n lines of a side.
type edit struct {
start, end int
@@ -210,14 +295,7 @@ type edit struct {
// lineDiff returns the line edits that turn a into b, from a longest common subsequence of the
// lines after the common prefix and suffix. It returns false when the table would exceed MaxCells.
func lineDiff(a, b [][]byte) ([]edit, bool) {
- pre := 0
- for pre < len(a) && pre < len(b) && bytes.Equal(a[pre], b[pre]) {
- pre++
- }
- suf := 0
- for suf < len(a)-pre && suf < len(b)-pre && bytes.Equal(a[len(a)-1-suf], b[len(b)-1-suf]) {
- suf++
- }
+ pre, suf := trim(a, b)
am, bm := a[pre:len(a)-suf], b[pre:len(b)-suf]
n, m := len(am), len(bm)
if n == 0 && m == 0 {
diff --git a/internal/graft/merge3/merge3_test.go b/internal/graft/merge3/merge3_test.go
index 758f5fe..99a9422 100644
--- a/internal/graft/merge3/merge3_test.go
+++ b/internal/graft/merge3/merge3_test.go
@@ -75,6 +75,43 @@ func TestMerge(t *testing.T) {
hunks: []Hunk{{Base: Range{1, 2}, Ours: Range{1, 1}, Theirs: Range{1, 2}}},
markers: "1\n<<<<<<< ours\n||||||| base\n2\n=======\nT\n>>>>>>> theirs\n3\n",
},
+ // The CRLF cases are the output of git merge-file -p --diff3 on the same files.
+ {
+ name: "CRLF markers in a CRLF file",
+ base: "1\r\n2\r\n3\r\n", ours: "1\r\nO\r\n3\r\n", theirs: "1\r\nT\r\n3\r\n",
+ hunks: []Hunk{{Base: Range{1, 2}, Ours: Range{1, 2}, Theirs: Range{1, 2}}},
+ markers: "1\r\n<<<<<<< ours\r\nO\r\n||||||| base\r\n2\r\n=======\r\nT\r\n>>>>>>> theirs\r\n3\r\n",
+ },
+ {
+ name: "CRLF: a side without a final newline gets CRLF",
+ base: "1\r\n2", ours: "1\r\nO", theirs: "1\r\nT",
+ hunks: []Hunk{{Base: Range{1, 2}, Ours: Range{1, 2}, Theirs: Range{1, 2}}},
+ markers: "1\r\n<<<<<<< ours\r\nO\r\n||||||| base\r\n2\r\n=======\r\nT\r\n>>>>>>> theirs\r\n",
+ },
+ {
+ name: "CRLF: a conflict on the first line",
+ base: "1\r\n2\r\n", ours: "O\r\n2\r\n", theirs: "T\r\n2\r\n",
+ hunks: []Hunk{{Base: Range{0, 1}, Ours: Range{0, 1}, Theirs: Range{0, 1}}},
+ markers: "<<<<<<< ours\r\nO\r\n||||||| base\r\n1\r\n=======\r\nT\r\n>>>>>>> theirs\r\n2\r\n",
+ },
+ {
+ name: "CRLF sides with an LF base get LF markers",
+ base: "1\n2\n3\n", ours: "1\r\nO\r\n3\r\n", theirs: "1\r\nT\r\n3\r\n",
+ hunks: []Hunk{{Base: Range{0, 3}, Ours: Range{0, 3}, Theirs: Range{0, 3}}},
+ markers: "<<<<<<< ours\n1\r\nO\r\n3\r\n||||||| base\n1\n2\n3\n=======\n1\r\nT\r\n3\r\n>>>>>>> theirs\n",
+ },
+ {
+ name: "CRLF sides without a base get LF markers",
+ base: "", ours: "o\r\n", theirs: "t\r\n",
+ hunks: []Hunk{{Base: Range{0, 0}, Ours: Range{0, 1}, Theirs: Range{0, 1}}},
+ markers: "<<<<<<< ours\no\r\n||||||| base\n=======\nt\r\n>>>>>>> theirs\n",
+ },
+ {
+ name: "CRLF sides whose base has no line ending get LF markers",
+ base: "1", ours: "O\r\n", theirs: "T\r\n",
+ hunks: []Hunk{{Base: Range{0, 1}, Ours: Range{0, 1}, Theirs: Range{0, 1}}},
+ markers: "<<<<<<< ours\nO\r\n||||||| base\n1\n=======\nT\r\n>>>>>>> theirs\n",
+ },
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
@@ -87,6 +124,37 @@ func TestMerge(t *testing.T) {
}
}
+func TestCost(t *testing.T) {
+ t.Parallel()
+
+ // Only the changed middle counts: base 1..5 against ours with line 3 changed is a 2x2 table,
+ // and theirs equal to the base costs nothing.
+ cost := func(base, ours, theirs string) (int, bool) { return Cost([]byte(base), []byte(ours), []byte(theirs)) }
+ requireCost := func(cells int, fits bool, gotCells int, gotFits bool) {
+ t.Helper()
+ require.Equal(t, cells, gotCells)
+ require.Equal(t, fits, gotFits)
+ }
+ c, ok := cost("1\n2\n3\n4\n5\n", "1\n2\nO\n4\n5\n", "1\n2\n3\n4\n5\n")
+ requireCost(4, true, c, ok)
+ c, ok = cost("a\n", "a\n", "a\n")
+ requireCost(0, true, c, ok)
+ // An add/add conflict diffs each side against the empty base: (0+1)*(2+1) + (0+1)*(1+1).
+ c, ok = cost("", "o1\no2\n", "t1\n")
+ requireCost(5, true, c, ok)
+
+ // One table over MaxCells: Merge fails, and Cost says so.
+ var a, b strings.Builder
+ for i := 0; i < 3000; i++ {
+ a.WriteString("a\n")
+ b.WriteString("b\n")
+ }
+ c, ok = cost(a.String(), b.String(), a.String())
+ requireCost(0, false, c, ok)
+ _, merged := Merge([]byte(a.String()), []byte(b.String()), []byte(a.String()))
+ require.False(t, merged)
+}
+
func TestMergeTooLarge(t *testing.T) {
t.Parallel()
diff --git a/internal/graft/resolver/check.go b/internal/graft/resolver/check.go
index 3e3838b..b39f934 100644
--- a/internal/graft/resolver/check.go
+++ b/internal/graft/resolver/check.go
@@ -25,7 +25,7 @@ func (c *Client) Check(ctx context.Context, req Request) (*CheckResponse, error)
req.Operation = OperationCheck
req.Limits = Limits{MaxFileBytes: c.maxFileBytes}
- if err := c.checkRequest(req); err != nil {
+ if err := c.checkFiles(req); err != nil {
return nil, err
}
if len(req.Resolution) != len(req.Files) {
diff --git a/internal/graft/resolver/client.go b/internal/graft/resolver/client.go
index 6ca2f4c..a63b749 100644
--- a/internal/graft/resolver/client.go
+++ b/internal/graft/resolver/client.go
@@ -41,11 +41,21 @@ type UnresolvableError struct {
// validOutcomes returns files when it has exactly one entry per requested path
// with a known outcome, and nil otherwise: a malformed list is not trusted in
-// part.
+// part. A refusal whose every file is resolved contradicts itself and is
+// malformed too.
func validOutcomes(req Request, files []FileOutcome) []FileOutcome {
if len(files) != len(req.Files) {
return nil
}
+ unresolved := false
+ for _, f := range files {
+ if f.Outcome != OutcomeResolved {
+ unresolved = true
+ }
+ }
+ if !unresolved {
+ return nil
+ }
want := make(map[string]bool, len(req.Files))
for _, f := range req.Files {
want[f.Path] = true
@@ -181,7 +191,10 @@ func (c *Client) Resolve(ctx context.Context, req Request) (*Response, error) {
req.Version = ProtocolVersion
req.Limits = Limits{MaxFileBytes: c.maxFileBytes}
- if err := c.checkRequest(req); err != nil {
+ if err := c.checkResolvePolicy(req); err != nil {
+ return nil, err
+ }
+ if err := c.checkFiles(req); err != nil {
return nil, err
}
@@ -226,10 +239,11 @@ func (c *Client) Resolve(ctx context.Context, req Request) (*Response, error) {
return &resp, nil
}
-// checkRequest enforces the client's limits and policy on an outgoing request:
-// file count, per-side size, clean unique UTF-8 paths, known kinds, the path
-// policy and the actor policy.
-func (c *Client) checkRequest(req Request) error {
+// checkResolvePolicy enforces what bounds a request for an AI resolution only:
+// max_files and the actor policy. The check of an agent's resolution is not
+// such a request: it runs for every actor that may land, on every file the
+// agent resolved (PLAN10 12).
+func (c *Client) checkResolvePolicy(req Request) error {
if len(req.Files) > c.maxFiles {
return fmt.Errorf("resolve request has %d conflicted files, limit is %d", len(req.Files), c.maxFiles)
}
@@ -237,7 +251,13 @@ func (c *Client) checkRequest(req Request) error {
if !c.ActorAllowed(req.Actor) {
return fmt.Errorf("actor %q may not request conflict resolution", req.Actor)
}
+ return nil
+}
+// checkFiles enforces the client's rules on the files of an outgoing request,
+// a resolve or a check: per-side size, clean unique UTF-8 paths, known kinds
+// and the path policy.
+func (c *Client) checkFiles(req Request) error {
seen := make(map[string]struct{}, len(req.Files))
for _, f := range req.Files {
if !cleanRelPath(f.Path) {
diff --git a/internal/graft/resolver/client_test.go b/internal/graft/resolver/client_test.go
index a81f003..e525e9c 100644
--- a/internal/graft/resolver/client_test.go
+++ b/internal/graft/resolver/client_test.go
@@ -406,6 +406,35 @@ func TestResolve_CommandGetsMinimalEnvironment(t *testing.T) {
require.Contains(t, string(raw), "PATH=")
}
+// TestCheck_runsForEveryActorAndFileCount: actors and max_files bound requests for an AI
+// resolution only; the check of an agent's resolution runs whatever the actor and the number of
+// files (PLAN10 12), while a resolve request with the same actor and files is refused.
+func TestCheck_runsForEveryActorAndFileCount(t *testing.T) {
+ requireUnix(t)
+
+ req := sampleRequest()
+ req.Resolution = validResponse("merged\n").Files
+ answer, err := json.Marshal(CheckResponse{
+ Version: ProtocolVersion, Operation: OperationCheck, Resolver: "graft-resolve",
+ Files: []CheckFile{{Path: "a.txt", OK: true, Syntax: SyntaxNone}, {Path: "b.txt", OK: true, Syntax: SyntaxNone}},
+ })
+ require.NoError(t, err)
+ cfg := commandConfig(cannedCommand(t, answer))
+ cfg.MaxFiles = 1
+ cfg.Actors = []string{"someone-else"}
+ client := newClient(t, cfg)
+
+ resp, err := client.Check(testhelper.Context(t), req)
+ require.NoError(t, err)
+ require.Len(t, resp.Files, 2)
+
+ _, err = client.Resolve(testhelper.Context(t), req)
+ require.ErrorContains(t, err, "2 conflicted files, limit is 1")
+ cfg.MaxFiles = 0
+ _, err = newClient(t, cfg).Resolve(testhelper.Context(t), req)
+ require.ErrorContains(t, err, `actor "agent-7" may not request conflict resolution`)
+}
+
func TestResolve_RequestChecksDoNotRunTheResolver(t *testing.T) {
requireUnix(t)
@@ -569,6 +598,7 @@ func TestValidOutcomes(t *testing.T) {
"duplicate": {{Path: "a", Outcome: OutcomeResolved}, {Path: "a", Outcome: OutcomeFailed}},
"unknown path": {{Path: "a", Outcome: OutcomeResolved}, {Path: "z", Outcome: OutcomeFailed}},
"unknown status": {{Path: "a", Outcome: OutcomeResolved}, {Path: "b", Outcome: "maybe"}},
+ "all resolved": {{Path: "a", Outcome: OutcomeResolved}, {Path: "b", Outcome: OutcomeResolved}},
} {
require.Nil(t, validOutcomes(req, files), name)
}
diff --git a/internal/graft/resolver/validate.go b/internal/graft/resolver/validate.go
index 65354b0..ea9e8aa 100644
--- a/internal/graft/resolver/validate.go
+++ b/internal/graft/resolver/validate.go
@@ -4,6 +4,8 @@ import (
"bytes"
"errors"
"fmt"
+ "path"
+ "strings"
)
// Validate applies the server's acceptance rules to a resolver answer. An
@@ -78,6 +80,12 @@ func validateFile(f ResponseFile, maxBytes int64) error {
return fmt.Errorf("invalid mode %q for write", f.Mode)
}
+ if f.Mode == ModeSymlink {
+ if special := gitSpecialFile(path.Base(f.Path)); special != "" {
+ return fmt.Errorf("a symbolic link named %s is refused: git fsck and checkout do not allow %s, .gitmodules, .gitattributes, .gitignore and .mailmap to be symbolic links", path.Base(f.Path), special)
+ }
+ }
+
if int64(len(f.Content)) > maxBytes {
return fmt.Errorf("content is %d bytes, limit is %d", len(f.Content), maxBytes)
}
@@ -102,6 +110,59 @@ func validateFile(f ResponseFile, maxBytes int64) error {
}
}
+// gitSpecialFiles are the files git reads from the tree itself, which must not be symbolic links
+// (git fsck: gitmodulesSymlink, gitattributesSymlink, gitignoreSymlink, mailmapSymlink), each with
+// the stem of its NTFS short name when it is not the first six letters of its name.
+var gitSpecialFiles = []struct {
+ name, shortHash string
+}{
+ {".gitmodules", "gi7eba"},
+ {".gitattributes", "gi7d29"},
+ {".gitignore", "gi250a"},
+ {".mailmap", "maba30"},
+}
+
+// gitSpecialFile returns the special file that the tree entry name stands for on some file
+// system, or "". git compares names the way the file systems that check out the tree do:
+// - case-insensitively, and ignoring the code points that HFS+ ignores (zero-width and
+// directional marks, U+FEFF);
+// - on NTFS, also with trailing spaces and dots, an alternate data stream (":stream"), and as
+// an 8.3 short name: the first six letters of the name, or the stem above, then "~" and a
+// digit.
+func gitSpecialFile(name string) string {
+ folded := strings.ToLower(strings.Map(func(r rune) rune {
+ if hfsIgnorable(r) {
+ return -1
+ }
+ return r
+ }, name))
+ ntfs := strings.ToLower(name)
+ if i := strings.IndexByte(ntfs, ':'); i >= 0 {
+ ntfs = ntfs[:i]
+ }
+ ntfs = strings.TrimRight(ntfs, " .")
+ for _, s := range gitSpecialFiles {
+ if folded == s.name || ntfs == s.name {
+ return s.name
+ }
+ for _, stem := range []string{s.name[1:7], s.shortHash} {
+ if len(ntfs) == len(stem)+2 && strings.HasPrefix(ntfs, stem+"~") && ntfs[len(stem)+1] >= '1' && ntfs[len(stem)+1] <= '9' {
+ return s.name
+ }
+ }
+ }
+ return ""
+}
+
+// hfsIgnorable reports whether HFS+ ignores r when it compares names.
+func hfsIgnorable(r rune) bool {
+ switch {
+ case r >= 0x200c && r <= 0x200f, r >= 0x202a && r <= 0x202e, r >= 0x206a && r <= 0x206f, r == 0xfeff:
+ return true
+ }
+ return false
+}
+
// validMode reports whether mode is a git file mode the server accepts.
func validMode(mode string) bool {
switch mode {
diff --git a/internal/graft/resolver/validate_test.go b/internal/graft/resolver/validate_test.go
index b98138f..b4a1c92 100644
--- a/internal/graft/resolver/validate_test.go
+++ b/internal/graft/resolver/validate_test.go
@@ -283,3 +283,24 @@ func TestValidate_Errors(t *testing.T) {
require.False(t, errors.Is(err, ErrInvalidResponse))
})
}
+
+func TestValidateFile_specialFileSymlinks(t *testing.T) {
+ t.Parallel()
+
+ for _, name := range []string{
+ ".gitmodules", "sub/.gitattributes", ".gitignore", ".mailmap",
+ ".GITMODULES", ".gitmodules ", ".gitmodules...", ".gitmodules::$DATA",
+ "GITMOD~1", "gi7eba~4", "GI7D29~1", "maba30~2", "gitign~1",
+ // HFS+ ignores zero-width code points.
+ ".git\u200cmodules", "\ufeff.gitattributes",
+ } {
+ err := ValidateFile(ResponseFile{Path: name, Action: ActionWrite, Mode: ModeSymlink, Content: []byte("target")}, 1<<20)
+ require.ErrorContains(t, err, "is refused", "%q", name)
+ // As a regular file the name is fine.
+ require.NoError(t, ValidateFile(ResponseFile{Path: name, Action: ActionWrite, Mode: ModeRegular, Content: []byte("x")}, 1<<20), "%q", name)
+ }
+
+ for _, name := range []string{".gitmodules-old", "gitmodules", "GITMOD~A", "gitmod~10", "x.gitignore", "link"} {
+ require.NoError(t, ValidateFile(ResponseFile{Path: name, Action: ActionWrite, Mode: ModeSymlink, Content: []byte("target")}, 1<<20), "%q", name)
+ }
+}
diff --git a/internal/graft/workspace/land_resolve_test.go b/internal/graft/workspace/land_resolve_test.go
index b61e662..28eb3ac 100644
--- a/internal/graft/workspace/land_resolve_test.go
+++ b/internal/graft/workspace/land_resolve_test.go
@@ -134,6 +134,10 @@ func TestLandResolutionLandsTheResolvedFiles(t *testing.T) {
_, err = ws.LandResolution(context.Background(), "", committer, &Resolution{Tip: tip, Commit: "other", Files: nil})
require.ErrorContains(t, err, "not the pending commit")
+ // The backend refuses it too, as the server does, for a caller that goes around the workspace.
+ _, err = b.Land(context.Background(), LandOptions{Branch: "main", Commit: pending, Strategy: StrategyMerge, Committer: committer,
+ Resolution: &Resolution{Tip: tip, Commit: "other", Files: []ResolvedFile{{Path: "a.txt", Mode: "100644", Content: []byte("both")}}}})
+ require.ErrorContains(t, err, `the resolution is for commit "other"`)
res, err := ws.LandResolution(context.Background(), "", committer, &Resolution{Tip: tip, Commit: pending,
Files: []ResolvedFile{{Path: "a.txt", Mode: "100644", Content: []byte("both")}}})
diff --git a/internal/graft/workspace/memory.go b/internal/graft/workspace/memory.go
index decbb99..9dd2464 100644
--- a/internal/graft/workspace/memory.go
+++ b/internal/graft/workspace/memory.go
@@ -295,6 +295,10 @@ func (m *MemoryBackend) Land(_ context.Context, opts LandOptions) (LandResult, e
// Three-way merge of the commit's changes (relative to its parent) onto the tip. With a
// resolution, the conflicting names take the resolved files, as the server's merge commit
// does; the resolution must be made against this tip and resolve exactly those names.
+ // As on the server, a resolution for another commit is refused, whatever its files.
+ if opts.Resolution != nil && opts.Resolution.Commit != id {
+ return LandResult{}, fmt.Errorf("the resolution is for commit %q, not commit %q", opts.Resolution.Commit, id)
+ }
if opts.Resolution != nil && opts.Resolution.Tip != tip {
return LandResult{}, fmt.Errorf("the resolution was made against tip %s, the branch is at %s: %w", opts.Resolution.Tip, tip, ErrMergeConflict)
}
diff --git a/proto/go/gitalypb/operations.pb.go b/proto/go/gitalypb/operations.pb.go
index 66b47a2..7df5e11 100644
--- a/proto/go/gitalypb/operations.pb.go
+++ b/proto/go/gitalypb/operations.pb.go
@@ -377,7 +377,7 @@ func (x LandResolvedFile_Action) Number() protoreflect.EnumNumber {
// Deprecated: Use LandResolvedFile_Action.Descriptor instead.
func (LandResolvedFile_Action) EnumDescriptor() ([]byte, []int) {
- return file_operations_proto_rawDescGZIP(), []int{56, 0}
+ return file_operations_proto_rawDescGZIP(), []int{57, 0}
}
// UserCreateBranchRequest is a request for the UserCreateBranch RPC.
@@ -4866,12 +4866,16 @@ type LandConflict struct {
CommitMessage []byte `protobuf:"bytes,5,opt,name=commit_message,json=commitMessage,proto3" json:"commit_message,omitempty"`
// messages_truncated is set when a message was cut.
MessagesTruncated bool `protobuf:"varint,6,opt,name=messages_truncated,json=messagesTruncated,proto3" json:"messages_truncated,omitempty"`
- // files are the conflicting files, at most max_files of them.
+ // files are all the conflicting files. A merge with more than 1000 conflicting
+ // files gets no package files: reason says so, and it cannot be resolved through a
+ // land.
Files []*LandConflictFile `protobuf:"bytes,7,rep,name=files,proto3" json:"files,omitempty"`
// reason is set when the server did not try to resolve the request at all, for
// example because it has too many files or the actor may not resolve; it is cut to
// 512 bytes.
- Reason string `protobuf:"bytes,8,opt,name=reason,proto3" json:"reason,omitempty"`
+ Reason string `protobuf:"bytes,8,opt,name=reason,proto3" json:"reason,omitempty"`
+ // messages are the messages of the merge about its conflicts, at most 1000.
+ Messages []*LandConflictMessage `protobuf:"bytes,9,rep,name=messages,proto3" json:"messages,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -4962,6 +4966,13 @@ func (x *LandConflict) GetReason() string {
return ""
}
+func (x *LandConflict) GetMessages() []*LandConflictMessage {
+ if x != nil {
+ return x.Messages
+ }
+ return nil
+}
+
// LandConflictFile is one conflicting file of a LandConflict.
type LandConflictFile struct {
state protoimpl.MessageState `protogen:"open.v1"`
@@ -4985,8 +4996,13 @@ type LandConflictFile struct {
// syntax_unchecked is set when a resolution of the file was accepted without a
// syntax verdict, because a side does not parse with the grammar of its language.
SyntaxUnchecked bool `protobuf:"varint,9,opt,name=syntax_unchecked,json=syntaxUnchecked,proto3" json:"syntax_unchecked,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ // hunks_omitted says why hunks is empty or incomplete for a content or add/add
+ // conflict: a side too large to read, a diff over its cost bound, more regions
+ // than a file lists, or a package over its size bound. It is empty when hunks is
+ // complete, and for the kinds of conflict that have no hunks.
+ HunksOmitted string `protobuf:"bytes,10,opt,name=hunks_omitted,json=hunksOmitted,proto3" json:"hunks_omitted,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *LandConflictFile) Reset() {
@@ -5082,13 +5098,27 @@ func (x *LandConflictFile) GetSyntaxUnchecked() bool {
return false
}
+func (x *LandConflictFile) GetHunksOmitted() string {
+ if x != nil {
+ return x.HunksOmitted
+ }
+ return ""
+}
+
// LandConflictSide is one side of a conflicting file; its content is read by oid.
type LandConflictSide struct {
state protoimpl.MessageState `protogen:"open.v1"`
- // oid is the object ID of the blob.
+ // oid is the object ID of the blob. It is set only for a blob in the tree of the
+ // merge base, the tip or the landed commit, which the repository keeps. A side
+ // that the merge wrote for this conflict alone (such as the content merge of a
+ // rename) is not kept after the land fails, so it has no oid and unavailable says
+ // why.
Oid string `protobuf:"bytes,1,opt,name=oid,proto3" json:"oid,omitempty"`
// mode is the file mode.
- Mode string `protobuf:"bytes,2,opt,name=mode,proto3" json:"mode,omitempty"`
+ Mode string `protobuf:"bytes,2,opt,name=mode,proto3" json:"mode,omitempty"`
+ // unavailable is set instead of oid when the side's blob is not kept in the
+ // repository: its content cannot be read.
+ Unavailable string `protobuf:"bytes,3,opt,name=unavailable,proto3" json:"unavailable,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -5137,6 +5167,79 @@ func (x *LandConflictSide) GetMode() string {
return ""
}
+func (x *LandConflictSide) GetUnavailable() string {
+ if x != nil {
+ return x.Unavailable
+ }
+ return ""
+}
+
+// LandConflictMessage is a message of the merge about a conflict, as git
+// merge-tree reports it. A conflict without a conflicting file (a directory rename
+// split, say) is described by its message alone.
+type LandConflictMessage struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ // paths are the paths the message is about.
+ Paths [][]byte `protobuf:"bytes,1,rep,name=paths,proto3" json:"paths,omitempty"`
+ // type is the kind of the conflict, such as "CONFLICT (rename/delete)".
+ Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
+ // message is the message, cut to 512 bytes.
+ Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *LandConflictMessage) Reset() {
+ *x = LandConflictMessage{}
+ mi := &file_operations_proto_msgTypes[53]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *LandConflictMessage) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*LandConflictMessage) ProtoMessage() {}
+
+func (x *LandConflictMessage) ProtoReflect() protoreflect.Message {
+ mi := &file_operations_proto_msgTypes[53]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use LandConflictMessage.ProtoReflect.Descriptor instead.
+func (*LandConflictMessage) Descriptor() ([]byte, []int) {
+ return file_operations_proto_rawDescGZIP(), []int{53}
+}
+
+func (x *LandConflictMessage) GetPaths() [][]byte {
+ if x != nil {
+ return x.Paths
+ }
+ return nil
+}
+
+func (x *LandConflictMessage) GetType() string {
+ if x != nil {
+ return x.Type
+ }
+ return ""
+}
+
+func (x *LandConflictMessage) GetMessage() string {
+ if x != nil {
+ return x.Message
+ }
+ return ""
+}
+
// LandConflictHunk is a conflicting region as line ranges of each side. Each range
// counts the lines of the side it names (base of the base side's file, ours of the
// tip's, theirs of the landed commit's), 1-based and half-open ([start, end)); an
@@ -5155,7 +5258,7 @@ type LandConflictHunk struct {
func (x *LandConflictHunk) Reset() {
*x = LandConflictHunk{}
- mi := &file_operations_proto_msgTypes[53]
+ mi := &file_operations_proto_msgTypes[54]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -5167,7 +5270,7 @@ func (x *LandConflictHunk) String() string {
func (*LandConflictHunk) ProtoMessage() {}
func (x *LandConflictHunk) ProtoReflect() protoreflect.Message {
- mi := &file_operations_proto_msgTypes[53]
+ mi := &file_operations_proto_msgTypes[54]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -5180,7 +5283,7 @@ func (x *LandConflictHunk) ProtoReflect() protoreflect.Message {
// Deprecated: Use LandConflictHunk.ProtoReflect.Descriptor instead.
func (*LandConflictHunk) Descriptor() ([]byte, []int) {
- return file_operations_proto_rawDescGZIP(), []int{53}
+ return file_operations_proto_rawDescGZIP(), []int{54}
}
func (x *LandConflictHunk) GetBase() *LineRange {
@@ -5217,7 +5320,7 @@ type LineRange struct {
func (x *LineRange) Reset() {
*x = LineRange{}
- mi := &file_operations_proto_msgTypes[54]
+ mi := &file_operations_proto_msgTypes[55]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -5229,7 +5332,7 @@ func (x *LineRange) String() string {
func (*LineRange) ProtoMessage() {}
func (x *LineRange) ProtoReflect() protoreflect.Message {
- mi := &file_operations_proto_msgTypes[54]
+ mi := &file_operations_proto_msgTypes[55]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -5242,7 +5345,7 @@ func (x *LineRange) ProtoReflect() protoreflect.Message {
// Deprecated: Use LineRange.ProtoReflect.Descriptor instead.
func (*LineRange) Descriptor() ([]byte, []int) {
- return file_operations_proto_rawDescGZIP(), []int{54}
+ return file_operations_proto_rawDescGZIP(), []int{55}
}
func (x *LineRange) GetStart() uint32 {
@@ -5274,7 +5377,7 @@ type LandResolution struct {
func (x *LandResolution) Reset() {
*x = LandResolution{}
- mi := &file_operations_proto_msgTypes[55]
+ mi := &file_operations_proto_msgTypes[56]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -5286,7 +5389,7 @@ func (x *LandResolution) String() string {
func (*LandResolution) ProtoMessage() {}
func (x *LandResolution) ProtoReflect() protoreflect.Message {
- mi := &file_operations_proto_msgTypes[55]
+ mi := &file_operations_proto_msgTypes[56]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -5299,7 +5402,7 @@ func (x *LandResolution) ProtoReflect() protoreflect.Message {
// Deprecated: Use LandResolution.ProtoReflect.Descriptor instead.
func (*LandResolution) Descriptor() ([]byte, []int) {
- return file_operations_proto_rawDescGZIP(), []int{55}
+ return file_operations_proto_rawDescGZIP(), []int{56}
}
func (x *LandResolution) GetTip() string {
@@ -5340,7 +5443,7 @@ type LandResolvedFile struct {
func (x *LandResolvedFile) Reset() {
*x = LandResolvedFile{}
- mi := &file_operations_proto_msgTypes[56]
+ mi := &file_operations_proto_msgTypes[57]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -5352,7 +5455,7 @@ func (x *LandResolvedFile) String() string {
func (*LandResolvedFile) ProtoMessage() {}
func (x *LandResolvedFile) ProtoReflect() protoreflect.Message {
- mi := &file_operations_proto_msgTypes[56]
+ mi := &file_operations_proto_msgTypes[57]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -5365,7 +5468,7 @@ func (x *LandResolvedFile) ProtoReflect() protoreflect.Message {
// Deprecated: Use LandResolvedFile.ProtoReflect.Descriptor instead.
func (*LandResolvedFile) Descriptor() ([]byte, []int) {
- return file_operations_proto_rawDescGZIP(), []int{56}
+ return file_operations_proto_rawDescGZIP(), []int{57}
}
func (x *LandResolvedFile) GetPath() []byte {
@@ -5432,7 +5535,7 @@ type UserLandResponse struct {
func (x *UserLandResponse) Reset() {
*x = UserLandResponse{}
- mi := &file_operations_proto_msgTypes[57]
+ mi := &file_operations_proto_msgTypes[58]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -5444,7 +5547,7 @@ func (x *UserLandResponse) String() string {
func (*UserLandResponse) ProtoMessage() {}
func (x *UserLandResponse) ProtoReflect() protoreflect.Message {
- mi := &file_operations_proto_msgTypes[57]
+ mi := &file_operations_proto_msgTypes[58]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -5457,7 +5560,7 @@ func (x *UserLandResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use UserLandResponse.ProtoReflect.Descriptor instead.
func (*UserLandResponse) Descriptor() ([]byte, []int) {
- return file_operations_proto_rawDescGZIP(), []int{57}
+ return file_operations_proto_rawDescGZIP(), []int{58}
}
func (x *UserLandResponse) GetBranchUpdate() *OperationBranchUpdate {
@@ -5548,7 +5651,7 @@ type UserLandError struct {
func (x *UserLandError) Reset() {
*x = UserLandError{}
- mi := &file_operations_proto_msgTypes[58]
+ mi := &file_operations_proto_msgTypes[59]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -5560,7 +5663,7 @@ func (x *UserLandError) String() string {
func (*UserLandError) ProtoMessage() {}
func (x *UserLandError) ProtoReflect() protoreflect.Message {
- mi := &file_operations_proto_msgTypes[58]
+ mi := &file_operations_proto_msgTypes[59]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -5573,7 +5676,7 @@ func (x *UserLandError) ProtoReflect() protoreflect.Message {
// Deprecated: Use UserLandError.ProtoReflect.Descriptor instead.
func (*UserLandError) Descriptor() ([]byte, []int) {
- return file_operations_proto_rawDescGZIP(), []int{58}
+ return file_operations_proto_rawDescGZIP(), []int{59}
}
func (x *UserLandError) GetError() isUserLandError_Error {
@@ -5708,7 +5811,7 @@ type UserRebaseConfirmableRequest_Header struct {
func (x *UserRebaseConfirmableRequest_Header) Reset() {
*x = UserRebaseConfirmableRequest_Header{}
- mi := &file_operations_proto_msgTypes[59]
+ mi := &file_operations_proto_msgTypes[60]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -5720,7 +5823,7 @@ func (x *UserRebaseConfirmableRequest_Header) String() string {
func (*UserRebaseConfirmableRequest_Header) ProtoMessage() {}
func (x *UserRebaseConfirmableRequest_Header) ProtoReflect() protoreflect.Message {
- mi := &file_operations_proto_msgTypes[59]
+ mi := &file_operations_proto_msgTypes[60]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -5828,7 +5931,7 @@ type UserApplyPatchRequest_Header struct {
func (x *UserApplyPatchRequest_Header) Reset() {
*x = UserApplyPatchRequest_Header{}
- mi := &file_operations_proto_msgTypes[60]
+ mi := &file_operations_proto_msgTypes[61]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -5840,7 +5943,7 @@ func (x *UserApplyPatchRequest_Header) String() string {
func (*UserApplyPatchRequest_Header) ProtoMessage() {}
func (x *UserApplyPatchRequest_Header) ProtoReflect() protoreflect.Message {
- mi := &file_operations_proto_msgTypes[60]
+ mi := &file_operations_proto_msgTypes[61]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -6267,7 +6370,7 @@ const file_operations_proto_rawDesc = "" +
"\bStrategy\x12\x1f\n" +
"\x1bSTRATEGY_REBASE_UNSPECIFIED\x10\x00\x12\x12\n" +
"\x0eSTRATEGY_MERGE\x10\x01\x12\x14\n" +
- "\x10STRATEGY_FF_ONLY\x10\x02\"\x96\x02\n" +
+ "\x10STRATEGY_FF_ONLY\x10\x02\"\xcf\x02\n" +
"\fLandConflict\x12\x10\n" +
"\x03tip\x18\x01 \x01(\tR\x03tip\x12\x16\n" +
"\x06commit\x18\x02 \x01(\tR\x06commit\x12\x1d\n" +
@@ -6278,7 +6381,8 @@ const file_operations_proto_rawDesc = "" +
"\x0ecommit_message\x18\x05 \x01(\fR\rcommitMessage\x12-\n" +
"\x12messages_truncated\x18\x06 \x01(\bR\x11messagesTruncated\x12.\n" +
"\x05files\x18\a \x03(\v2\x18.gitaly.LandConflictFileR\x05files\x12\x16\n" +
- "\x06reason\x18\b \x01(\tR\x06reason\"\x95\x05\n" +
+ "\x06reason\x18\b \x01(\tR\x06reason\x127\n" +
+ "\bmessages\x18\t \x03(\v2\x1b.gitaly.LandConflictMessageR\bmessages\"\xba\x05\n" +
"\x10LandConflictFile\x12\x12\n" +
"\x04path\x18\x01 \x01(\fR\x04path\x121\n" +
"\x04kind\x18\x02 \x01(\x0e2\x1d.gitaly.LandConflictFile.KindR\x04kind\x12,\n" +
@@ -6288,7 +6392,9 @@ const file_operations_proto_rawDesc = "" +
"\x05hunks\x18\x06 \x03(\v2\x18.gitaly.LandConflictHunkR\x05hunks\x12:\n" +
"\aoutcome\x18\a \x01(\x0e2 .gitaly.LandConflictFile.OutcomeR\aoutcome\x12\x16\n" +
"\x06reason\x18\b \x01(\tR\x06reason\x12)\n" +
- "\x10syntax_unchecked\x18\t \x01(\bR\x0fsyntaxUnchecked\"g\n" +
+ "\x10syntax_unchecked\x18\t \x01(\bR\x0fsyntaxUnchecked\x12#\n" +
+ "\rhunks_omitted\x18\n" +
+ " \x01(\tR\fhunksOmitted\"g\n" +
"\x04Kind\x12\x14\n" +
"\x10KIND_UNSPECIFIED\x10\x00\x12\x10\n" +
"\fKIND_CONTENT\x10\x01\x12\x16\n" +
@@ -6301,10 +6407,15 @@ const file_operations_proto_rawDesc = "" +
"\x10OUTCOME_REJECTED\x10\x02\x12\x12\n" +
"\x0eOUTCOME_FAILED\x10\x03\x12\x14\n" +
"\x10OUTCOME_RESOLVED\x10\x04\x12\x19\n" +
- "\x15OUTCOME_NOT_ATTEMPTED\x10\x05\"8\n" +
+ "\x15OUTCOME_NOT_ATTEMPTED\x10\x05\"Z\n" +
"\x10LandConflictSide\x12\x10\n" +
"\x03oid\x18\x01 \x01(\tR\x03oid\x12\x12\n" +
- "\x04mode\x18\x02 \x01(\tR\x04mode\"\x8b\x01\n" +
+ "\x04mode\x18\x02 \x01(\tR\x04mode\x12 \n" +
+ "\vunavailable\x18\x03 \x01(\tR\vunavailable\"Y\n" +
+ "\x13LandConflictMessage\x12\x14\n" +
+ "\x05paths\x18\x01 \x03(\fR\x05paths\x12\x12\n" +
+ "\x04type\x18\x02 \x01(\tR\x04type\x12\x18\n" +
+ "\amessage\x18\x03 \x01(\tR\amessage\"\x8b\x01\n" +
"\x10LandConflictHunk\x12%\n" +
"\x04base\x18\x01 \x01(\v2\x11.gitaly.LineRangeR\x04base\x12%\n" +
"\x04ours\x18\x02 \x01(\v2\x11.gitaly.LineRangeR\x04ours\x12)\n" +
@@ -6380,7 +6491,7 @@ func file_operations_proto_rawDescGZIP() []byte {
}
var file_operations_proto_enumTypes = make([]protoimpl.EnumInfo, 6)
-var file_operations_proto_msgTypes = make([]protoimpl.MessageInfo, 61)
+var file_operations_proto_msgTypes = make([]protoimpl.MessageInfo, 62)
var file_operations_proto_goTypes = []any{
(UserRevertResponse_CreateTreeError)(0), // 0: gitaly.UserRevertResponse.CreateTreeError
(UserCommitFilesActionHeader_ActionType)(0), // 1: gitaly.UserCommitFilesActionHeader.ActionType
@@ -6441,194 +6552,196 @@ var file_operations_proto_goTypes = []any{
(*LandConflict)(nil), // 56: gitaly.LandConflict
(*LandConflictFile)(nil), // 57: gitaly.LandConflictFile
(*LandConflictSide)(nil), // 58: gitaly.LandConflictSide
- (*LandConflictHunk)(nil), // 59: gitaly.LandConflictHunk
- (*LineRange)(nil), // 60: gitaly.LineRange
- (*LandResolution)(nil), // 61: gitaly.LandResolution
- (*LandResolvedFile)(nil), // 62: gitaly.LandResolvedFile
- (*UserLandResponse)(nil), // 63: gitaly.UserLandResponse
- (*UserLandError)(nil), // 64: gitaly.UserLandError
- (*UserRebaseConfirmableRequest_Header)(nil), // 65: gitaly.UserRebaseConfirmableRequest.Header
- (*UserApplyPatchRequest_Header)(nil), // 66: gitaly.UserApplyPatchRequest.Header
- (*Repository)(nil), // 67: gitaly.Repository
- (*User)(nil), // 68: gitaly.User
- (*Branch)(nil), // 69: gitaly.Branch
- (*CustomHookError)(nil), // 70: gitaly.CustomHookError
- (*AccessCheckError)(nil), // 71: gitaly.AccessCheckError
- (*ReferenceUpdateError)(nil), // 72: gitaly.ReferenceUpdateError
- (*timestamppb.Timestamp)(nil), // 73: google.protobuf.Timestamp
- (*Tag)(nil), // 74: gitaly.Tag
- (*ReferenceExistsError)(nil), // 75: gitaly.ReferenceExistsError
- (*MergeConflictError)(nil), // 76: gitaly.MergeConflictError
- (*GitCommit)(nil), // 77: gitaly.GitCommit
- (*NotAncestorError)(nil), // 78: gitaly.NotAncestorError
- (*ChangesAlreadyAppliedError)(nil), // 79: gitaly.ChangesAlreadyAppliedError
- (*IndexError)(nil), // 80: gitaly.IndexError
- (*ResolveRevisionError)(nil), // 81: gitaly.ResolveRevisionError
- (*PathError)(nil), // 82: gitaly.PathError
+ (*LandConflictMessage)(nil), // 59: gitaly.LandConflictMessage
+ (*LandConflictHunk)(nil), // 60: gitaly.LandConflictHunk
+ (*LineRange)(nil), // 61: gitaly.LineRange
+ (*LandResolution)(nil), // 62: gitaly.LandResolution
+ (*LandResolvedFile)(nil), // 63: gitaly.LandResolvedFile
+ (*UserLandResponse)(nil), // 64: gitaly.UserLandResponse
+ (*UserLandError)(nil), // 65: gitaly.UserLandError
+ (*UserRebaseConfirmableRequest_Header)(nil), // 66: gitaly.UserRebaseConfirmableRequest.Header
+ (*UserApplyPatchRequest_Header)(nil), // 67: gitaly.UserApplyPatchRequest.Header
+ (*Repository)(nil), // 68: gitaly.Repository
+ (*User)(nil), // 69: gitaly.User
+ (*Branch)(nil), // 70: gitaly.Branch
+ (*CustomHookError)(nil), // 71: gitaly.CustomHookError
+ (*AccessCheckError)(nil), // 72: gitaly.AccessCheckError
+ (*ReferenceUpdateError)(nil), // 73: gitaly.ReferenceUpdateError
+ (*timestamppb.Timestamp)(nil), // 74: google.protobuf.Timestamp
+ (*Tag)(nil), // 75: gitaly.Tag
+ (*ReferenceExistsError)(nil), // 76: gitaly.ReferenceExistsError
+ (*MergeConflictError)(nil), // 77: gitaly.MergeConflictError
+ (*GitCommit)(nil), // 78: gitaly.GitCommit
+ (*NotAncestorError)(nil), // 79: gitaly.NotAncestorError
+ (*ChangesAlreadyAppliedError)(nil), // 80: gitaly.ChangesAlreadyAppliedError
+ (*IndexError)(nil), // 81: gitaly.IndexError
+ (*ResolveRevisionError)(nil), // 82: gitaly.ResolveRevisionError
+ (*PathError)(nil), // 83: gitaly.PathError
}
var file_operations_proto_depIdxs = []int32{
- 67, // 0: gitaly.UserCreateBranchRequest.repository:type_name -> gitaly.Repository
- 68, // 1: gitaly.UserCreateBranchRequest.user:type_name -> gitaly.User
- 69, // 2: gitaly.UserCreateBranchResponse.branch:type_name -> gitaly.Branch
- 70, // 3: gitaly.UserCreateBranchError.custom_hook:type_name -> gitaly.CustomHookError
- 67, // 4: gitaly.UserUpdateBranchRequest.repository:type_name -> gitaly.Repository
- 68, // 5: gitaly.UserUpdateBranchRequest.user:type_name -> gitaly.User
- 67, // 6: gitaly.UserDeleteBranchRequest.repository:type_name -> gitaly.Repository
- 68, // 7: gitaly.UserDeleteBranchRequest.user:type_name -> gitaly.User
- 71, // 8: gitaly.UserDeleteBranchError.access_check:type_name -> gitaly.AccessCheckError
- 72, // 9: gitaly.UserDeleteBranchError.reference_update:type_name -> gitaly.ReferenceUpdateError
- 70, // 10: gitaly.UserDeleteBranchError.custom_hook:type_name -> gitaly.CustomHookError
- 67, // 11: gitaly.UserDeleteTagRequest.repository:type_name -> gitaly.Repository
- 68, // 12: gitaly.UserDeleteTagRequest.user:type_name -> gitaly.User
- 67, // 13: gitaly.UserCreateTagRequest.repository:type_name -> gitaly.Repository
- 68, // 14: gitaly.UserCreateTagRequest.user:type_name -> gitaly.User
- 73, // 15: gitaly.UserCreateTagRequest.timestamp:type_name -> google.protobuf.Timestamp
- 74, // 16: gitaly.UserCreateTagResponse.tag:type_name -> gitaly.Tag
- 71, // 17: gitaly.UserCreateTagError.access_check:type_name -> gitaly.AccessCheckError
- 72, // 18: gitaly.UserCreateTagError.reference_update:type_name -> gitaly.ReferenceUpdateError
- 70, // 19: gitaly.UserCreateTagError.custom_hook:type_name -> gitaly.CustomHookError
- 75, // 20: gitaly.UserCreateTagError.reference_exists:type_name -> gitaly.ReferenceExistsError
- 67, // 21: gitaly.UserMergeBranchRequest.repository:type_name -> gitaly.Repository
- 68, // 22: gitaly.UserMergeBranchRequest.user:type_name -> gitaly.User
- 73, // 23: gitaly.UserMergeBranchRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 68, // 0: gitaly.UserCreateBranchRequest.repository:type_name -> gitaly.Repository
+ 69, // 1: gitaly.UserCreateBranchRequest.user:type_name -> gitaly.User
+ 70, // 2: gitaly.UserCreateBranchResponse.branch:type_name -> gitaly.Branch
+ 71, // 3: gitaly.UserCreateBranchError.custom_hook:type_name -> gitaly.CustomHookError
+ 68, // 4: gitaly.UserUpdateBranchRequest.repository:type_name -> gitaly.Repository
+ 69, // 5: gitaly.UserUpdateBranchRequest.user:type_name -> gitaly.User
+ 68, // 6: gitaly.UserDeleteBranchRequest.repository:type_name -> gitaly.Repository
+ 69, // 7: gitaly.UserDeleteBranchRequest.user:type_name -> gitaly.User
+ 72, // 8: gitaly.UserDeleteBranchError.access_check:type_name -> gitaly.AccessCheckError
+ 73, // 9: gitaly.UserDeleteBranchError.reference_update:type_name -> gitaly.ReferenceUpdateError
+ 71, // 10: gitaly.UserDeleteBranchError.custom_hook:type_name -> gitaly.CustomHookError
+ 68, // 11: gitaly.UserDeleteTagRequest.repository:type_name -> gitaly.Repository
+ 69, // 12: gitaly.UserDeleteTagRequest.user:type_name -> gitaly.User
+ 68, // 13: gitaly.UserCreateTagRequest.repository:type_name -> gitaly.Repository
+ 69, // 14: gitaly.UserCreateTagRequest.user:type_name -> gitaly.User
+ 74, // 15: gitaly.UserCreateTagRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 75, // 16: gitaly.UserCreateTagResponse.tag:type_name -> gitaly.Tag
+ 72, // 17: gitaly.UserCreateTagError.access_check:type_name -> gitaly.AccessCheckError
+ 73, // 18: gitaly.UserCreateTagError.reference_update:type_name -> gitaly.ReferenceUpdateError
+ 71, // 19: gitaly.UserCreateTagError.custom_hook:type_name -> gitaly.CustomHookError
+ 76, // 20: gitaly.UserCreateTagError.reference_exists:type_name -> gitaly.ReferenceExistsError
+ 68, // 21: gitaly.UserMergeBranchRequest.repository:type_name -> gitaly.Repository
+ 69, // 22: gitaly.UserMergeBranchRequest.user:type_name -> gitaly.User
+ 74, // 23: gitaly.UserMergeBranchRequest.timestamp:type_name -> google.protobuf.Timestamp
27, // 24: gitaly.UserMergeBranchResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
- 71, // 25: gitaly.UserMergeBranchError.access_check:type_name -> gitaly.AccessCheckError
- 72, // 26: gitaly.UserMergeBranchError.reference_update:type_name -> gitaly.ReferenceUpdateError
- 70, // 27: gitaly.UserMergeBranchError.custom_hook:type_name -> gitaly.CustomHookError
- 76, // 28: gitaly.UserMergeBranchError.merge_conflict:type_name -> gitaly.MergeConflictError
- 67, // 29: gitaly.UserMergeToRefRequest.repository:type_name -> gitaly.Repository
- 68, // 30: gitaly.UserMergeToRefRequest.user:type_name -> gitaly.User
- 73, // 31: gitaly.UserMergeToRefRequest.timestamp:type_name -> google.protobuf.Timestamp
- 76, // 32: gitaly.UserMergeToRefError.merge_conflict:type_name -> gitaly.MergeConflictError
- 67, // 33: gitaly.UserRebaseToRefRequest.repository:type_name -> gitaly.Repository
- 68, // 34: gitaly.UserRebaseToRefRequest.user:type_name -> gitaly.User
- 73, // 35: gitaly.UserRebaseToRefRequest.timestamp:type_name -> google.protobuf.Timestamp
- 70, // 36: gitaly.UserFFBranchError.custom_hook:type_name -> gitaly.CustomHookError
- 72, // 37: gitaly.UserFFBranchError.reference_update:type_name -> gitaly.ReferenceUpdateError
- 67, // 38: gitaly.UserFFBranchRequest.repository:type_name -> gitaly.Repository
- 68, // 39: gitaly.UserFFBranchRequest.user:type_name -> gitaly.User
+ 72, // 25: gitaly.UserMergeBranchError.access_check:type_name -> gitaly.AccessCheckError
+ 73, // 26: gitaly.UserMergeBranchError.reference_update:type_name -> gitaly.ReferenceUpdateError
+ 71, // 27: gitaly.UserMergeBranchError.custom_hook:type_name -> gitaly.CustomHookError
+ 77, // 28: gitaly.UserMergeBranchError.merge_conflict:type_name -> gitaly.MergeConflictError
+ 68, // 29: gitaly.UserMergeToRefRequest.repository:type_name -> gitaly.Repository
+ 69, // 30: gitaly.UserMergeToRefRequest.user:type_name -> gitaly.User
+ 74, // 31: gitaly.UserMergeToRefRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 77, // 32: gitaly.UserMergeToRefError.merge_conflict:type_name -> gitaly.MergeConflictError
+ 68, // 33: gitaly.UserRebaseToRefRequest.repository:type_name -> gitaly.Repository
+ 69, // 34: gitaly.UserRebaseToRefRequest.user:type_name -> gitaly.User
+ 74, // 35: gitaly.UserRebaseToRefRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 71, // 36: gitaly.UserFFBranchError.custom_hook:type_name -> gitaly.CustomHookError
+ 73, // 37: gitaly.UserFFBranchError.reference_update:type_name -> gitaly.ReferenceUpdateError
+ 68, // 38: gitaly.UserFFBranchRequest.repository:type_name -> gitaly.Repository
+ 69, // 39: gitaly.UserFFBranchRequest.user:type_name -> gitaly.User
27, // 40: gitaly.UserFFBranchResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
- 67, // 41: gitaly.UserCherryPickRequest.repository:type_name -> gitaly.Repository
- 68, // 42: gitaly.UserCherryPickRequest.user:type_name -> gitaly.User
- 77, // 43: gitaly.UserCherryPickRequest.commit:type_name -> gitaly.GitCommit
- 67, // 44: gitaly.UserCherryPickRequest.start_repository:type_name -> gitaly.Repository
- 73, // 45: gitaly.UserCherryPickRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 68, // 41: gitaly.UserCherryPickRequest.repository:type_name -> gitaly.Repository
+ 69, // 42: gitaly.UserCherryPickRequest.user:type_name -> gitaly.User
+ 78, // 43: gitaly.UserCherryPickRequest.commit:type_name -> gitaly.GitCommit
+ 68, // 44: gitaly.UserCherryPickRequest.start_repository:type_name -> gitaly.Repository
+ 74, // 45: gitaly.UserCherryPickRequest.timestamp:type_name -> google.protobuf.Timestamp
27, // 46: gitaly.UserCherryPickResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
- 76, // 47: gitaly.UserCherryPickError.cherry_pick_conflict:type_name -> gitaly.MergeConflictError
- 78, // 48: gitaly.UserCherryPickError.target_branch_diverged:type_name -> gitaly.NotAncestorError
- 79, // 49: gitaly.UserCherryPickError.changes_already_applied:type_name -> gitaly.ChangesAlreadyAppliedError
- 71, // 50: gitaly.UserCherryPickError.access_check:type_name -> gitaly.AccessCheckError
- 67, // 51: gitaly.UserRevertRequest.repository:type_name -> gitaly.Repository
- 68, // 52: gitaly.UserRevertRequest.user:type_name -> gitaly.User
- 77, // 53: gitaly.UserRevertRequest.commit:type_name -> gitaly.GitCommit
- 67, // 54: gitaly.UserRevertRequest.start_repository:type_name -> gitaly.Repository
- 73, // 55: gitaly.UserRevertRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 77, // 47: gitaly.UserCherryPickError.cherry_pick_conflict:type_name -> gitaly.MergeConflictError
+ 79, // 48: gitaly.UserCherryPickError.target_branch_diverged:type_name -> gitaly.NotAncestorError
+ 80, // 49: gitaly.UserCherryPickError.changes_already_applied:type_name -> gitaly.ChangesAlreadyAppliedError
+ 72, // 50: gitaly.UserCherryPickError.access_check:type_name -> gitaly.AccessCheckError
+ 68, // 51: gitaly.UserRevertRequest.repository:type_name -> gitaly.Repository
+ 69, // 52: gitaly.UserRevertRequest.user:type_name -> gitaly.User
+ 78, // 53: gitaly.UserRevertRequest.commit:type_name -> gitaly.GitCommit
+ 68, // 54: gitaly.UserRevertRequest.start_repository:type_name -> gitaly.Repository
+ 74, // 55: gitaly.UserRevertRequest.timestamp:type_name -> google.protobuf.Timestamp
27, // 56: gitaly.UserRevertResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
0, // 57: gitaly.UserRevertResponse.create_tree_error_code:type_name -> gitaly.UserRevertResponse.CreateTreeError
- 76, // 58: gitaly.UserRevertError.merge_conflict:type_name -> gitaly.MergeConflictError
- 79, // 59: gitaly.UserRevertError.changes_already_applied:type_name -> gitaly.ChangesAlreadyAppliedError
- 70, // 60: gitaly.UserRevertError.custom_hook:type_name -> gitaly.CustomHookError
- 78, // 61: gitaly.UserRevertError.not_ancestor:type_name -> gitaly.NotAncestorError
+ 77, // 58: gitaly.UserRevertError.merge_conflict:type_name -> gitaly.MergeConflictError
+ 80, // 59: gitaly.UserRevertError.changes_already_applied:type_name -> gitaly.ChangesAlreadyAppliedError
+ 71, // 60: gitaly.UserRevertError.custom_hook:type_name -> gitaly.CustomHookError
+ 79, // 61: gitaly.UserRevertError.not_ancestor:type_name -> gitaly.NotAncestorError
1, // 62: gitaly.UserCommitFilesActionHeader.action:type_name -> gitaly.UserCommitFilesActionHeader.ActionType
37, // 63: gitaly.UserCommitFilesAction.header:type_name -> gitaly.UserCommitFilesActionHeader
- 67, // 64: gitaly.UserCommitFilesRequestHeader.repository:type_name -> gitaly.Repository
- 68, // 65: gitaly.UserCommitFilesRequestHeader.user:type_name -> gitaly.User
- 67, // 66: gitaly.UserCommitFilesRequestHeader.start_repository:type_name -> gitaly.Repository
- 73, // 67: gitaly.UserCommitFilesRequestHeader.timestamp:type_name -> google.protobuf.Timestamp
+ 68, // 64: gitaly.UserCommitFilesRequestHeader.repository:type_name -> gitaly.Repository
+ 69, // 65: gitaly.UserCommitFilesRequestHeader.user:type_name -> gitaly.User
+ 68, // 66: gitaly.UserCommitFilesRequestHeader.start_repository:type_name -> gitaly.Repository
+ 74, // 67: gitaly.UserCommitFilesRequestHeader.timestamp:type_name -> google.protobuf.Timestamp
39, // 68: gitaly.UserCommitFilesRequest.header:type_name -> gitaly.UserCommitFilesRequestHeader
38, // 69: gitaly.UserCommitFilesRequest.action:type_name -> gitaly.UserCommitFilesAction
27, // 70: gitaly.UserCommitFilesResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
- 71, // 71: gitaly.UserCommitFilesError.access_check:type_name -> gitaly.AccessCheckError
- 80, // 72: gitaly.UserCommitFilesError.index_update:type_name -> gitaly.IndexError
- 70, // 73: gitaly.UserCommitFilesError.custom_hook:type_name -> gitaly.CustomHookError
- 65, // 74: gitaly.UserRebaseConfirmableRequest.header:type_name -> gitaly.UserRebaseConfirmableRequest.Header
- 67, // 75: gitaly.UserSquashRequest.repository:type_name -> gitaly.Repository
- 68, // 76: gitaly.UserSquashRequest.user:type_name -> gitaly.User
- 68, // 77: gitaly.UserSquashRequest.author:type_name -> gitaly.User
- 73, // 78: gitaly.UserSquashRequest.timestamp:type_name -> google.protobuf.Timestamp
- 76, // 79: gitaly.UserRebaseConfirmableError.rebase_conflict:type_name -> gitaly.MergeConflictError
- 71, // 80: gitaly.UserRebaseConfirmableError.access_check:type_name -> gitaly.AccessCheckError
- 81, // 81: gitaly.UserSquashError.resolve_revision:type_name -> gitaly.ResolveRevisionError
- 76, // 82: gitaly.UserSquashError.rebase_conflict:type_name -> gitaly.MergeConflictError
- 66, // 83: gitaly.UserApplyPatchRequest.header:type_name -> gitaly.UserApplyPatchRequest.Header
- 70, // 84: gitaly.UserApplyPatchError.custom_hook:type_name -> gitaly.CustomHookError
+ 72, // 71: gitaly.UserCommitFilesError.access_check:type_name -> gitaly.AccessCheckError
+ 81, // 72: gitaly.UserCommitFilesError.index_update:type_name -> gitaly.IndexError
+ 71, // 73: gitaly.UserCommitFilesError.custom_hook:type_name -> gitaly.CustomHookError
+ 66, // 74: gitaly.UserRebaseConfirmableRequest.header:type_name -> gitaly.UserRebaseConfirmableRequest.Header
+ 68, // 75: gitaly.UserSquashRequest.repository:type_name -> gitaly.Repository
+ 69, // 76: gitaly.UserSquashRequest.user:type_name -> gitaly.User
+ 69, // 77: gitaly.UserSquashRequest.author:type_name -> gitaly.User
+ 74, // 78: gitaly.UserSquashRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 77, // 79: gitaly.UserRebaseConfirmableError.rebase_conflict:type_name -> gitaly.MergeConflictError
+ 72, // 80: gitaly.UserRebaseConfirmableError.access_check:type_name -> gitaly.AccessCheckError
+ 82, // 81: gitaly.UserSquashError.resolve_revision:type_name -> gitaly.ResolveRevisionError
+ 77, // 82: gitaly.UserSquashError.rebase_conflict:type_name -> gitaly.MergeConflictError
+ 67, // 83: gitaly.UserApplyPatchRequest.header:type_name -> gitaly.UserApplyPatchRequest.Header
+ 71, // 84: gitaly.UserApplyPatchError.custom_hook:type_name -> gitaly.CustomHookError
27, // 85: gitaly.UserApplyPatchResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
- 67, // 86: gitaly.UserUpdateSubmoduleRequest.repository:type_name -> gitaly.Repository
- 68, // 87: gitaly.UserUpdateSubmoduleRequest.user:type_name -> gitaly.User
- 73, // 88: gitaly.UserUpdateSubmoduleRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 68, // 86: gitaly.UserUpdateSubmoduleRequest.repository:type_name -> gitaly.Repository
+ 69, // 87: gitaly.UserUpdateSubmoduleRequest.user:type_name -> gitaly.User
+ 74, // 88: gitaly.UserUpdateSubmoduleRequest.timestamp:type_name -> google.protobuf.Timestamp
27, // 89: gitaly.UserUpdateSubmoduleResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
- 70, // 90: gitaly.UserUpdateSubmoduleError.custom_hook:type_name -> gitaly.CustomHookError
- 72, // 91: gitaly.UserUpdateSubmoduleError.reference_update:type_name -> gitaly.ReferenceUpdateError
- 82, // 92: gitaly.UserUpdateSubmoduleError.path_error:type_name -> gitaly.PathError
- 67, // 93: gitaly.UserLandRequest.repository:type_name -> gitaly.Repository
- 68, // 94: gitaly.UserLandRequest.user:type_name -> gitaly.User
+ 71, // 90: gitaly.UserUpdateSubmoduleError.custom_hook:type_name -> gitaly.CustomHookError
+ 73, // 91: gitaly.UserUpdateSubmoduleError.reference_update:type_name -> gitaly.ReferenceUpdateError
+ 83, // 92: gitaly.UserUpdateSubmoduleError.path_error:type_name -> gitaly.PathError
+ 68, // 93: gitaly.UserLandRequest.repository:type_name -> gitaly.Repository
+ 69, // 94: gitaly.UserLandRequest.user:type_name -> gitaly.User
2, // 95: gitaly.UserLandRequest.strategy:type_name -> gitaly.UserLandRequest.Strategy
- 73, // 96: gitaly.UserLandRequest.timestamp:type_name -> google.protobuf.Timestamp
- 61, // 97: gitaly.UserLandRequest.resolution:type_name -> gitaly.LandResolution
+ 74, // 96: gitaly.UserLandRequest.timestamp:type_name -> google.protobuf.Timestamp
+ 62, // 97: gitaly.UserLandRequest.resolution:type_name -> gitaly.LandResolution
57, // 98: gitaly.LandConflict.files:type_name -> gitaly.LandConflictFile
- 3, // 99: gitaly.LandConflictFile.kind:type_name -> gitaly.LandConflictFile.Kind
- 58, // 100: gitaly.LandConflictFile.base:type_name -> gitaly.LandConflictSide
- 58, // 101: gitaly.LandConflictFile.ours:type_name -> gitaly.LandConflictSide
- 58, // 102: gitaly.LandConflictFile.theirs:type_name -> gitaly.LandConflictSide
- 59, // 103: gitaly.LandConflictFile.hunks:type_name -> gitaly.LandConflictHunk
- 4, // 104: gitaly.LandConflictFile.outcome:type_name -> gitaly.LandConflictFile.Outcome
- 60, // 105: gitaly.LandConflictHunk.base:type_name -> gitaly.LineRange
- 60, // 106: gitaly.LandConflictHunk.ours:type_name -> gitaly.LineRange
- 60, // 107: gitaly.LandConflictHunk.theirs:type_name -> gitaly.LineRange
- 62, // 108: gitaly.LandResolution.files:type_name -> gitaly.LandResolvedFile
- 5, // 109: gitaly.LandResolvedFile.action:type_name -> gitaly.LandResolvedFile.Action
- 27, // 110: gitaly.UserLandResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
- 76, // 111: gitaly.UserLandError.merge_conflict:type_name -> gitaly.MergeConflictError
- 78, // 112: gitaly.UserLandError.not_ancestor:type_name -> gitaly.NotAncestorError
- 72, // 113: gitaly.UserLandError.reference_update:type_name -> gitaly.ReferenceUpdateError
- 70, // 114: gitaly.UserLandError.custom_hook:type_name -> gitaly.CustomHookError
- 71, // 115: gitaly.UserLandError.access_check:type_name -> gitaly.AccessCheckError
- 67, // 116: gitaly.UserRebaseConfirmableRequest.Header.repository:type_name -> gitaly.Repository
- 68, // 117: gitaly.UserRebaseConfirmableRequest.Header.user:type_name -> gitaly.User
- 67, // 118: gitaly.UserRebaseConfirmableRequest.Header.remote_repository:type_name -> gitaly.Repository
- 73, // 119: gitaly.UserRebaseConfirmableRequest.Header.timestamp:type_name -> google.protobuf.Timestamp
- 67, // 120: gitaly.UserApplyPatchRequest.Header.repository:type_name -> gitaly.Repository
- 68, // 121: gitaly.UserApplyPatchRequest.Header.user:type_name -> gitaly.User
- 73, // 122: gitaly.UserApplyPatchRequest.Header.timestamp:type_name -> google.protobuf.Timestamp
- 6, // 123: gitaly.OperationService.UserCreateBranch:input_type -> gitaly.UserCreateBranchRequest
- 9, // 124: gitaly.OperationService.UserUpdateBranch:input_type -> gitaly.UserUpdateBranchRequest
- 11, // 125: gitaly.OperationService.UserDeleteBranch:input_type -> gitaly.UserDeleteBranchRequest
- 16, // 126: gitaly.OperationService.UserCreateTag:input_type -> gitaly.UserCreateTagRequest
- 14, // 127: gitaly.OperationService.UserDeleteTag:input_type -> gitaly.UserDeleteTagRequest
- 22, // 128: gitaly.OperationService.UserMergeToRef:input_type -> gitaly.UserMergeToRefRequest
- 25, // 129: gitaly.OperationService.UserRebaseToRef:input_type -> gitaly.UserRebaseToRefRequest
- 19, // 130: gitaly.OperationService.UserMergeBranch:input_type -> gitaly.UserMergeBranchRequest
- 29, // 131: gitaly.OperationService.UserFFBranch:input_type -> gitaly.UserFFBranchRequest
- 31, // 132: gitaly.OperationService.UserCherryPick:input_type -> gitaly.UserCherryPickRequest
- 40, // 133: gitaly.OperationService.UserCommitFiles:input_type -> gitaly.UserCommitFilesRequest
- 43, // 134: gitaly.OperationService.UserRebaseConfirmable:input_type -> gitaly.UserRebaseConfirmableRequest
- 34, // 135: gitaly.OperationService.UserRevert:input_type -> gitaly.UserRevertRequest
- 45, // 136: gitaly.OperationService.UserSquash:input_type -> gitaly.UserSquashRequest
- 49, // 137: gitaly.OperationService.UserApplyPatch:input_type -> gitaly.UserApplyPatchRequest
- 52, // 138: gitaly.OperationService.UserUpdateSubmodule:input_type -> gitaly.UserUpdateSubmoduleRequest
- 55, // 139: gitaly.OperationService.UserLand:input_type -> gitaly.UserLandRequest
- 7, // 140: gitaly.OperationService.UserCreateBranch:output_type -> gitaly.UserCreateBranchResponse
- 10, // 141: gitaly.OperationService.UserUpdateBranch:output_type -> gitaly.UserUpdateBranchResponse
- 12, // 142: gitaly.OperationService.UserDeleteBranch:output_type -> gitaly.UserDeleteBranchResponse
- 17, // 143: gitaly.OperationService.UserCreateTag:output_type -> gitaly.UserCreateTagResponse
- 15, // 144: gitaly.OperationService.UserDeleteTag:output_type -> gitaly.UserDeleteTagResponse
- 23, // 145: gitaly.OperationService.UserMergeToRef:output_type -> gitaly.UserMergeToRefResponse
- 26, // 146: gitaly.OperationService.UserRebaseToRef:output_type -> gitaly.UserRebaseToRefResponse
- 20, // 147: gitaly.OperationService.UserMergeBranch:output_type -> gitaly.UserMergeBranchResponse
- 30, // 148: gitaly.OperationService.UserFFBranch:output_type -> gitaly.UserFFBranchResponse
- 32, // 149: gitaly.OperationService.UserCherryPick:output_type -> gitaly.UserCherryPickResponse
- 41, // 150: gitaly.OperationService.UserCommitFiles:output_type -> gitaly.UserCommitFilesResponse
- 44, // 151: gitaly.OperationService.UserRebaseConfirmable:output_type -> gitaly.UserRebaseConfirmableResponse
- 35, // 152: gitaly.OperationService.UserRevert:output_type -> gitaly.UserRevertResponse
- 46, // 153: gitaly.OperationService.UserSquash:output_type -> gitaly.UserSquashResponse
- 51, // 154: gitaly.OperationService.UserApplyPatch:output_type -> gitaly.UserApplyPatchResponse
- 53, // 155: gitaly.OperationService.UserUpdateSubmodule:output_type -> gitaly.UserUpdateSubmoduleResponse
- 63, // 156: gitaly.OperationService.UserLand:output_type -> gitaly.UserLandResponse
- 140, // [140:157] is the sub-list for method output_type
- 123, // [123:140] is the sub-list for method input_type
- 123, // [123:123] is the sub-list for extension type_name
- 123, // [123:123] is the sub-list for extension extendee
- 0, // [0:123] is the sub-list for field type_name
+ 59, // 99: gitaly.LandConflict.messages:type_name -> gitaly.LandConflictMessage
+ 3, // 100: gitaly.LandConflictFile.kind:type_name -> gitaly.LandConflictFile.Kind
+ 58, // 101: gitaly.LandConflictFile.base:type_name -> gitaly.LandConflictSide
+ 58, // 102: gitaly.LandConflictFile.ours:type_name -> gitaly.LandConflictSide
+ 58, // 103: gitaly.LandConflictFile.theirs:type_name -> gitaly.LandConflictSide
+ 60, // 104: gitaly.LandConflictFile.hunks:type_name -> gitaly.LandConflictHunk
+ 4, // 105: gitaly.LandConflictFile.outcome:type_name -> gitaly.LandConflictFile.Outcome
+ 61, // 106: gitaly.LandConflictHunk.base:type_name -> gitaly.LineRange
+ 61, // 107: gitaly.LandConflictHunk.ours:type_name -> gitaly.LineRange
+ 61, // 108: gitaly.LandConflictHunk.theirs:type_name -> gitaly.LineRange
+ 63, // 109: gitaly.LandResolution.files:type_name -> gitaly.LandResolvedFile
+ 5, // 110: gitaly.LandResolvedFile.action:type_name -> gitaly.LandResolvedFile.Action
+ 27, // 111: gitaly.UserLandResponse.branch_update:type_name -> gitaly.OperationBranchUpdate
+ 77, // 112: gitaly.UserLandError.merge_conflict:type_name -> gitaly.MergeConflictError
+ 79, // 113: gitaly.UserLandError.not_ancestor:type_name -> gitaly.NotAncestorError
+ 73, // 114: gitaly.UserLandError.reference_update:type_name -> gitaly.ReferenceUpdateError
+ 71, // 115: gitaly.UserLandError.custom_hook:type_name -> gitaly.CustomHookError
+ 72, // 116: gitaly.UserLandError.access_check:type_name -> gitaly.AccessCheckError
+ 68, // 117: gitaly.UserRebaseConfirmableRequest.Header.repository:type_name -> gitaly.Repository
+ 69, // 118: gitaly.UserRebaseConfirmableRequest.Header.user:type_name -> gitaly.User
+ 68, // 119: gitaly.UserRebaseConfirmableRequest.Header.remote_repository:type_name -> gitaly.Repository
+ 74, // 120: gitaly.UserRebaseConfirmableRequest.Header.timestamp:type_name -> google.protobuf.Timestamp
+ 68, // 121: gitaly.UserApplyPatchRequest.Header.repository:type_name -> gitaly.Repository
+ 69, // 122: gitaly.UserApplyPatchRequest.Header.user:type_name -> gitaly.User
+ 74, // 123: gitaly.UserApplyPatchRequest.Header.timestamp:type_name -> google.protobuf.Timestamp
+ 6, // 124: gitaly.OperationService.UserCreateBranch:input_type -> gitaly.UserCreateBranchRequest
+ 9, // 125: gitaly.OperationService.UserUpdateBranch:input_type -> gitaly.UserUpdateBranchRequest
+ 11, // 126: gitaly.OperationService.UserDeleteBranch:input_type -> gitaly.UserDeleteBranchRequest
+ 16, // 127: gitaly.OperationService.UserCreateTag:input_type -> gitaly.UserCreateTagRequest
+ 14, // 128: gitaly.OperationService.UserDeleteTag:input_type -> gitaly.UserDeleteTagRequest
+ 22, // 129: gitaly.OperationService.UserMergeToRef:input_type -> gitaly.UserMergeToRefRequest
+ 25, // 130: gitaly.OperationService.UserRebaseToRef:input_type -> gitaly.UserRebaseToRefRequest
+ 19, // 131: gitaly.OperationService.UserMergeBranch:input_type -> gitaly.UserMergeBranchRequest
+ 29, // 132: gitaly.OperationService.UserFFBranch:input_type -> gitaly.UserFFBranchRequest
+ 31, // 133: gitaly.OperationService.UserCherryPick:input_type -> gitaly.UserCherryPickRequest
+ 40, // 134: gitaly.OperationService.UserCommitFiles:input_type -> gitaly.UserCommitFilesRequest
+ 43, // 135: gitaly.OperationService.UserRebaseConfirmable:input_type -> gitaly.UserRebaseConfirmableRequest
+ 34, // 136: gitaly.OperationService.UserRevert:input_type -> gitaly.UserRevertRequest
+ 45, // 137: gitaly.OperationService.UserSquash:input_type -> gitaly.UserSquashRequest
+ 49, // 138: gitaly.OperationService.UserApplyPatch:input_type -> gitaly.UserApplyPatchRequest
+ 52, // 139: gitaly.OperationService.UserUpdateSubmodule:input_type -> gitaly.UserUpdateSubmoduleRequest
+ 55, // 140: gitaly.OperationService.UserLand:input_type -> gitaly.UserLandRequest
+ 7, // 141: gitaly.OperationService.UserCreateBranch:output_type -> gitaly.UserCreateBranchResponse
+ 10, // 142: gitaly.OperationService.UserUpdateBranch:output_type -> gitaly.UserUpdateBranchResponse
+ 12, // 143: gitaly.OperationService.UserDeleteBranch:output_type -> gitaly.UserDeleteBranchResponse
+ 17, // 144: gitaly.OperationService.UserCreateTag:output_type -> gitaly.UserCreateTagResponse
+ 15, // 145: gitaly.OperationService.UserDeleteTag:output_type -> gitaly.UserDeleteTagResponse
+ 23, // 146: gitaly.OperationService.UserMergeToRef:output_type -> gitaly.UserMergeToRefResponse
+ 26, // 147: gitaly.OperationService.UserRebaseToRef:output_type -> gitaly.UserRebaseToRefResponse
+ 20, // 148: gitaly.OperationService.UserMergeBranch:output_type -> gitaly.UserMergeBranchResponse
+ 30, // 149: gitaly.OperationService.UserFFBranch:output_type -> gitaly.UserFFBranchResponse
+ 32, // 150: gitaly.OperationService.UserCherryPick:output_type -> gitaly.UserCherryPickResponse
+ 41, // 151: gitaly.OperationService.UserCommitFiles:output_type -> gitaly.UserCommitFilesResponse
+ 44, // 152: gitaly.OperationService.UserRebaseConfirmable:output_type -> gitaly.UserRebaseConfirmableResponse
+ 35, // 153: gitaly.OperationService.UserRevert:output_type -> gitaly.UserRevertResponse
+ 46, // 154: gitaly.OperationService.UserSquash:output_type -> gitaly.UserSquashResponse
+ 51, // 155: gitaly.OperationService.UserApplyPatch:output_type -> gitaly.UserApplyPatchResponse
+ 53, // 156: gitaly.OperationService.UserUpdateSubmodule:output_type -> gitaly.UserUpdateSubmoduleResponse
+ 64, // 157: gitaly.OperationService.UserLand:output_type -> gitaly.UserLandResponse
+ 141, // [141:158] is the sub-list for method output_type
+ 124, // [124:141] is the sub-list for method input_type
+ 124, // [124:124] is the sub-list for extension type_name
+ 124, // [124:124] is the sub-list for extension extendee
+ 0, // [0:124] is the sub-list for field type_name
}
func init() { file_operations_proto_init() }
@@ -6719,7 +6832,7 @@ func file_operations_proto_init() {
(*UserUpdateSubmoduleError_ReferenceUpdate)(nil),
(*UserUpdateSubmoduleError_PathError)(nil),
}
- file_operations_proto_msgTypes[58].OneofWrappers = []any{
+ file_operations_proto_msgTypes[59].OneofWrappers = []any{
(*UserLandError_MergeConflict)(nil),
(*UserLandError_NotAncestor)(nil),
(*UserLandError_ReferenceUpdate)(nil),
@@ -6732,7 +6845,7 @@ func file_operations_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_operations_proto_rawDesc), len(file_operations_proto_rawDesc)),
NumEnums: 6,
- NumMessages: 61,
+ NumMessages: 62,
NumExtensions: 0,
NumServices: 1,
},
diff --git a/proto/operations.proto b/proto/operations.proto
index b549e27..ec1f4b1 100644
--- a/proto/operations.proto
+++ b/proto/operations.proto
@@ -1300,12 +1300,16 @@ message LandConflict {
bytes commit_message = 5;
// messages_truncated is set when a message was cut.
bool messages_truncated = 6;
- // files are the conflicting files, at most max_files of them.
+ // files are all the conflicting files. A merge with more than 1000 conflicting
+ // files gets no package files: reason says so, and it cannot be resolved through a
+ // land.
repeated LandConflictFile files = 7;
// reason is set when the server did not try to resolve the request at all, for
// example because it has too many files or the actor may not resolve; it is cut to
// 512 bytes.
string reason = 8;
+ // messages are the messages of the merge about its conflicts, at most 1000.
+ repeated LandConflictMessage messages = 9;
}
// LandConflictFile is one conflicting file of a LandConflict.
@@ -1362,14 +1366,38 @@ message LandConflictFile {
// syntax_unchecked is set when a resolution of the file was accepted without a
// syntax verdict, because a side does not parse with the grammar of its language.
bool syntax_unchecked = 9;
+ // hunks_omitted says why hunks is empty or incomplete for a content or add/add
+ // conflict: a side too large to read, a diff over its cost bound, more regions
+ // than a file lists, or a package over its size bound. It is empty when hunks is
+ // complete, and for the kinds of conflict that have no hunks.
+ string hunks_omitted = 10;
}
// LandConflictSide is one side of a conflicting file; its content is read by oid.
message LandConflictSide {
- // oid is the object ID of the blob.
+ // oid is the object ID of the blob. It is set only for a blob in the tree of the
+ // merge base, the tip or the landed commit, which the repository keeps. A side
+ // that the merge wrote for this conflict alone (such as the content merge of a
+ // rename) is not kept after the land fails, so it has no oid and unavailable says
+ // why.
string oid = 1;
// mode is the file mode.
string mode = 2;
+ // unavailable is set instead of oid when the side's blob is not kept in the
+ // repository: its content cannot be read.
+ string unavailable = 3;
+}
+
+// LandConflictMessage is a message of the merge about a conflict, as git
+// merge-tree reports it. A conflict without a conflicting file (a directory rename
+// split, say) is described by its message alone.
+message LandConflictMessage {
+ // paths are the paths the message is about.
+ repeated bytes paths = 1;
+ // type is the kind of the conflict, such as "CONFLICT (rename/delete)".
+ string type = 2;
+ // message is the message, cut to 512 bytes.
+ string message = 3;
}
// LandConflictHunk is a conflicting region as line ranges of each side. Each range
diff --git a/sdk/conflict.go b/sdk/conflict.go
index 96b1f77..92a8343 100644
--- a/sdk/conflict.go
+++ b/sdk/conflict.go
@@ -22,44 +22,68 @@ func LandConflict(err error) (*gitalypb.LandConflict, bool) {
return detailOf[*gitalypb.LandConflict](err)
}
-// ConflictSides are the contents of the sides of a conflicting file; an absent side is nil.
+// ConflictSides are the contents of the sides of a conflicting file. An absent side is nil, and so
+// is a side that cannot be read: Unreadable gives the reason of each, by side ("base", "ours",
+// "theirs").
type ConflictSides struct {
Base, Ours, Theirs []byte
+ Unreadable map[string]string
}
-// ConflictSides reads the sides of every file of a conflict package, by path, with GetObjects.
+// ConflictSides reads the sides of every file of a conflict package, by path, with GetObjects. A
+// side that cannot be read costs only that side: one the package marks unavailable (the merge
+// wrote it for the conflict, and the repository did not keep it), or one the repository does not
+// have, is nil with its reason in Unreadable. An error is a failure to read at all.
func (r *Repo) ConflictSides(ctx context.Context, c *gitalypb.LandConflict) (map[string]ConflictSides, error) {
var oids []string
+ seen := map[string]bool{}
for _, f := range c.GetFiles() {
for _, s := range []*gitalypb.LandConflictSide{f.GetBase(), f.GetOurs(), f.GetTheirs()} {
- if s != nil {
- oids = append(oids, s.GetOid())
+ if oid := s.GetOid(); oid != "" && !seen[oid] {
+ seen[oid] = true
+ oids = append(oids, oid)
}
}
}
- objects, err := r.GetObjects(ctx, oids)
- if err != nil {
- return nil, err
- }
- data := make(map[string][]byte, len(objects))
- for _, o := range objects {
- if o.Missing {
- return nil, status.Errorf(codes.NotFound, "conflict side %s is missing from the repository", o.OID)
- }
- data[o.OID] = o.Data
- }
- read := func(s *gitalypb.LandConflictSide) []byte {
- if s == nil {
- return nil
+ data := make(map[string][]byte, len(oids))
+ missing := map[string]bool{}
+ if len(oids) > 0 {
+ objects, err := r.GetObjects(ctx, oids)
+ if err != nil {
+ return nil, err
}
- if b := data[s.GetOid()]; b != nil {
- return b
+ for _, o := range objects {
+ if o.Missing {
+ missing[o.OID] = true
+ continue
+ }
+ data[o.OID] = o.Data
}
- return []byte{}
}
out := make(map[string]ConflictSides, len(c.GetFiles()))
for _, f := range c.GetFiles() {
- out[string(f.GetPath())] = ConflictSides{Base: read(f.GetBase()), Ours: read(f.GetOurs()), Theirs: read(f.GetTheirs())}
+ var sides [3][]byte
+ unreadable := map[string]string{}
+ for i, s := range []*gitalypb.LandConflictSide{f.GetBase(), f.GetOurs(), f.GetTheirs()} {
+ name := []string{"base", "ours", "theirs"}[i]
+ switch {
+ case s == nil:
+ case s.GetOid() == "":
+ unreadable[name] = s.GetUnavailable()
+ case missing[s.GetOid()]:
+ unreadable[name] = "the blob " + s.GetOid() + " is missing from the repository"
+ default:
+ sides[i] = data[s.GetOid()]
+ if sides[i] == nil {
+ sides[i] = []byte{}
+ }
+ }
+ }
+ cs := ConflictSides{Base: sides[0], Ours: sides[1], Theirs: sides[2]}
+ if len(unreadable) > 0 {
+ cs.Unreadable = unreadable
+ }
+ out[string(f.GetPath())] = cs
}
return out, nil
}
diff --git a/sdk/integration_test.go b/sdk/integration_test.go
index c027cf5..1daaf44 100644
--- a/sdk/integration_test.go
+++ b/sdk/integration_test.go
@@ -836,6 +836,28 @@ func TestIntegration_Land(t *testing.T) {
require.NotContains(t, body, "Graft-Checked-By:")
})
+ t.Run("a side the repository does not keep", func(t *testing.T) {
+ t.Parallel()
+
+ // The tip renames a.txt to c.txt and changes its last line; the change changes its first
+ // line and adds a c.txt of its own. The tip's side of the add/add conflict on c.txt is the
+ // content merge of the rename, which no tree holds.
+ env := startIntegration(t, nil)
+ base := env.writeCommit(t, "main", map[string]string{"a.txt": "1\n2\n3\n4\n5\n6\n7\n8\n"})
+ env.writeCommit(t, "main", map[string]string{"c.txt": "1\n2\n3\n4\n5\n6\n7\neight\n"}, base)
+ change := env.writeCommit(t, "", map[string]string{"a.txt": "one\n2\n3\n4\n5\n6\n7\n8\n", "c.txt": "theirs\n"}, base)
+
+ _, err := env.repo.Land(env.ctx, sdk.LandOptions{Branch: "main", Commit: change.String(), User: user, ResolveConflicts: true})
+ pkg, ok := sdk.LandConflict(err)
+ require.True(t, ok, "got %v", err)
+ sides, err := env.repo.ConflictSides(env.ctx, pkg)
+ require.NoError(t, err, "an unavailable side fails no other side")
+ c := sides["c.txt"]
+ require.Nil(t, c.Ours)
+ require.Contains(t, c.Unreadable["ours"], "the merge wrote this blob")
+ require.Equal(t, []byte("theirs\n"), c.Theirs)
+ })
+
t.Run("create branch", func(t *testing.T) {
t.Parallel()