rgit stage, unstage and discard take many paths, and --hunk takes rgit's own start lines
Statement#
rgit stage,unstageanddiscardtake several paths, folders and globs, likegit addandgit restore(rgit3699e76and later). Older builds took one path per call:stagerefused a folder withcannot create blob ... it is a directory, anddiscardwith two paths failed witherror: unexpected argument '<second path>' found. On an older build, loop:for f in a b; do rgit discard "$f"; done.--hunktakes several new-side start lines, comma-separated (--hunk 10,42, rgit8d37a5dand later). Take them fromrgit diff --patch; they can differ by a line fromgit diff.- Before rgit
5d47390, a--hunknumber that matched no hunk still reported "staged part" and exited 0 while staging nothing. A commit made next went in without that hunk. From5d47390,stage,unstage,discardand--linesfail with exit 1 when N matches no hunk, stage nothing, and list the start lines:
error: "no hunk at line 99 of f.txt; hunks start at: 1, 22"
help: Run `rgit diff --patch` to see the current hunks
On an older build, run git diff --cached --stat after a hunk stage and before rgit commit.
- Cause of the old defect:
--hunklooks each N up among rgit's own hunk start lines.stage_hunkapplied the diff with a libgit2 hunk callback that matched no hunk, sorepo.applywrote nothing and returned success.unstage,discardand--linesalready failed on a missing hunk, but their error did not list the valid start lines.
Evidence#
2026-09-27, dftracer-utils: rgit discard with 10 paths failed as above; one call per path discarded all 10.
2026-09-27: in the rkb repository a commit went in without its test hunk after --hunk 1021 (rgit's number was 1022), found by checking the index (git diff placed the hunk at 1021, rgit's own diff at 1022). The matching commit was then amended with rgit's number. In a scratch repository with rgit 3699e76, rgit stage d g.txt staged a folder and a file, and rgit stage f.txt --hunk 99 printed "staged part of f.txt", exited 0 and staged nothing.
2026-09-27, rgit 3699e76: rgit discard dir c.txt and rgit unstage dir c.txt worked in one call (test stage_unstage_and_discard_take_many_paths_folders_and_globs in crates/rgit-cli/tests/paths.rs). rgit 5d47390: rgit stage f.txt --hunk 99 printed no hunk at line 99 of f.txt; hunks start at: 1, 22 and exited 1. The test a_line_that_starts_no_hunk_is_an_error in crates/rgit-cli/tests/hunks.rs covers it.
Also found by searching
- error: unexpected argument '<second path>' found
- cannot create blob ... it is a directory
- rgit stage --hunk printed staged part but nothing is in the index
- how do I stage several files or hunks with rgit in one call
- rgit --hunk number differs from git diff by one line
- rgit discard a.txt b.txt -> error: unexpected argument 'b.txt' found
- rgit stage --hunk said it staged part of the file but nothing was in the index and the commit missed the test
- how do I stage several files or several hunks at once with rgit, and which line numbers does --hunk take?