git: refresh index stat cache after CLI status
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! Read-only snapshots and patches. Ordinary Git state only; never refresh/write the index.
|
||||
//! Snapshots and patches. Only CLI status refreshes the ordinary Git index stat cache.
|
||||
use crate::Result;
|
||||
use crate::{
|
||||
HeadInfo, head_info,
|
||||
@@ -223,6 +223,13 @@ fn changes(old: &Snapshot, new: &Snapshot) -> Vec<Change> {
|
||||
.collect()
|
||||
}
|
||||
pub fn status(repo: &gix::Repository) -> Result<Status> {
|
||||
status_inner(repo, false)
|
||||
}
|
||||
/// CLI status refreshes cached file stats. RPC status remains read-only.
|
||||
pub fn refresh_status(repo: &gix::Repository) -> Result<Status> {
|
||||
status_inner(repo, true)
|
||||
}
|
||||
fn status_inner(repo: &gix::Repository, refresh: bool) -> Result<Status> {
|
||||
repo::worktree(repo)?;
|
||||
let (index, conflicts) = index(repo)?;
|
||||
let mut head = tree(repo, "HEAD")?;
|
||||
@@ -237,13 +244,13 @@ pub fn status(repo: &gix::Repository) -> Result<Status> {
|
||||
conflicted: conflicts.iter().map(|p| display(p)).collect(),
|
||||
};
|
||||
use gix::status::index_worktree::{Item, iter::Summary};
|
||||
let iter = repo
|
||||
let mut iter = repo
|
||||
.status(gix::progress::Discard)
|
||||
.map_err(|e| error("status", e))?
|
||||
.untracked_files(gix::status::UntrackedFiles::Files)
|
||||
.into_index_worktree_iter(Vec::<gix::bstr::BString>::new())
|
||||
.map_err(|e| error("status", e))?;
|
||||
for item in iter {
|
||||
for item in iter.by_ref() {
|
||||
let item = item.map_err(|e| error("status", e))?;
|
||||
#[cfg(target_os = "wasi")]
|
||||
if matches!(
|
||||
@@ -285,6 +292,13 @@ pub fn status(repo: &gix::Repository) -> Result<Status> {
|
||||
},
|
||||
});
|
||||
}
|
||||
if refresh
|
||||
&& let Some(mut outcome) = iter.into_outcome()
|
||||
&& outcome.has_changes()
|
||||
{
|
||||
// A read-only repository must still support status, like native Git.
|
||||
let _ = outcome.write_changes();
|
||||
}
|
||||
result.unstaged.sort_by(|a, b| a.path.cmp(&b.path));
|
||||
result.untracked.sort();
|
||||
Ok(result)
|
||||
|
||||
Reference in New Issue
Block a user