Skip to content

Commit

Permalink
repo: consider empty and undescribed merge commits as discardable
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonz committed May 29, 2024
1 parent 5d2c034 commit 3090adf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 4 additions & 10 deletions lib/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
3 changes: 1 addition & 2 deletions lib/tests/test_mut_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 3090adf

Please sign in to comment.