-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepository_info.rs
52 lines (47 loc) · 1.34 KB
/
repository_info.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::path::PathBuf;
use strum::Display;
#[derive(Display)]
pub enum RepositoryState {
Unknown,
/// The current git HEAD is detached.
Detached,
/// Repo has been fetched, merged and is up-to-date.
UpToDate,
/// The repo looks fine during a `Check` run.
Ok,
/// We just fetched the newest info from the default remote.
Fetched,
/// The repository has been successfully updated.
Updated,
/// There's no way to fast-forward merge.
NoFastForward,
/// There're some local filesystem changes.
LocalChanges,
/// There're unpushed commits in this repo.
NotPushed,
}
pub struct RepositoryInfo {
pub path: PathBuf,
pub name: String,
pub state: RepositoryState,
pub stashed: usize,
/// The time (ms) it took to check the repo.
pub check_time: Option<usize>,
pub hook: Option<String>,
}
impl RepositoryInfo {
pub fn new(path: PathBuf, hook: Option<String>) -> RepositoryInfo {
// Get the repository name from the path for the progress bar
let name = path.file_name().map_or("no_name?".to_string(), |name| {
name.to_string_lossy().to_string()
});
RepositoryInfo {
path,
name,
state: RepositoryState::Unknown,
stashed: 0,
check_time: None,
hook,
}
}
}