fix(kvb-git-commit-next): renumber kept hunks in stage_hunks.py
git apply --unidiff-zero places an add-only hunk, which has no context to match, at its new-side start line. That line counts every earlier hunk of the diff, so each hunk select() dropped shifted the later add-only hunks down by its size: on the real README a staged node landed in the wrong Mermaid subgraph. renumber() rewrites each kept header from the old start plus the net lines of the hunks kept before it (+1 for a pure insertion, -1 for a pure deletion), with counts that match the kept lines. A new test drops an early hunk and a line of a mixed one and compares the whole staged file; against the previous script it fails with the line one place too low. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43b0949f6b
commit
4ffbc85411
2 files changed
+27
-1
No files matched your search
@@ -55,6 +55,16 @@ class TestStageHunks(unittest.TestCase):
|
||||
unstaged = [line for line in self._git("diff", "-U0").splitlines() if line.startswith("+") and not line.startswith("+++")]
|
||||
self.assertEqual(unstaged, ["+beta one", "+beta two"])
|
||||
|
||||
def test_kept_lines_land_where_they_stand_after_dropped_hunks(self):
|
||||
self.file.write_text(
|
||||
"one\nbeta one\ntwo\nthree\nalpha three\nbeta three\nfour\nfive\nalpha five\n", encoding="utf-8"
|
||||
)
|
||||
result = self._run("alpha")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(
|
||||
self._git("show", ":notes.txt"), "one\ntwo\nthree\nalpha three\nfour\nfive\nalpha five\n"
|
||||
)
|
||||
|
||||
def test_no_match_exits_1_and_bad_pattern_exits_2(self):
|
||||
self.assertEqual(self._run("gamma").returncode, 1)
|
||||
self.assertEqual(self._run("(").returncode, 2)
|
||||
|
||||
Reference in new issue
Block a user