diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 33ee97ab43..729897d94f 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -57,7 +57,7 @@ use jj_lib::revset::{ RevsetAliasesMap, RevsetExpression, RevsetExtensions, RevsetFilterPredicate, RevsetIteratorExt, RevsetModifier, RevsetParseContext, RevsetWorkspaceContext, SymbolResolverExtension, }; -use jj_lib::rewrite::restore_tree; +use jj_lib::rewrite::{merge_commit_trees, restore_tree}; use jj_lib::settings::{ConfigResultExt as _, UserSettings}; use jj_lib::signing::SignInitError; use jj_lib::str_util::StringPattern; @@ -1280,7 +1280,6 @@ See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-workin if num_rebased > 0 { writeln!(ui.status(), "Rebased {num_rebased} descendant commits")?; } - let old_repo = tx.base_repo().clone(); let maybe_old_wc_commit = old_repo @@ -1304,10 +1303,23 @@ See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-workin } self.user_repo = ReadonlyUserRepo::new(tx.commit(description)); self.report_repo_changes(ui, &old_repo)?; - if self.may_update_working_copy { if let Some(new_commit) = &maybe_new_wc_commit { - self.update_working_copy(ui, maybe_old_wc_commit.as_ref(), new_commit)?; + self.update_working_copy(ui, maybe_old_wc_commit.as_ref(), &new_commit)?; + println!("{:?}", new_commit.id()); + if self.check_rewritable([new_commit.id()]).is_err() { + let settings = self.settings.clone(); + let mut tx = self.start_transaction(); + let _top_commit = tx + .mut_repo() + .new_commit( + &settings, + vec![new_commit.id().clone()], + new_commit.tree_id().clone(), + ) + .write()?; + tx.finish(ui, "added mutable commit to avoid @ immutable.")?; + } } else { // It seems the workspace was deleted, so we shouldn't try to // update it.