Ray's Knowledge Base
Unlock

rgit stage, unstage and discard take many paths, and --hunk takes rgit's own start lines

FactVerified 28 Sep 2026Holds anywhere
Fact. A statement and the evidence for it.

Statement#

  • rgit stage, unstage and discard take several paths, folders and globs, like git add and git restore (rgit 3699e76 and later). Older builds took one path per call: stage refused a folder with cannot create blob ... it is a directory, and discard with two paths failed with error: unexpected argument '<second path>' found. On an older build, loop: for f in a b; do rgit discard "$f"; done.
  • --hunk takes several new-side start lines, comma-separated (--hunk 10,42, rgit 8d37a5d and later). Take them from rgit diff --patch; they can differ by a line from git diff.
  • Before rgit 5d47390, a --hunk number that matched no hunk still reported "staged part" and exited 0 while staging nothing. A commit made next went in without that hunk. From 5d47390, stage, unstage, discard and --lines fail 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: --hunk looks each N up among rgit's own hunk start lines. stage_hunk applied the diff with a libgit2 hunk callback that matched no hunk, so repo.apply wrote nothing and returned success. unstage, discard and --lines already 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?