Skip to content

Commit 292bbca

Browse files
extrawurstIndianBoy42
authored andcommitted
Reset branch in branch popup (gitui-org#2171)
allow triggering branch reset from branch popup. closes gitui-org#2170
1 parent 38f398b commit 292bbca

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

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

1617
### Changed
1718
* Make info and error message popups scrollable [[@MichaelAug](https://github.com/MichaelAug)] ([#1138](https://github.com/extrawurst/gitui/issues/1138))

src/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,13 @@ impl App {
482482
pull_popup,
483483
fetch_popup,
484484
tag_commit_popup,
485+
reset_popup,
485486
create_branch_popup,
486487
rename_branch_popup,
487488
select_branch_popup,
488489
revision_files_popup,
489490
submodule_popup,
490491
tags_popup,
491-
reset_popup,
492492
options_popup,
493493
help_popup,
494494
revlog,

src/keys/key_list.rs

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub struct KeysList {
9999
pub delete_branch: GituiKeyEvent,
100100
pub merge_branch: GituiKeyEvent,
101101
pub rebase_branch: GituiKeyEvent,
102+
pub reset_branch: GituiKeyEvent,
102103
pub compare_commits: GituiKeyEvent,
103104
pub tags: GituiKeyEvent,
104105
pub delete_tag: GituiKeyEvent,
@@ -190,6 +191,7 @@ impl Default for KeysList {
190191
delete_branch: GituiKeyEvent::new(KeyCode::Char('D'), KeyModifiers::SHIFT),
191192
merge_branch: GituiKeyEvent::new(KeyCode::Char('m'), KeyModifiers::empty()),
192193
rebase_branch: GituiKeyEvent::new(KeyCode::Char('R'), KeyModifiers::SHIFT),
194+
reset_branch: GituiKeyEvent::new(KeyCode::Char('s'), KeyModifiers::empty()),
193195
compare_commits: GituiKeyEvent::new(KeyCode::Char('C'), KeyModifiers::SHIFT),
194196
tags: GituiKeyEvent::new(KeyCode::Char('T'), KeyModifiers::SHIFT),
195197
delete_tag: GituiKeyEvent::new(KeyCode::Char('D'), KeyModifiers::SHIFT),

src/popups/branchlist.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ impl Component for BranchListPopup {
211211
true,
212212
true,
213213
));
214+
215+
out.push(CommandInfo::new(
216+
strings::commands::reset_branch(&self.key_config),
217+
self.valid_selection(),
218+
true,
219+
));
214220
}
215221
visibility_blocking(self)
216222
}
@@ -277,7 +283,7 @@ impl Component for BranchListPopup {
277283
) && self.valid_selection()
278284
{
279285
self.hide();
280-
if let Some(commit_id) = self.get_selected() {
286+
if let Some(commit_id) = self.get_selected_commit() {
281287
self.queue.push(InternalEvent::OpenPopup(
282288
StackablePopupOpen::CompareCommits(
283289
InspectCommitOpen::new(commit_id),
@@ -288,6 +294,13 @@ impl Component for BranchListPopup {
288294
&& self.has_remotes
289295
{
290296
self.queue.push(InternalEvent::FetchRemotes);
297+
} else if key_match(e, self.key_config.keys.reset_branch)
298+
{
299+
if let Some(commit_id) = self.get_selected_commit() {
300+
self.queue.push(InternalEvent::OpenResetPopup(
301+
commit_id,
302+
));
303+
}
291304
} else if key_match(
292305
e,
293306
self.key_config.keys.cmd_bar_toggle,
@@ -466,7 +479,7 @@ impl BranchListPopup {
466479
}
467480

468481
fn inspect_head_of_branch(&mut self) {
469-
if let Some(commit_id) = self.get_selected() {
482+
if let Some(commit_id) = self.get_selected_commit() {
470483
self.hide();
471484
self.queue.push(InternalEvent::OpenPopup(
472485
StackablePopupOpen::InspectCommit(
@@ -509,7 +522,8 @@ impl BranchListPopup {
509522
.count() > 0
510523
}
511524

512-
fn get_selected(&self) -> Option<CommitId> {
525+
// top commit of selected branch
526+
fn get_selected_commit(&self) -> Option<CommitId> {
513527
self.branches
514528
.get(usize::from(self.selection))
515529
.map(|b| b.top_commit)

src/strings.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1403,17 +1403,29 @@ pub mod commands {
14031403
pub fn reset_commit(key_config: &SharedKeyConfig) -> CommandText {
14041404
CommandText::new(
14051405
format!(
1406-
"Confirm [{}]",
1406+
"Confirm [{}]",
14071407
key_config.get_hint(key_config.keys.enter),
14081408
),
14091409
"confirm reset",
14101410
CMD_GROUP_LOG,
14111411
)
14121412
}
1413+
1414+
pub fn reset_branch(key_config: &SharedKeyConfig) -> CommandText {
1415+
CommandText::new(
1416+
format!(
1417+
"Reset [{}]",
1418+
key_config.get_hint(key_config.keys.reset_branch),
1419+
),
1420+
"confirm reset",
1421+
CMD_GROUP_BRANCHES,
1422+
)
1423+
}
1424+
14131425
pub fn reset_type(key_config: &SharedKeyConfig) -> CommandText {
14141426
CommandText::new(
14151427
format!(
1416-
"Change Type [{}{}]",
1428+
"Change Type [{}{}]",
14171429
key_config.get_hint(key_config.keys.move_up),
14181430
key_config.get_hint(key_config.keys.move_down)
14191431
),

0 commit comments

Comments
 (0)