merge

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Create(head, incoming []byte) Result

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

func Note(base, head, incoming []byte) Result

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.

func Text

func Text(base, head, incoming []byte) Result

Text merges plain text by line. A hunk both sides changed differently merges again by word; where both sides only inserted lines at the same place, both insertions are kept, the head's first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL