From c42a9419163f947445ed0ccf9ca1d2542adc5b27 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 6 Sep 2024 09:20:24 -0700 Subject: [PATCH] cli: don't create a new working-copy commit for already immutable commits --- cli/src/cli_util.rs | 6 ++++++ cli/tests/test_git_private_commits.rs | 3 --- cli/tests/test_immutable_commits.rs | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 4122a024f..91cbd4927 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -1476,9 +1476,15 @@ See https://martinvonz.github.io/jj/latest/working-copy/#stale-working-copy \ tx.mut_repo().view().wc_commit_ids().clone().iter().sorted() //sorting otherwise non deterministic order (bad for tests) { + // Create a new working-copy commit in the workspace if the working copy became + // immutable (but not if it already was) if self .check_repo_rewritable(tx.repo(), [wc_commit_id]) .is_err() + && tx.base_repo().index().has_id(wc_commit_id) + && !self + .check_repo_rewritable(tx.base_repo().as_ref(), [wc_commit_id]) + .is_err() { let wc_commit = tx.repo().store().get_commit(wc_commit_id)?; tx.mut_repo() diff --git a/cli/tests/test_git_private_commits.rs b/cli/tests/test_git_private_commits.rs index 3fec135f9..54243d261 100644 --- a/cli/tests/test_git_private_commits.rs +++ b/cli/tests/test_git_private_commits.rs @@ -138,9 +138,6 @@ fn test_git_private_commits_are_not_checked_if_immutable() { insta::assert_snapshot!(stderr, @r###" Branch changes to push to origin: Move forward branch main from 7eb97bf230ad to aa3058ff8663 - Warning: The working-copy commit in workspace 'default' became immutable, so a new commit has been created on top of it. - Working copy now at: yostqsxw dce4a15c (empty) (no description set) - Parent commit : yqosqzyt aa3058ff main | (empty) private 1 "###); } diff --git a/cli/tests/test_immutable_commits.rs b/cli/tests/test_immutable_commits.rs index 0fffeae54..c37d214eb 100644 --- a/cli/tests/test_immutable_commits.rs +++ b/cli/tests/test_immutable_commits.rs @@ -125,11 +125,11 @@ fn test_immutable_heads_set_to_working_copy() { test_env.jj_cmd_ok(test_env.env_root(), &["git", "init"]); test_env.jj_cmd_ok(test_env.env_root(), &["branch", "create", "main"]); test_env.add_config(r#"revset-aliases."immutable_heads()" = "@""#); + // No new commit since it was already immutable let (_, stderr) = test_env.jj_cmd_ok(test_env.env_root(), &["new", "-m=a"]); insta::assert_snapshot!(stderr, @r###" - Warning: The working-copy commit in workspace 'default' became immutable, so a new commit has been created on top of it. - Working copy now at: pmmvwywv 7278b2d8 (empty) (no description set) - Parent commit : kkmpptxz a713ef56 (empty) a + Working copy now at: kkmpptxz a713ef56 (empty) a + Parent commit : qpvuntsm e0360db1 main | (no description set) "###); }