1use std::fmt;
2use std::path::PathBuf;
3
4mod apply;
5mod branch;
6mod errors;
7mod ghost_commits;
8mod operations;
9mod platform;
10
11pub use apply::ApplyGitRequest;
12pub use apply::ApplyGitResult;
13pub use apply::apply_git_patch;
14pub use apply::extract_paths_from_patch;
15pub use apply::parse_git_apply_output;
16pub use apply::stage_paths;
17pub use branch::merge_base_with_head;
18pub use errors::GitToolingError;
19pub use ghost_commits::CreateGhostCommitOptions;
20pub use ghost_commits::GhostSnapshotReport;
21pub use ghost_commits::LargeUntrackedDir;
22pub use ghost_commits::capture_ghost_snapshot_report;
23pub use ghost_commits::create_ghost_commit;
24pub use ghost_commits::create_ghost_commit_with_report;
25pub use ghost_commits::restore_ghost_commit;
26pub use ghost_commits::restore_to_commit;
27pub use platform::create_symlink;
28use schemars::JsonSchema;
29use serde::Deserialize;
30use serde::Serialize;
31use ts_rs::TS;
32
33type CommitID = String;
34
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)]
37pub struct GhostCommit {
38 id: CommitID,
39 parent: Option<CommitID>,
40 preexisting_untracked_files: Vec<PathBuf>,
41 preexisting_untracked_dirs: Vec<PathBuf>,
42}
43
44impl GhostCommit {
45 pub fn new(
47 id: CommitID,
48 parent: Option<CommitID>,
49 preexisting_untracked_files: Vec<PathBuf>,
50 preexisting_untracked_dirs: Vec<PathBuf>,
51 ) -> Self {
52 Self {
53 id,
54 parent,
55 preexisting_untracked_files,
56 preexisting_untracked_dirs,
57 }
58 }
59
60 pub fn id(&self) -> &str {
62 &self.id
63 }
64
65 pub fn parent(&self) -> Option<&str> {
67 self.parent.as_deref()
68 }
69
70 pub fn preexisting_untracked_files(&self) -> &[PathBuf] {
72 &self.preexisting_untracked_files
73 }
74
75 pub fn preexisting_untracked_dirs(&self) -> &[PathBuf] {
77 &self.preexisting_untracked_dirs
78 }
79}
80
81impl fmt::Display for GhostCommit {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 write!(f, "{}", self.id)
84 }
85}