Skip to content

Patch

One file-level patch operation.

Patch values are returned by diff and yielded by decode.

Fields

source

Source path of the patch as a Path.

Present for delete, modify, move, and copy operations.

Example
let p = [...patch.decode diff_text][0]
echo $p.source
target

Target path of the patch as a Path.

Present for create, modify, move, and copy operations.

Example
let p = [...patch.decode diff_text][0]
echo $p.target
type

Operation kind as a symbol.

One of :CREATE:, :DELETE:, :MODIFY:, :MOVE:, or :COPY:.

Example
let p = patch.diff "alpha\n" "beta\n"
assert_eq $p.type :MODIFY:

Methods

apply base -> (Str | Bin)

Applies the patch to base.

Parameters

NameTypeDescription
base (Str | Bin) Content to patch. Text content must still be valid UTF-8 once patched.

Returns

The same type as base.

Errors

Exception Condition
ApplyError The patch does not apply cleanly
ApplyError A text result is not valid UTF-8
TypeError base is not Str or Bin

Example

let p = patch.diff "alpha\n" "beta\n"
assert_eq (p.apply "alpha\n") "beta\n"