repo: consider empty and undescribed merge commits as discardable

This commit is contained in:
Martin von Zweigbergk 2024-05-27 22:24:02 -07:00 committed by Martin von Zweigbergk
parent 5d2c0347a2
commit 3090adfd5c
4 changed files with 9 additions and 13 deletions

View file

@ -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)

View file

@ -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<bool> {
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<bool> {
Ok(self.description().is_empty() && self.is_empty(repo)?)
}
/// A quick way to just check if a signature is present.

View file

@ -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()))

View file

@ -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]