diff --git a/src/commands.rs b/src/commands.rs index 1a3a0c7d1..9a67fe2c9 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -593,6 +593,7 @@ impl WorkspaceCommandHelper { // divergence. let checkout_commit = repo.store().get_commit(&checkout_id)?; let wc_tree_id = locked_wc.old_tree_id().clone(); + let mut wc_was_stale = false; if *checkout_commit.tree_id() != wc_tree_id { let wc_operation_data = self .repo @@ -636,6 +637,7 @@ impl WorkspaceCommandHelper { err )) })?; + wc_was_stale = true; } else { return Err(CommandError::InternalError(format!( "The repo was loaded at operation {}, which seems to be a sibling of the \ @@ -674,6 +676,8 @@ impl WorkspaceCommandHelper { self.repo = tx.commit(); locked_wc.finish(self.repo.op_id().clone()); + } else if wc_was_stale { + locked_wc.finish(self.repo.op_id().clone()); } else { locked_wc.discard(); } diff --git a/tests/test_workspaces.rs b/tests/test_workspaces.rs index cecf6d407..411f96f7c 100644 --- a/tests/test_workspaces.rs +++ b/tests/test_workspaces.rs @@ -124,6 +124,17 @@ fn test_workspaces_conflicting_edits() { o 52601f748bf6cb00ad5389922f530f20a7ecffaa o 0000000000000000000000000000000000000000 "###); + + // The stale working copy should have been resolved by the previous command + let stdout = get_log_output(&test_env, &secondary_path); + assert!(!stdout.starts_with("The working copy is stale")); + insta::assert_snapshot!(stdout, @r###" + @ 8d8269a323a01a287236c4fd5f64dc9737febb5b secondary@ + | o 6d004761e81306cf8b2168a18868fbc84f182556 default@ + |/ + o 52601f748bf6cb00ad5389922f530f20a7ecffaa + o 0000000000000000000000000000000000000000 + "###); } /// Test forgetting workspaces