upsertManagedBlock
upsertManagedBlock(
content,__namedParameters):string
Defined in: managed-block.ts:59
Inserts or replaces a block of lines delimited by marker lines, leaving everything outside it untouched.
- Block present (
start…end): replaced in place. - No block: appended, separated from existing content by a blank line, with a single trailing newline.
startpresent butendmissing (hand-edited or truncated): the block is taken to run to the next blank line, or to the end of the file — so the content after it is kept, not lost. Anendmarker only closes the block when it comes before that blank line; one further down is left alone.
Line endings follow the existing text (\r\n when it mostly uses them), so
a CRLF file stays CRLF. That is also why lines can’t contain blank lines: a
blank line is how an unterminated block is told apart from the next section.
Idempotent: calling it again with the same options returns the same text. There are no default markers; callers choose them, and must keep them stable so existing blocks are still found.
Parameters
Section titled “Parameters”content
Section titled “content”string
__namedParameters
Section titled “__namedParameters”Returns
Section titled “Returns”string
Throws
Section titled “Throws”when an entry in lines is blank or contains a line break.
Example
Section titled “Example”import { upsertManagedBlock } from "@theholocron/git-utils";
upsertManagedBlock("node_modules\n", { start: "# managed: skills", end: "# end managed: skills", lines: ["/.agents/"],});// "node_modules\n\n# managed: skills\n/.agents/\n# end managed: skills\n"