Skip to content

Patch

One file-level patch operation.

Patch values are returned by diff and yielded by decode.

Fields

source @ fs.Path [get]

Source path of the patch as a Path.

Present for delete, modify, move, and copy operations; reading it for a create raises FieldError.

Example
let p = [...patch.decode diff_text][0]
echo $p.source
target @ fs.Path [get]

Target path of the patch as a Path.

Present for create, modify, move, and copy operations; reading it for a delete raises FieldError.

Example
let p = [...patch.decode diff_text][0]
echo $p.target
type @ (:CREATE: | :DELETE: | :MODIFY: | :MOVE: | :COPY:) [get]

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

ApplyError if the patch does not apply cleanly, or a text result is not valid UTF-8.

Example

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