Skip to content

patch: -p/--strip is parsed but never applied — patch always strips 0 components #1345

Closed

Description

@caomengxuan666

patch: -p/--strip is parsed but never applied — patch always strips 0 components

patch.cpp::execute builds a full ParsedOptions opts via the shared parser, then never reads it: it calls apply_unified_diff(...) which itself re-scans argv, looks only for the literal forms -i/--input and a ^-p prefix, and passes a hardcoded strip count of 0 to its two apply call sites. -pN, --strip=N and --strip N therefore have no effect, and files named by the patch headers are opened literally.

Verified with the same-source harness under Wine, twice, against GNU patch 2.7.6 (fixture: src/f.txt containing l1/l2/l3, a unified diff addressed to a/src/f.txt / b/src/f.txt):

$ patch -p1 < p.diff
winx: patch: cannot open file 'b/src/f.txt': No such file or directory   (exit 2, file unchanged)
gnu : (applies)                                                          (exit 0, src/f.txt now l1/L2/l3)

Minor same-command observations from the same probes: for an unknown option, patch prints the help hint without its program prefix and with the generic exit code — winx patch: unrecognized option '--bogus' + Try 'patch --help' for more information. (exit 1) vs GNU patch: unrecognized option '--bogus' + patch: Try 'patch --help' for more information. (exit 2).

Expected (GNU)

  • -pN/--strip=N strip N leading path components from header file names; --strip N likewise.
  • The parsed options structure should be the single source the applier consumes.

Regression seed

In-repo test named with this issue number: fixture above; patch -p1 applies the hunk to src/f.txt (content + exit 0 asserted); patch -p0 on the same input must fail to find a/src/f.txt; --strip=1 and --strip 1 forms behave identically to -p1.

Activity

  1. added
    bug
    compat-gap
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcompat-gap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions