Fixer tail-line deletion lost when an unstaged edit overlaps it (different case from #929/#965) #988
-
|
Versions: hk 1.47.0 and 1.48.0 (latest), git 2.x, macOS arm64. Reproduces on both. SummaryIf a file is partially staged, a fixer deletes lines at the end of the staged content, and there's an unstaged edit in the middle of the same file, the stash restore puts the deleted tail lines back in the worktree. The commit itself is fine (the index keeps the fixer's deletion), but the worktree ends up reverted to the full pre-hook content, so the fixer's deletion and the staged edit are both gone from disk. This is a different case from #929/#931. That fix made Reprover=1.48.0
git init t && cd t
git config user.email r@e.c && git config user.name r
cat > hk.pkl <<EOF
amends "package://github.com/jdx/hk/releases/download/v${ver}/hk@${ver}#/Config.pkl"
hooks { ["pre-commit"] { fix = true; stash = "patch-file"; steps {
["fixer"] { glob = "f.txt"; fix = "head -2 f.txt > .t && mv .t f.txt"; stage = List("f.txt") }
} } }
EOF
printf 'l1\nl2\nl3\nl4\nl5\n' > f.txt
git add -A && git commit -qm base
printf 'l1 STAGED\nl2\nl3\nl4\nl5\n' > f.txt # staged edit on line 1
git add f.txt
printf 'l1 STAGED\nl2\nl3 UNSTAGED\nl4\nl5\n' > f.txt # unstaged edit in the middle
hk run pre-commit
cat f.txtExpected: the fixer truncates the file to 2 lines, so after the restore the worktree should have the unstaged middle edit merged on top of that, with l4/l5 still deleted. (The index gets this right.) Actual: the worktree is back to all 5 lines. Where it happensIn
The two hunks overlap at base line 2. while fi < fixer_hunks.len() && fixer_hunks[fi].start < idx { fi += 1; }skips the fixer hunk because its Workaround attempts
Happy to test a patch; the repro above is self-contained. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
#990