add_to_index

Function add_to_index 

Source
pub fn add_to_index<T, I>(repo: &mut Repository, paths: I) -> Result<()>
where T: IntoCString, I: IntoIterator<Item = T>,
Expand description

Stage pathspecs into the index (like git add),

Treats each item in paths as a pathspec and passes the collection to git2::Index::add_all. Ignores honored; re‑adding existing staged entries is a no‑op.

Supported pathspecs:

  • Files: “src/main.rs”
  • Directories (recursive): “src/”
  • Globs (libgit2 syntax): “.rs”, “docs/**/.md”
  • Mixed file + pattern list

§Errors

  • Loading index fails.
  • Applying any pathspec fails.
  • Writing updated index fails.

§Future Work

  • Expose force option to include otherwise ignored files.
  • Return count of affected entries for diagnostics.