Skip to content

Commit 8ab6224

Browse files
authored
support reset from log view (#1534)
1 parent 1a0167e commit 8ab6224

File tree

13 files changed

+379
-8
lines changed

13 files changed

+379
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
**reset to commit**
11+
12+
![reset](assets/reset_in_log.gif)
13+
1014
### Added
1115
* changes in commit message inside external editor [[@bc-universe]](https://github.com/bc-universe) ([#1420](https://github.com/extrawurst/gitui/issues/1420))
1216
* allow detaching HEAD and checking out specific commit from log view [[@fralcow]](https://github.com/fralcow) ([#1499](https://github.com/extrawurst/gitui/pull/1499))
1317
* add no-verify option on commits to not run hooks [[@dam5h]](https://github.com/dam5h) ([#1374](https://github.com/extrawurst/gitui/issues/1374))
1418
* allow `fetch` on status tab [[@alensiljak]](https://github.com/alensiljak) ([#1471](https://github.com/extrawurst/gitui/issues/1471))
19+
* allow reset (soft,mixed,hard) from commit log ([#1500](https://github.com/extrawurst/gitui/issues/1500))
1520

1621
### Fixes
1722
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))

assets/reset_in_log.gif

1.16 MB
Loading

asyncgit/src/sync/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub use remotes::{
7575
};
7676
pub(crate) use repository::repo;
7777
pub use repository::{RepoPath, RepoPathRef};
78-
pub use reset::{reset_stage, reset_workdir};
78+
pub use reset::{reset_repo, reset_stage, reset_workdir};
7979
pub use staging::{discard_lines, stage_lines};
8080
pub use stash::{
8181
get_stashes, stash_apply, stash_drop, stash_pop, stash_save,
@@ -96,6 +96,8 @@ pub use utils::{
9696
stage_add_file, stage_addremoved, Head,
9797
};
9898

99+
pub use git2::ResetType;
100+
99101
#[cfg(test)]
100102
mod tests {
101103
use super::{

asyncgit/src/sync/reset.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::{utils::get_head_repo, RepoPath};
1+
use super::{utils::get_head_repo, CommitId, RepoPath};
22
use crate::{error::Result, sync::repository::repo};
3-
use git2::{build::CheckoutBuilder, ObjectType};
3+
use git2::{build::CheckoutBuilder, ObjectType, ResetType};
44
use scopetime::scope_time;
55

66
///
@@ -38,6 +38,23 @@ pub fn reset_workdir(repo_path: &RepoPath, path: &str) -> Result<()> {
3838
Ok(())
3939
}
4040

41+
///
42+
pub fn reset_repo(
43+
repo_path: &RepoPath,
44+
commit: CommitId,
45+
kind: ResetType,
46+
) -> Result<()> {
47+
scope_time!("reset_repo");
48+
49+
let repo = repo(repo_path)?;
50+
51+
let c = repo.find_commit(commit.into())?;
52+
53+
repo.reset(c.as_object(), kind, None)?;
54+
55+
Ok(())
56+
}
57+
4158
#[cfg(test)]
4259
mod tests {
4360
use super::{reset_stage, reset_workdir};

src/app.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
FileRevlogComponent, HelpComponent, InspectCommitComponent,
1111
MsgComponent, OptionsPopupComponent, PullComponent,
1212
PushComponent, PushTagsComponent, RenameBranchComponent,
13-
RevisionFilesPopup, StashMsgComponent,
13+
ResetPopupComponent, RevisionFilesPopup, StashMsgComponent,
1414
SubmodulesListComponent, TagCommitComponent,
1515
TagListComponent,
1616
},
@@ -84,6 +84,7 @@ pub struct App {
8484
options_popup: OptionsPopupComponent,
8585
submodule_popup: SubmodulesListComponent,
8686
tags_popup: TagListComponent,
87+
reset_popup: ResetPopupComponent,
8788
cmdbar: RefCell<CommandBar>,
8889
tab: usize,
8990
revlog: Revlog,
@@ -204,6 +205,12 @@ impl App {
204205
theme.clone(),
205206
key_config.clone(),
206207
),
208+
reset_popup: ResetPopupComponent::new(
209+
&queue,
210+
&repo,
211+
theme.clone(),
212+
key_config.clone(),
213+
),
207214
pull_popup: PullComponent::new(
208215
&repo,
209216
&queue,
@@ -484,6 +491,7 @@ impl App {
484491
self.files_tab.update()?;
485492
self.stashing_tab.update()?;
486493
self.stashlist_tab.update()?;
494+
self.reset_popup.update()?;
487495

488496
self.update_commands();
489497

@@ -590,6 +598,7 @@ impl App {
590598
revision_files_popup,
591599
submodule_popup,
592600
tags_popup,
601+
reset_popup,
593602
options_popup,
594603
help,
595604
revlog,
@@ -615,6 +624,7 @@ impl App {
615624
select_branch_popup,
616625
submodule_popup,
617626
tags_popup,
627+
reset_popup,
618628
create_branch_popup,
619629
rename_branch_popup,
620630
revision_files_popup,
@@ -926,6 +936,9 @@ impl App {
926936
self.do_quit =
927937
QuitState::OpenSubmodule(submodule_repo_path);
928938
}
939+
InternalEvent::OpenResetPopup(id) => {
940+
self.reset_popup.open(id)?;
941+
}
929942
};
930943

931944
Ok(flags)

src/components/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod push;
2222
mod push_tags;
2323
mod rename_branch;
2424
mod reset;
25+
mod reset_popup;
2526
mod revision_files;
2627
mod revision_files_popup;
2728
mod stashmsg;
@@ -57,6 +58,7 @@ pub use push::PushComponent;
5758
pub use push_tags::PushTagsComponent;
5859
pub use rename_branch::RenameBranchComponent;
5960
pub use reset::ConfirmComponent;
61+
pub use reset_popup::ResetPopupComponent;
6062
pub use revision_files::RevisionFilesComponent;
6163
pub use revision_files_popup::{FileTreeOpen, RevisionFilesPopup};
6264
pub use stashmsg::StashMsgComponent;

0 commit comments

Comments
 (0)