git_policy_cli/private_index_request.rs
1//! What:
2//! The private index and object store a commit's preparation reads and writes, and the Git request that selects them.
3//! Why:
4//! Staging and listing read the private commit index, and only staging writes objects, into the scratch object store;
5//! `GIT_INDEX_FILE` and `GIT_OBJECT_DIRECTORY` select that private state while the invocation's global options are ignored,
6//! as the incumbent does.
7//!
8//! In TS you'd write (pseudocode):
9//! ```ts
10//! runTransactionGit({ gitPath, cwd, indexPath, objectDirectory, args })
11//! ```
12
13use super::transaction_git::GitRequest;
14use std::ffi::OsStr;
15use std::path::{Path, PathBuf};
16
17/// What:
18/// The index and object-store inputs of one listing.
19/// Why:
20/// Staging and listing read the private index,
21/// and only staging writes objects into the scratch store.
22///
23/// In TS you'd write (pseudocode):
24/// ```ts
25/// type Workspace = Pick<CommitTransactionWorkspace, 'capturedIndexPath' | 'commitIndexPath' | 'objectDirectory'>;
26/// ```
27#[derive(Clone, Debug, Eq, PartialEq)]
28pub struct CaptureIndexes {
29 /// Real index copied at invocation.
30 pub captured_index: PathBuf,
31 /// Private commit index.
32 pub commit_index: PathBuf,
33 /// Scratch object store.
34 pub object_directory: PathBuf,
35}
36
37/// What:
38/// A Git request that reads or writes one private index,
39/// ignoring the invocation's global options as the incumbent does.
40/// Why:
41/// `GIT_INDEX_FILE` and `GIT_OBJECT_DIRECTORY` select the private state.
42///
43/// In TS you'd write (pseudocode):
44/// ```ts
45/// runTransactionGit({ gitPath, cwd, indexPath, objectDirectory, args })
46/// ```
47pub fn indexed_request<S: AsRef<OsStr>>(
48 cwd: &Path,
49 arguments: &[S],
50 index: Option<&Path>,
51 object_directory: Option<&Path>,
52) -> GitRequest {
53 let mut request: GitRequest = GitRequest::new(cwd, arguments);
54 request.without_prefix = true;
55 request.index = index.map(Path::to_path_buf);
56 request.object_directory = object_directory.map(Path::to_path_buf);
57 return request;
58}
59
60/// Request controls stay out of the release executable.
61#[cfg(test)]
62#[path = "private_index_request_tests.rs"]
63mod tests;