diff --git a/CHANGELOG.md b/CHANGELOG.md index 40fa841e6a..3cde4f35be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 key](https://toml.io/en/v1.0.0#keys). Quote meta characters as needed. Example: `jj config get "revset-aliases.'trunk()'"` +* When updating the working copy away from an empty and undescribed commit, it + is now abandoned even if it is a merge commit. + * If a new working-copy commit is created because the old one was abandoned, and the old commit was merge, then the new commit will now also be. [#2859](https://github.com/martinvonz/jj/issues/2859) diff --git a/lib/src/commit.rs b/lib/src/commit.rs index 2165f12b6d..78d9934437 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -153,16 +153,10 @@ impl Commit { &self.data.committer } - /// A commit is discardable if it has one parent, no change from its - /// parent, and an empty description. - pub fn is_discardable(&self) -> BackendResult { - if self.description().is_empty() { - let parents: Vec<_> = self.parents().try_collect()?; - if let [parent_commit] = &*parents { - return Ok(self.tree_id() == parent_commit.tree_id()); - } - } - Ok(false) + /// A commit is discardable if it has no change from its parent, and an + /// empty description. + pub fn is_discardable(&self, repo: &dyn Repo) -> BackendResult { + Ok(self.description().is_empty() && self.is_empty(repo)?) } /// A quick way to just check if a signature is present. diff --git a/lib/src/repo.rs b/lib/src/repo.rs index a624f0594d..e77b5464fb 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -1355,7 +1355,7 @@ impl MutableRepo { .store() .get_commit(&wc_commit_id) .map_err(EditCommitError::WorkingCopyCommitNotFound)?; - if wc_commit.is_discardable()? + if wc_commit.is_discardable(self)? && self .view .with_ref(|v| local_branch_target_ids(v).all(|id| id != wc_commit.id())) diff --git a/lib/tests/test_mut_repo.rs b/lib/tests/test_mut_repo.rs index 81d352f42b..ff19e181e3 100644 --- a/lib/tests/test_mut_repo.rs +++ b/lib/tests/test_mut_repo.rs @@ -151,8 +151,7 @@ fn test_edit_previous_empty_merge() { let new_wc_commit = write_random_commit(mut_repo, &settings); mut_repo.edit(ws_id, &new_wc_commit).unwrap(); mut_repo.rebase_descendants(&settings).unwrap(); - // TODO: The old commit should no longer be visible - assert!(mut_repo.view().heads().contains(old_wc_commit.id())); + assert!(!mut_repo.view().heads().contains(old_wc_commit.id())); } #[test]