diff --git a/lib/src/commit.rs b/lib/src/commit.rs index 3480c8152..6decf6f39 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -128,4 +128,15 @@ impl Commit { pub fn committer(&self) -> &Signature { &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) -> bool { + if self.description().is_empty() { + if let [parent_commit] = &*self.parents() { + return self.tree_id() == parent_commit.tree_id(); + } + } + false + } } diff --git a/lib/src/repo.rs b/lib/src/repo.rs index f3c34620b..21f8bb869 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -743,11 +743,7 @@ impl MutableRepo { .store() .get_commit(&wc_commit_id) .map_err(EditCommitError::WorkingCopyCommitNotFound)?; - if wc_commit.parent_ids().len() == 1 - && wc_commit.parents()[0].tree_id() == wc_commit.tree_id() - && wc_commit.description().is_empty() - && self.view().heads().contains(wc_commit.id()) - { + if wc_commit.is_discardable() && self.view().heads().contains(wc_commit.id()) { // Abandon the working-copy commit we're leaving if it's empty and a head commit self.record_abandoned_commit(wc_commit_id); }