memory: base scoped commits on HEAD
This commit is contained in:
parent
0c9db09888
commit
9ceaf61fa6
1 changed files with 48 additions and 0 deletions
|
|
@ -619,6 +619,15 @@ impl MemoryRepo {
|
|||
let repo = self.open_git()?;
|
||||
let mut index = repo.index().context("opening git index")?;
|
||||
|
||||
// A path-scoped commit starts from HEAD, not a possibly stale index.
|
||||
// Repos created before index persistence otherwise suffer one last eviction.
|
||||
if !repo.is_empty()? {
|
||||
let head_tree = repo.head()?.peel_to_tree()?;
|
||||
index
|
||||
.read_tree(&head_tree)
|
||||
.context("seeding git index from HEAD")?;
|
||||
}
|
||||
|
||||
for path in paths {
|
||||
let rel_path = self.to_relative(path);
|
||||
// Try with .md extension if not present
|
||||
|
|
@ -1475,6 +1484,45 @@ mod tests {
|
|||
assert!(!status.has_uncommitted);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn next_write_repairs_a_legacy_stale_index() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let repo = MemoryRepo::new("test-agent", dir.path());
|
||||
repo.init().await.unwrap();
|
||||
repo.write("journal/first", "first thought").await.unwrap();
|
||||
|
||||
let git = git2::Repository::open(repo.root()).unwrap();
|
||||
let mut stale_index = git.index().unwrap();
|
||||
stale_index.clear().unwrap();
|
||||
stale_index.write().unwrap();
|
||||
drop(stale_index);
|
||||
drop(git);
|
||||
|
||||
repo.write("journal/second", "second thought")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let git = git2::Repository::open(repo.root()).unwrap();
|
||||
let head = git.head().unwrap().peel_to_commit().unwrap();
|
||||
let tree = head.tree().unwrap();
|
||||
let index = git.index().unwrap();
|
||||
for path in [
|
||||
"system/persona.md",
|
||||
"system/state.md",
|
||||
"journal/first.md",
|
||||
"journal/second.md",
|
||||
] {
|
||||
assert!(
|
||||
tree.get_path(Path::new(path)).is_ok(),
|
||||
"HEAD lost {path}"
|
||||
);
|
||||
assert!(
|
||||
index.get_path(Path::new(path), 0).is_some(),
|
||||
"index lost {path}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn delete_survives_in_head_and_index() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue