Skip to content

Copy full Commit Hash by default #1836

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

Merged
merged 2 commits into from
Aug 26, 2023
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* fix hunk (un)staging/reset for # of context lines != 3 ([#1746](https://github.com/extrawurst/gitui/issues/1746))
* fix delay when opening external editor ([#1506](https://github.com/extrawurst/gitui/issues/1506))

### Changed
* Copy full Commit Hash by default [[@AmmarAbouZor](https://github.com/AmmarAbouZor)] ([#1836](https://github.com/extrawurst/gitui/issues/1836))

## [0.23.0] - 2022-06-19

**reset to commit**
Expand Down
18 changes: 7 additions & 11 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,37 +162,33 @@ impl CommitList {

pub fn copy_commit_hash(&self) -> Result<()> {
let marked = self.marked.as_slice();
let yank: Option<Cow<str>> = match marked {
let yank: Option<String> = match marked {
[] => self
.items
.iter()
.nth(
self.selection
.saturating_sub(self.items.index_offset()),
)
.map(|e| Cow::Borrowed(e.hash_short.as_ref())),
[(_idx, commit)] => {
Some(commit.get_short_string().into())
}
.map(|e| e.id.to_string()),
[(_idx, commit)] => Some(commit.to_string()),
[first, .., last] => {
let marked_consecutive =
marked.windows(2).all(|w| w[0].0 + 1 == w[1].0);

let yank = if marked_consecutive {
format!(
"{}^..{}",
first.1.get_short_string(),
last.1.get_short_string()
first.1.to_string(),
last.1.to_string()
)
} else {
marked
.iter()
.map(|(_idx, commit)| {
commit.get_short_string()
})
.map(|(_idx, commit)| commit.to_string())
.join(" ")
};
Some(yank.into())
Some(yank)
}
};

Expand Down