Skip to main content

ralph_workflow/git_helpers/
rebase.rs

1//! Git rebase operations using libgit2 with Git CLI fallback.
2//!
3//! This module provides functionality to:
4//! - Perform rebase operations onto a specified upstream branch
5//! - Detect and report conflicts during rebase
6//! - Abort an in-progress rebase
7//! - Continue a rebase after conflict resolution
8//! - Get lists of conflicted files
9//! - Handle all rebase failure modes with fault tolerance
10//!
11//! # Architecture
12//!
13//! This module uses a hybrid approach:
14//! - **libgit2**: For repository state detection, validation, and queries
15//! - **Git CLI**: For the actual rebase operation (more reliable)
16//! - **Fallback patterns**: For operations that may fail with libgit2
17//!
18//! The Git CLI is used for rebase operations because:
19//! 1. Better error messages for classification
20//! 2. More robust edge case handling
21//! 3. Better tested across Git versions
22//! 4. Supports autostash and other features reliably
23
24#![deny(unsafe_code)]
25
26/// Git directory name for rebase-apply state (for `git am`-style rebases).
27///
28/// Used by `detect_concurrent_git_operations` and `cleanup_stale_rebase_state`
29/// functions which are only available with the test-utils feature.
30#[cfg(any(test, feature = "test-utils"))]
31const REBASE_APPLY_DIR: &str = "rebase-apply";
32
33/// Git directory name for rebase-merge state (for interactive rebases).
34///
35/// Used by `detect_concurrent_git_operations` and `cleanup_stale_rebase_state`
36/// functions which are only available with the test-utils feature.
37#[cfg(any(test, feature = "test-utils"))]
38const REBASE_MERGE_DIR: &str = "rebase-merge";
39
40use std::path::Path;
41
42use crate::git_helpers::git2_to_io_error;
43
44mod io {
45    pub type Result<T> = std::io::Result<T>;
46    pub type Error = std::io::Error;
47    pub type ErrorKind = std::io::ErrorKind;
48}
49
50include!("rebase_kinds.rs");
51include!("rebase_classification.rs");
52include!("conflict_detection.rs");
53include!("rebase_preconditions.rs");
54include!("rebase_run.rs");
55include!("rebase_abort.rs");
56include!("rebase_conflicts.rs");
57include!("rebase_continuation.rs");
58include!("rebase_tests.rs");