Skip to content

Commit 2962e6a

Browse files
author
Stephan Dilly
committed
allow continue rebase]
1 parent c254d4b commit 2962e6a

File tree

5 files changed

+86
-6
lines changed

5 files changed

+86
-6
lines changed

asyncgit/src/sync/merge.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::{
22
error::{Error, Result},
33
sync::{
44
branch::merge_commit::commit_merge_with_head,
5-
rebase::get_rebase_progress, reset_stage, reset_workdir,
6-
utils, CommitId,
5+
rebase::{continue_rebase, get_rebase_progress},
6+
reset_stage, reset_workdir, utils, CommitId,
77
},
88
};
99
use git2::{BranchType, Commit, MergeOptions, Repository};
@@ -75,6 +75,17 @@ pub fn rebase_progress(repo_path: &str) -> Result<RebaseProgress> {
7575
get_rebase_progress(&repo)
7676
}
7777

78+
///
79+
pub fn continue_pending_rebase(
80+
repo_path: &str,
81+
) -> Result<RebaseState> {
82+
scope_time!("continue_pending_rebase");
83+
84+
let repo = utils::repo(repo_path)?;
85+
86+
continue_rebase(&repo)
87+
}
88+
7889
///
7990
pub fn merge_branch_repo(
8091
repo: &Repository,

asyncgit/src/sync/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ pub use hunks::{reset_hunk, stage_hunk, unstage_hunk};
5858
pub use ignore::add_to_ignore;
5959
pub use logwalker::{LogWalker, LogWalkerFilter};
6060
pub use merge::{
61-
abort_merge, merge_branch, merge_commit, merge_msg,
62-
mergehead_ids, rebase_branch, rebase_progress,
61+
abort_merge, continue_pending_rebase, merge_branch, merge_commit,
62+
merge_msg, mergehead_ids, rebase_branch, rebase_progress,
6363
};
6464
pub use remotes::{
6565
get_default_remote, get_remotes, push::AsyncProgress,

asyncgit/src/sync/rebase.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub enum RebaseState {
4747
}
4848

4949
/// rebase
50-
#[allow(dead_code)]
5150
pub fn rebase(
5251
repo: &git2::Repository,
5352
commit: &git2::AnnotatedCommit,
@@ -76,6 +75,38 @@ pub fn rebase(
7675
Ok(RebaseState::Finished)
7776
}
7877

78+
/// continue pending rebase
79+
pub fn continue_rebase(
80+
repo: &git2::Repository,
81+
) -> Result<RebaseState> {
82+
if repo.index()?.has_conflicts() {
83+
return Ok(RebaseState::Conflicted);
84+
}
85+
86+
let mut rebase = repo.open_rebase(None)?;
87+
let signature =
88+
crate::sync::commit::signature_allow_undefined_name(repo)?;
89+
90+
while let Some(op) = rebase.next() {
91+
let _op = op?;
92+
// dbg!(op.id());
93+
94+
if repo.index()?.has_conflicts() {
95+
return Ok(RebaseState::Conflicted);
96+
}
97+
98+
rebase.commit(None, &signature, None)?;
99+
}
100+
101+
if repo.index()?.has_conflicts() {
102+
return Ok(RebaseState::Conflicted);
103+
}
104+
105+
rebase.finish(Some(&signature))?;
106+
107+
Ok(RebaseState::Finished)
108+
}
109+
79110
///
80111
#[derive(PartialEq, Debug)]
81112
pub struct RebaseProgress {
@@ -86,7 +117,6 @@ pub struct RebaseProgress {
86117
}
87118

88119
///
89-
#[allow(dead_code)]
90120
pub fn get_rebase_progress(
91121
repo: &git2::Repository,
92122
) -> Result<RebaseProgress> {

src/strings.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,19 @@ pub mod commands {
628628
CMD_GROUP_GENERAL,
629629
)
630630
}
631+
632+
pub fn continue_rebase(
633+
key_config: &SharedKeyConfig,
634+
) -> CommandText {
635+
CommandText::new(
636+
format!(
637+
"Continue rebase [{}]",
638+
key_config.get_hint(key_config.rebase_branch),
639+
),
640+
"continue ongoing rebase",
641+
CMD_GROUP_GENERAL,
642+
)
643+
}
631644
pub fn select_staging(
632645
key_config: &SharedKeyConfig,
633646
) -> CommandText {

src/tabs/status.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,23 @@ impl Status {
541541
== RepoState::Merge
542542
}
543543

544+
fn pending_rebase() -> bool {
545+
sync::repo_state(CWD).unwrap_or(RepoState::Clean)
546+
== RepoState::Rebase
547+
}
548+
544549
pub fn abort_merge(&self) {
545550
try_or_popup!(self, "abort merge", sync::abort_merge(CWD));
546551
}
547552

553+
fn continue_rebase(&self) {
554+
try_or_popup!(
555+
self,
556+
"continue rebase",
557+
sync::continue_pending_rebase(CWD)
558+
);
559+
}
560+
548561
fn commands_nav(
549562
&self,
550563
out: &mut Vec<CommandInfo>,
@@ -642,6 +655,11 @@ impl Component for Status {
642655
true,
643656
Self::can_abort_merge() || force_all,
644657
));
658+
out.push(CommandInfo::new(
659+
strings::commands::continue_rebase(&self.key_config),
660+
true,
661+
Self::pending_rebase() || force_all,
662+
));
645663
}
646664

647665
{
@@ -747,6 +765,14 @@ impl Component for Status {
747765
Action::AbortMerge,
748766
));
749767

768+
Ok(EventState::Consumed)
769+
} else if k == self.key_config.rebase_branch
770+
&& Self::pending_rebase()
771+
{
772+
self.continue_rebase();
773+
self.queue.push(InternalEvent::Update(
774+
NeedsUpdate::ALL,
775+
));
750776
Ok(EventState::Consumed)
751777
} else {
752778
Ok(EventState::NotConsumed)

0 commit comments

Comments
 (0)