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;
35
36#[cfg(any(test, feature = "test-utils"))]
37pub mod rebase_checkpoint;
38
39#[cfg(any(test, feature = "test-utils"))]
40pub mod rebase_state_machine;
41
42mod repo;
43mod review_baseline;
44mod start_commit;
45mod wrapper;
46
47#[cfg(any(test, feature = "test-utils"))]
48pub mod ops;
49
50#[cfg(any(test, feature = "test-utils"))]
51pub mod test_trait;
52
53pub use branch::{get_default_branch, is_main_or_master_branch};
54pub use hooks::uninstall_hooks;
55pub use rebase::{
56    abort_rebase, continue_rebase, get_conflict_markers_for_file, get_conflicted_files,
57    rebase_in_progress, rebase_onto, RebaseResult,
58};
59
60// Types that are part of the public API but not used in binary
61#[cfg(any(test, feature = "test-utils"))]
62pub use rebase::{CleanupResult, ConcurrentOperation};
63
64#[cfg(any(test, feature = "test-utils"))]
65pub use rebase::{
66    attempt_automatic_recovery, cleanup_stale_rebase_state, detect_concurrent_git_operations,
67    is_dirty_tree_cli, rebase_in_progress_cli, restore_from_reflog,
68    validate_post_rebase_with_checks, validate_rebase_preconditions, verify_rebase_completed,
69    PostRebaseValidationResult,
70};
71
72#[cfg(any(test, feature = "test-utils"))]
73pub use rebase::RebaseErrorKind;
74
75#[cfg(any(test, feature = "test-utils"))]
76pub use rebase_checkpoint::RebasePhase;
77
78#[cfg(any(test, feature = "test-utils"))]
79pub use rebase_state_machine::{RebaseLock, RebaseStateMachine};
80pub use repo::{
81    get_repo_root, git_add_all, git_commit, git_diff, git_snapshot, require_git_repo,
82    truncate_diff_for_review, CommitResultFallback, DiffReviewContent, DiffTruncationLevel,
83};
84pub use review_baseline::{
85    get_baseline_summary, get_git_diff_from_review_baseline, get_review_baseline_info,
86    load_review_baseline, update_review_baseline, ReviewBaseline,
87};
88pub use start_commit::{
89    get_current_head_oid, get_start_commit_summary, load_start_point, reset_start_commit,
90    save_start_commit, StartPoint,
91};
92pub use wrapper::{
93    cleanup_agent_phase_silent, cleanup_orphaned_marker, disable_git_wrapper, end_agent_phase,
94    start_agent_phase, GitHelpers,
95};
96
97#[cfg(any(test, feature = "test-utils"))]
98pub use ops::{CommitResult, GitOps, RealGit};
99
100#[cfg(any(test, feature = "test-utils"))]
101pub use ops::RebaseResult as OpsRebaseResult;
102
103#[cfg(any(test, feature = "test-utils"))]
104pub use test_trait::MockGit;
105
106// Re-export checkpoint and recovery action for tests only
107#[cfg(any(test, feature = "test-utils"))]
108pub use rebase_checkpoint::RebaseCheckpoint;
109
110#[cfg(any(test, feature = "test-utils"))]
111pub use rebase_state_machine::RecoveryAction;
112
113#[cfg(test)]
114mod tests;