Skip to content

support reset from log view #1534

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

## Unreleased

**reset to commit**

![reset](assets/reset_in_log.gif)

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

### Fixes
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))
Expand Down
Binary file added assets/reset_in_log.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub use remotes::{
};
pub(crate) use repository::repo;
pub use repository::{RepoPath, RepoPathRef};
pub use reset::{reset_stage, reset_workdir};
pub use reset::{reset_repo, reset_stage, reset_workdir};
pub use staging::{discard_lines, stage_lines};
pub use stash::{
get_stashes, stash_apply, stash_drop, stash_pop, stash_save,
Expand All @@ -96,6 +96,8 @@ pub use utils::{
stage_add_file, stage_addremoved, Head,
};

pub use git2::ResetType;

#[cfg(test)]
mod tests {
use super::{
Expand Down
21 changes: 19 additions & 2 deletions asyncgit/src/sync/reset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{utils::get_head_repo, RepoPath};
use super::{utils::get_head_repo, CommitId, RepoPath};
use crate::{error::Result, sync::repository::repo};
use git2::{build::CheckoutBuilder, ObjectType};
use git2::{build::CheckoutBuilder, ObjectType, ResetType};
use scopetime::scope_time;

///
Expand Down Expand Up @@ -38,6 +38,23 @@ pub fn reset_workdir(repo_path: &RepoPath, path: &str) -> Result<()> {
Ok(())
}

///
pub fn reset_repo(
repo_path: &RepoPath,
commit: CommitId,
kind: ResetType,
) -> Result<()> {
scope_time!("reset_repo");

let repo = repo(repo_path)?;

let c = repo.find_commit(commit.into())?;

repo.reset(c.as_object(), kind, None)?;

Ok(())
}

#[cfg(test)]
mod tests {
use super::{reset_stage, reset_workdir};
Expand Down
15 changes: 14 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
FileRevlogComponent, HelpComponent, InspectCommitComponent,
MsgComponent, OptionsPopupComponent, PullComponent,
PushComponent, PushTagsComponent, RenameBranchComponent,
RevisionFilesPopup, StashMsgComponent,
ResetPopupComponent, RevisionFilesPopup, StashMsgComponent,
SubmodulesListComponent, TagCommitComponent,
TagListComponent,
},
Expand Down Expand Up @@ -84,6 +84,7 @@ pub struct App {
options_popup: OptionsPopupComponent,
submodule_popup: SubmodulesListComponent,
tags_popup: TagListComponent,
reset_popup: ResetPopupComponent,
cmdbar: RefCell<CommandBar>,
tab: usize,
revlog: Revlog,
Expand Down Expand Up @@ -204,6 +205,12 @@ impl App {
theme.clone(),
key_config.clone(),
),
reset_popup: ResetPopupComponent::new(
&queue,
&repo,
theme.clone(),
key_config.clone(),
),
pull_popup: PullComponent::new(
&repo,
&queue,
Expand Down Expand Up @@ -484,6 +491,7 @@ impl App {
self.files_tab.update()?;
self.stashing_tab.update()?;
self.stashlist_tab.update()?;
self.reset_popup.update()?;

self.update_commands();

Expand Down Expand Up @@ -590,6 +598,7 @@ impl App {
revision_files_popup,
submodule_popup,
tags_popup,
reset_popup,
options_popup,
help,
revlog,
Expand All @@ -615,6 +624,7 @@ impl App {
select_branch_popup,
submodule_popup,
tags_popup,
reset_popup,
create_branch_popup,
rename_branch_popup,
revision_files_popup,
Expand Down Expand Up @@ -926,6 +936,9 @@ impl App {
self.do_quit =
QuitState::OpenSubmodule(submodule_repo_path);
}
InternalEvent::OpenResetPopup(id) => {
self.reset_popup.open(id)?;
}
};

Ok(flags)
Expand Down
2 changes: 2 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod push;
mod push_tags;
mod rename_branch;
mod reset;
mod reset_popup;
mod revision_files;
mod revision_files_popup;
mod stashmsg;
Expand Down Expand Up @@ -57,6 +58,7 @@ pub use push::PushComponent;
pub use push_tags::PushTagsComponent;
pub use rename_branch::RenameBranchComponent;
pub use reset::ConfirmComponent;
pub use reset_popup::ResetPopupComponent;
pub use revision_files::RevisionFilesComponent;
pub use revision_files_popup::{FileTreeOpen, RevisionFilesPopup};
pub use stashmsg::StashMsgComponent;
Expand Down
Loading