LibraLibra
LibraLibra
DocsBlogLibra
Getting Started
Architecture
Design
Commands
libra addlibra agentlibra alternateslibra applylibra archivelibra authlibra automationlibra bisectlibra blamelibra branchlibra bundlelibra cachelibra cat-filelibra check-attrlibra check-ignorelibra check-mailmaplibra checkoutlibra cherry-picklibra cleanlibra clonelibra cloudlibra code-controllibra codelibra commit-treelibra commitlibra completionslibra configlibra credentiallibra depslibra describelibra diff-fileslibra diff-indexlibra diff-treelibra difflibra dirtylibra fast-exportlibra fast-importlibra fetchlibra filelibra for-each-reflibra format-patchlibra fscklibra gclibra graphlibra greplibra hash-objectlibra hookslibra hydratelibra index-packlibra initlibra investigatelibra layerlibra lfslibra loglibra logfilelibra loginlibra logoutlibra ls-fileslibra ls-remotelibra ls-treelibra maintenancelibra medialibra merge-baselibra merge-filelibra mergelibra metadatalibra mvlibra noteslibra oplibra openlibra pack-objectslibra packagelibra prunelibra publishlibra pulllibra pushlibra read-treelibra rebaselibra refloglibra remotelibra repacklibra replacelibra rererelibra resetlibra restorelibra rev-listlibra rev-parselibra revertlibra reviewlibra revisionlibra rmlibra sandboxlibra servicelibra shortloglibra show-reflibra showlibra sparse-viewlibra stashlibra statslibra statuslibra switchlibra symbolic-reflibra taglibra update-indexlibra update-reflibra usagelibra verify-packlibra whoamilibra worktreelibra write-tree
API Reference
Policy
Commands

libra apply

Command reference for `libra apply`

Check whether a unified-diff patch applies cleanly — an MVP of git apply --check. This version validates only: it parses the patch, safety-checks every target path, and test-applies each file's hunks against the current working tree without writing anything.

Synopsis

libra apply --check [-p<n>] [<patch>...]

Description

apply --check reads one or more unified-diff patches (from the named files, or from stdin when none are given), splits them into per-file sections, and for each file:

  1. parses the hunks (a malformed patch is a fatal error);
  2. resolves the target path, stripping <n> leading components (-p<n>, default 1) and rejecting any path that is absolute, contains .., contains a NUL, or points inside .libra/;
  3. test-applies the hunks to the current file content (an empty base for a new-file patch whose source is /dev/null).

If every file applies, the exit code is 0; if any file does not apply, it is 1. The working tree is never modified. Actually applying a patch (with an atomic temp-file + rename) is a planned future extension; --check is required today.

Patches larger than 64 MiB are rejected.

Options

OptionDescriptionExample
--checkValidate without writing (required in this version).libra apply --check fix.patch
-p<n>Strip <n> leading path components from each path (default 1).libra apply --check -p0 fix.patch
--json / --machineStructured output: { applies, files }.libra --json apply --check fix.patch

Exit codes

CodeMeaning
0The patch applies cleanly.
1The patch does not apply (conflicting context or a missing target).
128Not inside a repository, --check was omitted, the patch is malformed/oversized/non-UTF-8, or a target path is unsafe.

Examples

# Will this patch apply to the current tree?
libra apply --check fix.patch && echo "clean"

# Patch made without a/ b/ prefixes
libra apply --check -p0 fix.patch

# From a pipeline
git format-patch -1 --stdout | libra apply --check

Comparison with Git

TaskLibraGit
Check a patchlibra apply --check pgit apply --check p
Path striplibra apply --check -p0 pgit apply --check -p0 p

Differences and deferred features: actually applying the patch (without --check), --index / --cached, --3way, --reverse, --unidiff-zero, binary patches, and rename/mode hunks are not yet supported. Conflict markers are never written — --check only reports.

libra alternates

Command reference for `libra alternates`

libra archive

Command reference for `libra archive`

On this page

SynopsisDescriptionOptionsExit codesExamplesComparison with Git