Skip to content
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
27 changes: 21 additions & 6 deletions src/commands/commit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::commands::{find_upstream, resolve_rebase_autostash};
use crate::rebase_utils::{
RebaseState, apply_stash, check_worktrees, checkout_branch, clear_state, drop_stash,
git_rebase_in_progress, run_rebase_loop, save_state, state_path,
git_rebase_in_progress, passively_reconcile_rebase_state, run_rebase_loop, save_state,
};
use crate::stack::{
StackBranch, StackCommit, collect_descendants, enumerate_stack_commits,
Expand All @@ -17,8 +17,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
pub fn commit(args: &[String]) -> Result<()> {
let repo = crate::open_repo()?;

let path = state_path(&repo);
if path.exists() {
if passively_reconcile_rebase_state(&repo)? {
return Err(anyhow!(
"A Kindra operation is already in progress. Use 'kin continue' or 'kin abort'."
));
Expand Down Expand Up @@ -254,8 +253,22 @@ pub fn commit(args: &[String]) -> Result<()> {
let status = cmd.status()?;

if !status.success() {
if !pre_commit_state_required && git_rebase_in_progress(&repo) {
save_state(&repo, &state)?;
if !pre_commit_state_required {
if git_rebase_in_progress(&repo) {
state.in_progress_branch = Some(target_branch.clone());
save_state(&repo, &state)?;
} else if autosquash_state_required
&& let Some(stash_ref) = state.stash_ref.clone()
{
state.stash_ref = None;
state.in_progress_branch = None;
save_state(&repo, &state)?;
apply_stash(&stash_ref)?;
if let Err(err) = drop_stash(&stash_ref) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
eprintln!("Warning: {}", err);
}
save_state(&repo, &state)?;
}
}
return Err(anyhow!(
"git rebase --autosquash failed. Resolve conflicts and run 'kin continue', or run 'kin abort'."
Expand All @@ -264,12 +277,14 @@ pub fn commit(args: &[String]) -> Result<()> {

if autosquash_state_required {
if let Some(stash_ref) = state.stash_ref.clone() {
apply_stash(&stash_ref)?;
state.stash_ref = None;
state.in_progress_branch = None;
save_state(&repo, &state)?;
apply_stash(&stash_ref)?;
if let Err(err) = drop_stash(&stash_ref) {
eprintln!("Warning: {}", err);
}
save_state(&repo, &state)?;
}
clear_state(&repo)?;
}
Expand Down
8 changes: 4 additions & 4 deletions src/commands/continue_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::rebase_utils::{
Operation, git_rebase_in_progress, load_state, run_rebase_loop, state_path,
Operation, ReconcileMode, git_rebase_in_progress, reconcile_saved_rebase_state, run_rebase_loop,
};
use anyhow::{Result, anyhow};
use std::process::Command;

pub fn continue_cmd() -> Result<()> {
let repo = crate::open_repo()?;
let has_rebase_state = state_path(&repo).exists();
let rebase_state = reconcile_saved_rebase_state(&repo, ReconcileMode::Continue)?;
let has_rebase_state = rebase_state.is_some();
let has_run_state = crate::commands::run::run_state_exists(&repo);

if has_rebase_state && has_run_state {
Expand Down Expand Up @@ -40,8 +41,7 @@ pub fn continue_cmd() -> Result<()> {
}
}

if has_rebase_state {
let state = load_state(&repo)?;
if let Some(state) = rebase_state {
return match state.operation {
Operation::Sync => crate::commands::sync::finish_sync_after_rebase(&repo, state),
_ => run_rebase_loop(&repo, state),
Expand Down
7 changes: 4 additions & 3 deletions src/commands/move_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::commands::{find_upstream, resolve_rebase_autostash};
use crate::rebase_utils::{Operation, RebaseState, run_rebase_loop, save_state, state_path};
use crate::rebase_utils::{
Operation, RebaseState, passively_reconcile_rebase_state, run_rebase_loop, save_state,
};
use crate::stack::{
collect_descendants, get_stack_branches_from_merge_base, plan_descendant_reorder,
visualize_stack,
Expand Down Expand Up @@ -34,8 +36,7 @@ pub fn move_cmd(args: &MoveArgs) -> Result<()> {
}

fn start_move(repo: &Repository, args: &MoveArgs) -> Result<()> {
let path = state_path(repo);
if path.exists() {
if passively_reconcile_rebase_state(repo)? {
return Err(anyhow!(
"A Kindra operation is already in progress. Use 'kin continue' or 'kin abort'."
));
Expand Down
6 changes: 4 additions & 2 deletions src/commands/reorder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::commands::{find_upstream, resolve_rebase_autostash};
use crate::rebase_utils::{Operation, RebaseState, run_rebase_loop, save_state, state_path};
use crate::rebase_utils::{
Operation, RebaseState, passively_reconcile_rebase_state, run_rebase_loop, save_state,
};
use anyhow::{Result, anyhow};
use clap::Args;
use std::collections::{HashMap, HashSet};
Expand All @@ -21,7 +23,7 @@ pub struct ReorderArgs {

pub fn reorder(args: &ReorderArgs) -> Result<()> {
let repo = crate::open_repo()?;
if state_path(&repo).exists() {
if passively_reconcile_rebase_state(&repo)? {
return Err(anyhow!(
"A Kindra operation is already in progress. Use 'kin continue' or 'kin abort'."
));
Expand Down
10 changes: 7 additions & 3 deletions src/commands/restack.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::commands::{
prompt_multi_select, resolve_rebase_autostash, resolve_restack_history_limit,
};
use crate::rebase_utils::{Operation, RebaseState, run_rebase_loop, state_path};
use crate::rebase_utils::{
Operation, RebaseState, passively_reconcile_rebase_state, run_rebase_loop,
};
use anyhow::{Result, anyhow};
use clap::Args;
use git2::{BranchType, Commit, Oid, Repository};
Expand All @@ -27,8 +29,10 @@ pub struct RestackArgs {
pub fn restack(args: &RestackArgs) -> Result<()> {
let repo = crate::open_repo()?;

if state_path(&repo).exists() {
return Err(anyhow!("A rebase operation is already in progress."));
if passively_reconcile_rebase_state(&repo)? {
return Err(anyhow!(
"A Kindra-managed operation is already in progress. Use 'kin continue' or 'kin abort'."
));
}

let head = repo.head()?;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::commands::find_upstream;
use crate::rebase_utils::state_path;
use crate::rebase_utils::passively_reconcile_rebase_state;
use crate::stack::{
get_stack_branches_from_merge_base, resolve_merge_base, sort_branches_topologically,
};
Expand Down Expand Up @@ -47,7 +47,7 @@ pub(crate) struct RunState {

pub fn run(args: &RunArgs) -> Result<()> {
let repo = crate::open_repo()?;
if state_path(&repo).exists() || run_state_exists(&repo) {
if passively_reconcile_rebase_state(&repo)? || run_state_exists(&repo) {
return Err(anyhow!(
"A Kindra operation is already in progress. Use 'kin continue' or 'kin abort'."
));
Expand Down
8 changes: 4 additions & 4 deletions src/commands/status_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::rebase_utils::{Operation, load_state};
use crate::rebase_utils::{Operation, ReconcileMode, reconcile_saved_rebase_state};
use anyhow::Result;

pub fn status_cmd() -> Result<()> {
Expand Down Expand Up @@ -29,9 +29,9 @@ pub fn status_cmd() -> Result<()> {
return Ok(());
}

let state = match load_state(&repo) {
Ok(state) => state,
Err(_) => {
let state = match reconcile_saved_rebase_state(&repo, ReconcileMode::Passive)? {
Some(state) => state,
None => {
println!("No Kindra operation active.");
return Ok(());
}
Expand Down
7 changes: 3 additions & 4 deletions src/commands/sync.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::commands::find_upstream;
use crate::commands::resolve_rebase_autostash;
use crate::rebase_utils::{
Operation, RebaseState, checkout_branch, clear_state, git_rebase_in_progress, save_state,
state_path,
Operation, RebaseState, checkout_branch, clear_state, git_rebase_in_progress,
passively_reconcile_rebase_state, save_state,
};
use crate::stack::{
collect_merged_local_branches, find_sync_boundary, get_stack_branches_from_merge_base,
Expand Down Expand Up @@ -37,8 +37,7 @@ pub struct SyncArgs {
pub fn sync(args: &SyncArgs) -> Result<()> {
let repo = crate::open_repo()?;

let path = state_path(&repo);
if path.exists() {
if passively_reconcile_rebase_state(&repo)? {
return Err(anyhow!(
"A Kindra operation is already in progress. Use 'kin continue' or 'kin abort'."
));
Expand Down
Loading
Loading