Skip to content

Piping hledger rewrite --diff to patch fails #2548

@MatejaMaric

Description

@MatejaMaric

Output of hledger setup:

Checking your hledger setup..
Legend: good, neutral, unknown, warning

hledger
* is a released version ?                  yes  hledger 1.51.2, mac-aarch64
* is up to date ?                          yes  1.51.2 installed, latest is 1.51.2
* is a native binary for this machine ?    yes  aarch64
* is installed in PATH (this version) ?    yes  /opt/homebrew/bin/hledger
* has a system text encoding configured ?  yes  UTF-8, data files must use this encoding
* has a user config file ?                  no
* has a local config file ?                 no

terminal
* the NO_COLOR variable is defined ?        no
* --color is configured by config file ?    no
* hledger will use color by default ?      yes
* the PAGER variable is defined ?           no
* --pager is configured by config file ?    no
* hledger will use a pager when needed ?   yes  /usr/bin/less
* the LESS variable is defined ?           yes
* the HLEDGER_LESS variable is defined ?    no
* adjusting LESS variable for color etc. ? yes
* tables will use box-drawing chars ?       no  you can use --pretty to enable them

journal
* the LEDGER_FILE variable is defined ?    yes  /Users/mateja/Documents/finance/potrosnja.hledger
* a default journal file is readable ?     yes  /Users/mateja/Documents/finance/potrosnja.hledger
* it includes additional files ?           yes  6 files
* all commodities are declared ?           yes  5 commodities
* all accounts are declared ?              yes  84 accounts
* all accounts have types ?                 no  10 accounts without types
* accounts of all types exist ?            yes  ALERXCV accounts detected
* commodities/accounts are being checked ?  no  you can use -s to check them
* balance assertions are being checked ?   yes  you can use -I to ignore them

Operating system I'm running:

  System Version:	macOS 26.2 (25C56)
  Kernel Version:	Darwin 25.2.0

Link to the most relevant doc that I found: https://hledger.org/1.51/hledger.html#diff-output-format

Reproducible example:

sample.journal

= expenses:groceries date:2026-01-01..
    assets:funds:budget:month:food      *-1
    liabilities:funds                    *1

2026-01-01 Supermarket
    expenses:groceries     100 USD
    assets:bank           -100 USD

2026-01-02 Something
    expenses:other         100 USD
    assets:bank           -100 USD

2026-01-03 Something
    expenses:other         100 USD
    assets:bank           -100 USD

2026-01-04 Supermarket
    expenses:groceries     100 USD
    assets:bank           -100 USD

2026-01-05 Something
    expenses:other         100 USD
    assets:bank           -100 USD

When I run hledger rewrite --diff -f sample.journal | patch I get the following error:

patching file sample.journal
2 out of 2 hunks failed--saving rejects to sample.journal.rej

Content of sample.journal.rej:

@@ -5,3 +5,5 @@
 2026-01-01 Supermarket
-    expenses:groceries     100 USD
-    assets:bank           -100 USD
+    expenses:groceries                     100 USD
+    assets:funds:budget:month:food        -100 USD
+    liabilities:funds                      100 USD
+    assets:bank                           -100 USD
@@ -17,3 +19,5 @@
 2026-01-04 Supermarket
-    expenses:groceries     100 USD
-    assets:bank           -100 USD
+    expenses:groceries                     100 USD
+    assets:funds:budget:month:food        -100 USD
+    liabilities:funds                      100 USD
+    assets:bank                           -100 USD

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.affects3-fewAffects just a few users.annoyance4-majorMajor usability/doc bug, or any regression or crash.rewrite

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions