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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
use std::{fs, path::Path};
use ui::SyncBadge;
use crate::{config::Config, error::Result, fingerprint::FingerprintStore, platform, store, ui};
/// Show status of all tracked entries.
#[allow(clippy::too_many_lines)]
pub fn run(show_diff: bool) -> Result<()> {
let repo_root = store::require_repo_root()?;
let config_path = store::config_path(&repo_root);
let config = Config::load(&config_path)?;
if config.entries.is_empty() {
ui::info("no entries tracked");
ui::hint("add files with `dotling add <path>`");
return Ok(());
}
let mut ok_count = 0usize;
let mut warning_count = 0usize;
let mut error_count = 0usize;
// Load the fingerprint store for encrypted entry sync-state checks.
let fp_store = store::fingerprint_path().map_or_else(
|_| FingerprintStore::load(std::path::PathBuf::new()),
FingerprintStore::load,
);
ui::header("Tracked entries");
// Group entries by category (first path component of source)
let mut categories: std::collections::BTreeMap<String, Vec<usize>> =
std::collections::BTreeMap::new();
for (i, entry) in config.entries.iter().enumerate() {
let category = entry
.source
.split('/')
.next()
.unwrap_or("other")
.to_string();
categories.entry(category).or_default().push(i);
}
for (category, indices) in &categories {
println!("\n {category}/");
for &idx in indices {
let entry = &config.entries[idx];
// Skip check for wrong OS
if !platform::should_deploy(entry.os.as_deref()) {
let status = ui::Status::Ok;
let suffix = format!(" ({})", entry.os.as_deref().unwrap_or("all"));
ui::status_line(
&status,
&entry.source,
&format!("{}{}", entry.target, suffix),
SyncBadge::InSync,
);
ok_count += 1;
continue;
}
let state = crate::deploy::check_state(entry, &repo_root, config.settings.method);
let (status, badge) = match state {
crate::deploy::EntryState::Deployed => {
ok_count += 1;
if entry.template {
// Template: check if deployed rendered file matches the last sync.
// Uses who_changed (source_hash + target_hash) since templates are
// recorded via record_plain, not is_in_sync (which checks enc_hash).
let source_path = repo_root.join(&entry.source);
let badge = match crate::path::expand_tilde(Path::new(&entry.target)) {
Ok(target_path) => {
match fp_store.who_changed(
&entry.source,
&source_path,
&target_path,
) {
crate::fingerprint::WhichSide::Neither => SyncBadge::InSync,
crate::fingerprint::WhichSide::Unknown
| crate::fingerprint::WhichSide::RepoOnly
| crate::fingerprint::WhichSide::ActualOnly
| crate::fingerprint::WhichSide::Both => {
warning_count += 1;
ok_count -= 1;
SyncBadge::NeedsSync
}
}
}
Err(_) => SyncBadge::InSync,
};
(ui::Status::Template, badge)
} else if entry.encrypted {
let enc_path = repo_root.join(&entry.source);
let badge = match crate::path::expand_tilde(Path::new(&entry.target)) {
Ok(target_path) => {
match fp_store.is_in_sync(&entry.source, &enc_path, &target_path) {
Some(true) => SyncBadge::InSync,
Some(false) => {
// Counts as a warning — something drifted.
warning_count += 1;
ok_count -= 1;
SyncBadge::NeedsSync
}
None => {
// Never synced via dotling — conservative.
warning_count += 1;
ok_count -= 1;
SyncBadge::NeedsSync
}
}
}
Err(_) => SyncBadge::InSync,
};
(ui::Status::Encrypted, badge)
} else {
(ui::Status::Ok, SyncBadge::InSync)
}
}
crate::deploy::EntryState::Modified => {
warning_count += 1;
(ui::Status::Modified, SyncBadge::HasDiff)
}
crate::deploy::EntryState::Missing => {
error_count += 1;
(ui::Status::Missing, SyncBadge::NeedsSync)
}
crate::deploy::EntryState::Broken => {
error_count += 1;
(ui::Status::Broken, SyncBadge::NeedsSync)
}
crate::deploy::EntryState::Conflict => {
warning_count += 1;
(ui::Status::Conflict, SyncBadge::NeedsSync)
}
};
ui::status_line(&status, &entry.source, &entry.target, badge);
// Show diff for modified entries if requested
if show_diff && state == crate::deploy::EntryState::Modified {
let source_path = repo_root.join(&entry.source);
let target_path = crate::path::expand_tilde(std::path::Path::new(&entry.target));
if let Ok(target_path) = target_path {
if let (Ok(source_content), Ok(target_content)) = (
fs::read_to_string(&source_path),
fs::read_to_string(&target_path),
) {
println!();
ui::print_diff(
&format!("repo:{}", entry.source),
&entry.target,
&source_content,
&target_content,
);
println!();
}
}
}
}
}
ui::summary(ok_count, warning_count, error_count);
Ok(())
}