Repository navigation
Commit ea9573c
authored
Preserve standard input bytes when forwarding hooks (sds#925)
Overcommit forwards ad hoc hook input using `puts`, which adds a newline
to an empty stream or to an unterminated record. For a post-rewrite
consumer such as git-branchless, an empty stream becomes a blank record
and fails with `Invalid rewrite line`.
Read hook stdin and write the supplied subprocess input in binary mode.
This preserves empty input, record terminators, and arbitrary bytes on
Windows as well as Unix, while still closing stdin so the child sees
EOF.
Fixes sds#869.
Reproduced locally through an installed post-rewrite CustomScript using
a small parser with git-branchless's empty-stream/blank-record behavior.
Before the fix, empty input fails with `Invalid rewrite line`, and
unterminated input gains a newline. The fixture verifies arguments and
exact bytes for empty, unterminated, LF, multiline, and CRLF input.
Subprocess tests also cover binary data; existing expectations that
assumed an added newline now expect the actual supplied input.
Validation: full local RSpec suite (1,738 examples); RuboCop on all
changed Ruby files. Full Linux/Windows CI runs on the PR.
Also verified against git-branchless 0.11.1 downloaded into `/tmp` and
initialized only in a disposable repository: forwarding an empty stream
exits 0; forwarding the injected blank line exits 1 with `Invalid
rewrite line`. No system installation or existing repository
configuration was changed.
The first Windows CI run exposed stdin CRLF conversion before
forwarding; HookContext now reads the original stream in binary mode as
well. The CRLF integration case remains identical on every platform.1 parent aa7cd10 commit ea9573c
5 files changed
Lines changed: 62 additions & 4 deletions
File tree
- lib/overcommit
- hook_context
- spec
- integration
- overcommit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
103 | 106 | | |
104 | 107 | | |
105 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
55 | 66 | | |
56 | 67 | | |
57 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | | - | |
| 324 | + | |
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| |||
0 commit comments