Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reverse commit range before yanking #2441

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking Changes
* use default shell instead of bash on Unix-like OS [[@yerke](https://github.com/yerke)] ([#2343](https://github.com/extrawurst/gitui/pull/2343))
* reverse commit range before yanking marked commits, producing `<oldest>^..<newest>` for consecutive commit ranges. [[@Esgariot](https://github.com/Esgariot)] ([#2441](https://github.com/extrawurst/gitui/pull/2441))

### Fixes
* respect env vars like `GIT_CONFIG_GLOBAL` ([#2298](https://github.com/extrawurst/gitui/issues/2298))
Expand Down
6 changes: 4 additions & 2 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ impl CommitList {

///
pub fn copy_commit_hash(&self) -> Result<()> {
let marked = self.marked.as_slice();
let marked = self.marked.iter().rev().cloned().collect_vec();
let marked = marked.as_slice();

let yank: Option<String> = match marked {
[] => self
.items
Expand All @@ -147,7 +149,7 @@ impl CommitList {
[(_idx, commit)] => Some(commit.to_string()),
[first, .., last] => {
let marked_consecutive =
marked.windows(2).all(|w| w[0].0 + 1 == w[1].0);
marked.windows(2).all(|w| w[0].0 - 1 == w[1].0);

let yank = if marked_consecutive {
format!("{}^..{}", first.1, last.1)
Expand Down