mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 10:07:28 +00:00
cli: do not discard working copy changes recovered from stale state
Otherwise the subsequent command would rerun the checkout, which would fail if the diff contained added files.
This commit is contained in:
parent
51520bc87b
commit
7eed4068e9
2 changed files with 15 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue