Skip to content

Commit

Permalink
cli: don't create a new working-copy commit for already immutable com…
Browse files Browse the repository at this point in the history
…mits
  • Loading branch information
martinvonz committed Sep 7, 2024
1 parent e333620 commit c42a941
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 6 additions & 0 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions cli/tests/test_git_private_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"###);
}

Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_immutable_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"###);
}

Expand Down

0 comments on commit c42a941

Please sign in to comment.