Skip to content

Commit b987598

Browse files
committed
fix next commit msg from history ordering
and also disable this command if no history is present this fixes #1445
1 parent 234e7cb commit b987598

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Fixes
11+
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))
12+
1013
## [0.22.1] - 2022-11-22
1114

1215
Bugfix followup release - check `0.22.0` notes for more infos!

Diff for: src/components/commit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl Component for CommitComponent {
344344
strings::commands::commit_next_msg_from_history(
345345
&self.key_config,
346346
),
347-
true,
347+
self.options.borrow().has_commit_msg_history(),
348348
true,
349349
));
350350
}

Diff for: src/options.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,24 @@ impl Options {
104104
self.save();
105105
}
106106

107+
pub fn has_commit_msg_history(&self) -> bool {
108+
!self.data.commit_msgs.is_empty()
109+
}
110+
107111
pub fn commit_msg(&self, idx: usize) -> Option<String> {
108112
if self.data.commit_msgs.is_empty() {
109113
None
110114
} else {
111-
Some(
112-
self.data.commit_msgs
113-
[idx % self.data.commit_msgs.len()]
114-
.to_string(),
115-
)
115+
let entries = self.data.commit_msgs.len();
116+
let mut index = idx;
117+
118+
while index >= entries {
119+
index -= entries;
120+
}
121+
122+
index = entries.saturating_sub(1) - index;
123+
124+
Some(self.data.commit_msgs[index].to_string())
116125
}
117126
}
118127

0 commit comments

Comments
 (0)