Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8391,6 +8391,38 @@ impl ActorDaemonCoordinator {
};
let stash_sha =
Self::resolve_stash_sha_for_event(cmd, &operation, stash_ref.as_deref())?;
if stash_sha.is_none()
&& matches!(
operation,
StashOperation::Apply
| StashOperation::Pop
| StashOperation::Branch
| StashOperation::Drop
)
{
// A failed command with no target (a `pop` on an empty
// stack) changed nothing. A successful one with no
// target loses only this stash's attribution.
if cmd.exit_code != 0 {
tracing::debug!(
component = "daemon",
root_sid = %cmd.root_sid,
?operation,
?stash_ref,
exit_code = cmd.exit_code,
"skipping failed stash event without a target oid"
);
} else {
tracing::warn!(
component = "daemon",
root_sid = %cmd.root_sid,
?operation,
?stash_ref,
"skipping stash event: target oid is unresolved"
);
}
continue;
}
let head_sha = match operation {
StashOperation::Create => Self::resolve_stash_create_head_for_event(
cmd,
Expand All @@ -8412,19 +8444,6 @@ impl ActorDaemonCoordinator {
} else {
Vec::new()
};
if matches!(
operation,
StashOperation::Apply
| StashOperation::Pop
| StashOperation::Branch
| StashOperation::Drop
) && stash_sha.is_none()
{
return Err(AutterError::Generic(format!(
"stash {:?} missing resolvable target oid sid={} ref={:?}",
operation, cmd.root_sid, stash_ref
)));
}
if matches!(
operation,
StashOperation::Create
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/stash_attribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,36 @@ fn test_stash_pop_empty_repo() {
assert!(result.is_err(), "Should fail when no stash exists");
}

#[test]
fn test_stash_pop_empty_stack_does_not_fail_daemon_side_effects() {
let repo = TestRepo::new();

let mut readme = repo.filename("README.md");
readme.set_contents(vec!["# Test Repo".to_string()]);
repo.stage_all_and_commit("initial commit")
.expect("commit should succeed");
readme.assert_committed_lines(vec!["# Test Repo".human()]);

// Pop with no stash ever created.
assert!(repo.git(&["stash", "pop"]).is_err());
// Panics if the daemon recorded a side-effect error for the failed pop.
repo.sync_daemon();

let mut example = repo.filename("example.txt");
example.set_contents(vec!["AI content".ai()]);
repo.git(&["stash"]).expect("stash should succeed");
repo.git(&["stash", "pop"])
.expect("stash pop should succeed");

// Pop again after the stack is empty.
assert!(repo.git(&["stash", "pop"]).is_err());
repo.sync_daemon();

repo.stage_all_and_commit("apply stashed changes")
.expect("commit should succeed");
example.assert_committed_lines(vec!["AI content".ai()]);
}

#[test]
fn test_stash_mixed_human_and_ai() {
let repo = TestRepo::new();
Expand Down
Loading