Skip to main content

rskit_git/
options.rs

1//! Option types for git operations.
2
3use std::time::SystemTime;
4
5use crate::types::Signature;
6
7/// Raw extra CLI-style arguments preserved for implementation-specific usage.
8pub type ExtraArgs = Vec<String>;
9
10/// Controls repository initialization.
11#[derive(Debug, Clone, Default)]
12pub struct InitOptions {
13    /// Explicit short branch name for the unborn initial HEAD. When absent,
14    /// libgit2 follows the caller's Git configuration.
15    pub initial_branch: Option<String>,
16}
17
18impl InitOptions {
19    /// Set the short branch name for the unborn initial HEAD.
20    #[must_use = "builder methods return the updated options; chain or bind the result"]
21    pub fn with_initial_branch(mut self, branch: impl Into<String>) -> Self {
22        self.initial_branch = Some(branch.into());
23        self
24    }
25}
26
27/// Controls log traversal.
28#[derive(Debug, Clone, Default)]
29pub struct LogOptions {
30    /// Maximum number of commits to return.
31    pub max_count: Option<usize>,
32    /// Optional path to filter history by.
33    pub path_filter: Option<String>,
34    /// Optional author name or email filter.
35    pub author_filter: Option<String>,
36    /// Lower inclusive time bound.
37    pub since: Option<SystemTime>,
38    /// Upper inclusive time bound.
39    pub until: Option<SystemTime>,
40    /// Implementation-specific passthrough arguments.
41    pub extra_args: ExtraArgs,
42}
43
44/// Controls blame output.
45#[derive(Debug, Clone, Default)]
46pub struct BlameOptions {
47    /// First one-based line to include.
48    pub start_line: Option<usize>,
49    /// Last one-based line to include.
50    pub end_line: Option<usize>,
51    /// Whether to ignore whitespace-only changes.
52    pub ignore_whitespace: bool,
53    /// Implementation-specific passthrough arguments.
54    pub extra_args: ExtraArgs,
55}
56
57/// Controls `git describe`-style inspection.
58#[derive(Debug, Clone, Default)]
59pub struct DescribeOptions {
60    /// Restrict matching to annotated tags.
61    pub annotated_tags_only: bool,
62    /// Include long format output even when on an exact tag.
63    pub long: bool,
64    /// Implementation-specific passthrough arguments.
65    pub extra_args: ExtraArgs,
66}
67
68/// Controls `git grep`-style inspection.
69#[derive(Debug, Clone, Default)]
70pub struct GrepOptions {
71    /// Limit matches to the given repository-relative paths.
72    pub pathspecs: Vec<String>,
73    /// Whether matching should ignore case.
74    pub ignore_case: bool,
75    /// Whether to include line numbers in backend command composition.
76    pub line_numbers: bool,
77    /// Implementation-specific passthrough arguments.
78    pub extra_args: ExtraArgs,
79}
80
81/// Controls commit creation.
82#[derive(Debug, Clone, Default)]
83pub struct CommitOptions {
84    /// Explicit author signature.
85    pub author: Option<Signature>,
86    /// Explicit committer signature.
87    pub committer: Option<Signature>,
88    /// Whether to create a signed commit.
89    pub sign: bool,
90    /// Whether to amend the current commit.
91    pub amend: bool,
92    /// Implementation-specific passthrough arguments.
93    pub extra_args: ExtraArgs,
94}
95
96/// Controls merge behavior.
97#[derive(Debug, Clone, Default)]
98pub struct MergeOptions {
99    /// Prefer a merge commit even when fast-forward is possible.
100    pub no_fast_forward: bool,
101    /// Perform a squash merge.
102    pub squash: bool,
103    /// Optional merge commit message.
104    pub message: Option<String>,
105    /// Implementation-specific passthrough arguments.
106    pub extra_args: ExtraArgs,
107}
108
109/// Controls rebase behavior.
110#[derive(Debug, Clone, Default)]
111pub struct RebaseOptions {
112    /// Whether to request an interactive rebase.
113    pub interactive: bool,
114    /// Whether to enable autosquash semantics.
115    pub autosquash: bool,
116    /// Implementation-specific passthrough arguments.
117    pub extra_args: ExtraArgs,
118}
119
120/// Controls cherry-pick behavior.
121#[derive(Debug, Clone, Default)]
122pub struct CherryPickOptions {
123    /// Mainline parent to use for merge commits.
124    pub mainline: Option<usize>,
125    /// Apply changes without committing.
126    pub no_commit: bool,
127    /// Implementation-specific passthrough arguments.
128    pub extra_args: ExtraArgs,
129}
130
131/// Controls checkout behavior.
132#[derive(Debug, Clone, Default)]
133pub struct CheckoutOptions {
134    /// Force checkout when local changes are present.
135    pub force: bool,
136    /// Create a new branch while checking out.
137    pub create_branch: Option<String>,
138    /// Detach HEAD at the target ref.
139    pub detach: bool,
140    /// Implementation-specific passthrough arguments.
141    pub extra_args: ExtraArgs,
142}
143
144/// Controls fetch behavior.
145#[derive(Debug, Clone, Default)]
146pub struct FetchOptions {
147    /// Whether to prune deleted remote refs.
148    pub prune: bool,
149    /// Optional shallow fetch depth.
150    pub depth: Option<usize>,
151    /// Refspec overrides.
152    pub refspecs: Vec<String>,
153    /// Implementation-specific passthrough arguments.
154    pub extra_args: ExtraArgs,
155}
156
157/// Controls push behavior.
158#[derive(Debug, Clone, Default)]
159pub struct PushOptions {
160    /// Whether to force push.
161    pub force: bool,
162    /// Refspec overrides.
163    pub refspecs: Vec<String>,
164    /// Implementation-specific passthrough arguments.
165    pub extra_args: ExtraArgs,
166}
167
168/// Controls repository cleaning operations.
169#[derive(Debug, Clone, Default)]
170pub struct CleanOptions {
171    /// Remove untracked directories in addition to files.
172    pub directories: bool,
173    /// Include ignored files.
174    pub ignored: bool,
175    /// Require force semantics for destructive cleanup.
176    pub force: bool,
177    /// Implementation-specific passthrough arguments.
178    pub extra_args: ExtraArgs,
179}