Skip to content

Reset branch in branch popup #2171

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 4 commits into from
Apr 7, 2024
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Added
* provide nightly builds (see [NIGHTLIES.md](./NIGHTLIES.md)) ([#2083](https://github.com/extrawurst/gitui/issues/2083))
* sign commits using openpgp [[@hendrikmaus](https://github.com/hendrikmaus)] ([#97](https://github.com/extrawurst/gitui/issues/97))
* support `core.commitChar` filtering [[@concelare](https://github.com/concelare)] ([#2136](https://github.com/extrawurst/gitui/issues/2136))
* provide nightly builds (see [NIGHTLIES.md](./NIGHTLIES.md)) ([#2083](https://github.com/extrawurst/gitui/issues/2083))
* more version info in `gitui -V` and `help popup` (including git hash)
* support `core.commitChar` filtering [[@concelare](https://github.com/concelare)] ([#2136](https://github.com/extrawurst/gitui/issues/2136))
* allow reset in branch popup ([#2170](https://github.com/extrawurst/gitui/issues/2170))

### Changed
* Make info and error message popups scrollable [[@MichaelAug](https://github.com/MichaelAug)] ([#1138](https://github.com/extrawurst/gitui/issues/1138))
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ impl App {
pull_popup,
fetch_popup,
tag_commit_popup,
reset_popup,
create_branch_popup,
rename_branch_popup,
select_branch_popup,
revision_files_popup,
submodule_popup,
tags_popup,
reset_popup,
options_popup,
help_popup,
revlog,
Expand Down
2 changes: 2 additions & 0 deletions src/keys/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub struct KeysList {
pub delete_branch: GituiKeyEvent,
pub merge_branch: GituiKeyEvent,
pub rebase_branch: GituiKeyEvent,
pub reset_branch: GituiKeyEvent,
pub compare_commits: GituiKeyEvent,
pub tags: GituiKeyEvent,
pub delete_tag: GituiKeyEvent,
Expand Down Expand Up @@ -190,6 +191,7 @@ impl Default for KeysList {
delete_branch: GituiKeyEvent::new(KeyCode::Char('D'), KeyModifiers::SHIFT),
merge_branch: GituiKeyEvent::new(KeyCode::Char('m'), KeyModifiers::empty()),
rebase_branch: GituiKeyEvent::new(KeyCode::Char('R'), KeyModifiers::SHIFT),
reset_branch: GituiKeyEvent::new(KeyCode::Char('s'), KeyModifiers::empty()),
compare_commits: GituiKeyEvent::new(KeyCode::Char('C'), KeyModifiers::SHIFT),
tags: GituiKeyEvent::new(KeyCode::Char('T'), KeyModifiers::SHIFT),
delete_tag: GituiKeyEvent::new(KeyCode::Char('D'), KeyModifiers::SHIFT),
Expand Down
20 changes: 17 additions & 3 deletions src/popups/branchlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ impl Component for BranchListPopup {
true,
true,
));

out.push(CommandInfo::new(
strings::commands::reset_branch(&self.key_config),
self.valid_selection(),
true,
));
}
visibility_blocking(self)
}
Expand Down Expand Up @@ -277,7 +283,7 @@ impl Component for BranchListPopup {
) && self.valid_selection()
{
self.hide();
if let Some(commit_id) = self.get_selected() {
if let Some(commit_id) = self.get_selected_commit() {
self.queue.push(InternalEvent::OpenPopup(
StackablePopupOpen::CompareCommits(
InspectCommitOpen::new(commit_id),
Expand All @@ -288,6 +294,13 @@ impl Component for BranchListPopup {
&& self.has_remotes
{
self.queue.push(InternalEvent::FetchRemotes);
} else if key_match(e, self.key_config.keys.reset_branch)
{
if let Some(commit_id) = self.get_selected_commit() {
self.queue.push(InternalEvent::OpenResetPopup(
commit_id,
));
}
} else if key_match(
e,
self.key_config.keys.cmd_bar_toggle,
Expand Down Expand Up @@ -466,7 +479,7 @@ impl BranchListPopup {
}

fn inspect_head_of_branch(&mut self) {
if let Some(commit_id) = self.get_selected() {
if let Some(commit_id) = self.get_selected_commit() {
self.hide();
self.queue.push(InternalEvent::OpenPopup(
StackablePopupOpen::InspectCommit(
Expand Down Expand Up @@ -509,7 +522,8 @@ impl BranchListPopup {
.count() > 0
}

fn get_selected(&self) -> Option<CommitId> {
// top commit of selected branch
fn get_selected_commit(&self) -> Option<CommitId> {
self.branches
.get(usize::from(self.selection))
.map(|b| b.top_commit)
Expand Down
16 changes: 14 additions & 2 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1403,17 +1403,29 @@ pub mod commands {
pub fn reset_commit(key_config: &SharedKeyConfig) -> CommandText {
CommandText::new(
format!(
"Confirm [{}]",
"Confirm [{}]",
key_config.get_hint(key_config.keys.enter),
),
"confirm reset",
CMD_GROUP_LOG,
)
}

pub fn reset_branch(key_config: &SharedKeyConfig) -> CommandText {
CommandText::new(
format!(
"Reset [{}]",
key_config.get_hint(key_config.keys.reset_branch),
),
"confirm reset",
CMD_GROUP_BRANCHES,
)
}

pub fn reset_type(key_config: &SharedKeyConfig) -> CommandText {
CommandText::new(
format!(
"Change Type [{}{}]",
"Change Type [{}{}]",
key_config.get_hint(key_config.keys.move_up),
key_config.get_hint(key_config.keys.move_down)
),
Expand Down