gitpoulpi_core/domain/submodule.rs
1use serde::{Deserialize, Serialize};
2
3use super::Oid;
4
5/// Where a submodule stands relative to what the superproject records
6/// (`git submodule status`'s first column).
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8pub enum SubmoduleState {
9 /// Not cloned into the working tree yet (`-`): `submodule update --init`
10 /// fetches it.
11 Uninitialized,
12 /// Checked out at the commit the superproject records.
13 UpToDate,
14 /// Checked out at another commit than the recorded one (`+`): the
15 /// submodule moved on (or the superproject did) and the pointer was not
16 /// committed, or `submodule update` has not run yet.
17 Modified,
18 /// The superproject has merge conflicts on the submodule (`U`).
19 Conflicted,
20}
21
22/// One submodule of a repository, as `.gitmodules` and the index describe
23/// it. Both backends list the same submodules in the same order (by path).
24#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25pub struct Submodule {
26 /// The name in `.gitmodules` (usually the path).
27 pub name: String,
28 /// Repo-relative, `/`-separated.
29 pub path: String,
30 /// The URL `.gitmodules` records (empty when it records none).
31 pub url: String,
32 /// `submodule.<name>.branch`, when set.
33 pub branch: Option<String>,
34 pub state: SubmoduleState,
35 /// The commit the superproject records (index entry), if any.
36 pub expected: Option<Oid>,
37 /// The commit checked out in the submodule's working tree, `None` while
38 /// [`SubmoduleState::Uninitialized`].
39 pub head: Option<Oid>,
40}
41
42/// What [`crate::GitBackend::submodule_update`] updates and how.
43#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
44pub struct SubmoduleUpdateOptions {
45 /// Repo-relative paths; empty means every submodule.
46 pub paths: Vec<String>,
47 /// Clone and initialize submodules that are not yet (`--init`).
48 pub init: bool,
49 /// Also update the submodules' own submodules (`--recursive`).
50 pub recursive: bool,
51}