Documentation
¶
Overview ¶
Package merge merges three versions of a text file (ADR-0005, docs/design/sync.md#merge): the base both sides started from, the head (the hub's current version, or the version on disk for a local merge) and the incoming version. The head wins whatever still conflicts, and every conflict is reported so the caller can keep the incoming version as a conflict revision. Merges are deterministic and byte-exact: no input is normalized, and text that only one side touched keeps its bytes.
docs/specs/merge.md is the contract, and its fixtures are this package's golden tests (fixtures_test.go).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conflict ¶
type Conflict struct {
// Line is the 1-based line of Text where the head's side starts.
Line int
// Base, Head and Incoming are the hunk's three versions.
Base, Head, Incoming string
}
Conflict is one hunk the head won.
type Result ¶
type Result struct {
// Text is the merged file.
Text []byte
// Conflicts are the hunks where both sides changed the same text
// differently; Text holds the head's side of each.
Conflicts []Conflict
}
Result is a merge's output.
func Create ¶
Create merges two files created at the same path with no common revision, using the lines they share as the base. An empty side takes the other's content; two notes with nothing else in common conflict as a whole, and the head stands.
func Note ¶
Note merges a markdown note: frontmatter by top-level key, then the body as Text. Each key's lines (its value, nested lines, and the comments and blank lines after it) are one unit, so a key only one side touched keeps its bytes. A key both sides changed merges as Text, and if that conflicts the head's value stands. A key one side deleted and the other changed is kept, changed, and reported as a conflict. Frontmatter that cannot be split into keys (a repeated key) makes the whole note merge as Text.