From b987598c7be8441a3b02fb1c1cba03b4aa6db31e Mon Sep 17 00:00:00 2001 From: extrawurst Date: Tue, 22 Nov 2022 12:18:36 +0100 Subject: [PATCH] fix `next commit msg` from history ordering and also disable this command if no history is present this fixes #1445 --- CHANGELOG.md | 3 +++ src/components/commit.rs | 2 +- src/options.rs | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 828cf231..37be8831 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixes +* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445)) + ## [0.22.1] - 2022-11-22 Bugfix followup release - check `0.22.0` notes for more infos! diff --git a/src/components/commit.rs b/src/components/commit.rs index 70d67daf..cadaab43 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -344,7 +344,7 @@ impl Component for CommitComponent { strings::commands::commit_next_msg_from_history( &self.key_config, ), - true, + self.options.borrow().has_commit_msg_history(), true, )); } diff --git a/src/options.rs b/src/options.rs index a10bea39..4c0424c7 100644 --- a/src/options.rs +++ b/src/options.rs @@ -104,15 +104,24 @@ impl Options { self.save(); } + pub fn has_commit_msg_history(&self) -> bool { + !self.data.commit_msgs.is_empty() + } + pub fn commit_msg(&self, idx: usize) -> Option { if self.data.commit_msgs.is_empty() { None } else { - Some( - self.data.commit_msgs - [idx % self.data.commit_msgs.len()] - .to_string(), - ) + let entries = self.data.commit_msgs.len(); + let mut index = idx; + + while index >= entries { + index -= entries; + } + + index = entries.saturating_sub(1) - index; + + Some(self.data.commit_msgs[index].to_string()) } }