ralph_workflow/git_helpers/
mod.rs

1//! Git Helper Functions
2//!
3//! Provides git hooks management, a git wrapper for blocking commits during the
4//! agent phase, and basic repository utilities.
5//!
6//! # Module Structure
7//!
8//! - [`hooks`] - Git hooks installation and removal
9//! - [`identity`] - Git identity resolution with comprehensive fallback chain
10//! - [`repo`] - Basic git repository operations (add, commit, snapshot)
11//! - [`start_commit`] - Starting commit tracking for incremental diffs
12//! - [`review_baseline`] - Per-review-cycle baseline tracking
13//! - [`wrapper`] - Agent phase git wrapper for safe concurrent execution
14//! - [`branch`] - Branch detection and default branch resolution
15//! - [`rebase`] - Rebase operations with fault tolerance
16//!
17//! # Diff Truncation
18//!
19//! This module provides diff truncation for LLM consumption via
20//! [`truncate_diff_for_review`]. Large diffs are truncated to prevent
21//! exceeding LLM context limits:
22//!
23//! - **Warning threshold** ([`MAX_DIFF_SIZE_WARNING`]): 100KB - logs a warning
24//! - **Hard limit**: 1MB - truncates the diff
25//!
26//! When truncation occurs, a marker is prepended to the diff content to
27//! inform the LLM reviewer that the context is incomplete.
28
29#![deny(unsafe_code)]
30
31pub mod branch;
32mod hooks;
33pub mod identity;
34mod rebase;
35pub mod rebase_checkpoint;
36pub mod rebase_state_machine;
37mod repo;
38mod review_baseline;
39mod start_commit;
40mod wrapper;
41
42#[cfg(any(test, feature = "test-utils"))]
43pub mod ops;
44
45#[cfg(any(test, feature = "test-utils"))]
46pub mod test_trait;
47
48pub use branch::{get_default_branch, is_main_or_master_branch};
49pub use hooks::uninstall_hooks;
50pub use rebase::{
51    abort_rebase, cleanup_stale_rebase_state, continue_rebase, detect_concurrent_git_operations,
52    get_conflict_markers_for_file, get_conflicted_files, rebase_onto, validate_git_state,
53    validate_post_rebase_state, validate_rebase_preconditions, RebaseErrorKind, RebaseResult,
54};
55
56// Types that are part of the public API but not used in binary
57#[cfg(any(test, feature = "test-utils"))]
58pub use rebase::{CleanupResult, ConcurrentOperation};
59
60#[cfg(any(test, feature = "test-utils"))]
61pub use rebase::{
62    attempt_automatic_recovery, is_dirty_tree_cli, rebase_in_progress_cli, restore_from_reflog,
63    validate_post_rebase_with_checks, verify_rebase_completed, PostRebaseValidationResult,
64};
65
66pub use rebase_checkpoint::RebasePhase;
67pub use rebase_state_machine::{RebaseLock, RebaseStateMachine};
68pub use repo::{
69    get_repo_root, git_add_all, git_commit, git_diff, git_snapshot, require_git_repo,
70    truncate_diff_for_review, CommitResultFallback, DiffReviewContent, DiffTruncationLevel,
71};
72pub use review_baseline::{
73    get_baseline_summary, get_git_diff_from_review_baseline, get_review_baseline_info,
74    load_review_baseline, update_review_baseline, ReviewBaseline,
75};
76pub use start_commit::{
77    get_current_head_oid, get_start_commit_summary, load_start_point, reset_start_commit,
78    save_start_commit, StartPoint,
79};
80pub use wrapper::{
81    cleanup_agent_phase_silent, cleanup_orphaned_marker, disable_git_wrapper, end_agent_phase,
82    start_agent_phase, GitHelpers,
83};
84
85#[cfg(any(test, feature = "test-utils"))]
86pub use ops::{CommitResult, GitOps, RealGit};
87
88#[cfg(any(test, feature = "test-utils"))]
89pub use ops::RebaseResult as OpsRebaseResult;
90
91#[cfg(any(test, feature = "test-utils"))]
92pub use test_trait::MockGit;
93
94// Re-export checkpoint and recovery action for tests only
95#[cfg(any(test, feature = "test-utils"))]
96pub use rebase_checkpoint::RebaseCheckpoint;
97
98#[cfg(any(test, feature = "test-utils"))]
99pub use rebase_state_machine::RecoveryAction;
100
101#[cfg(test)]
102mod tests;