-
-
Notifications
You must be signed in to change notification settings - Fork 442
/
changed.rs
39 lines (31 loc) · 1.32 KB
/
changed.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
use crate::CliDiagnostic;
use biome_configuration::PartialConfiguration;
use biome_fs::FileSystem;
use biome_service::DynRef;
use std::ffi::OsString;
pub(crate) fn get_changed_files(
fs: &DynRef<'_, dyn FileSystem>,
configuration: &PartialConfiguration,
since: Option<String>,
) -> Result<Vec<OsString>, CliDiagnostic> {
let default_branch = configuration
.vcs
.as_ref()
.and_then(|v| v.default_branch.as_ref());
let base = match (since.as_ref(), default_branch) {
(Some(since), Some(_)) => since,
(Some(since), None) => since,
(None, Some(branch)) => branch,
(None, None) => return Err(CliDiagnostic::incompatible_end_configuration("The `--changed` flag was set, but Biome couldn't determine the base to compare against. Either set configuration.vcs.defaultBranch or use the --since argument.")),
};
let changed_files = fs.get_changed_files(base)?;
let filtered_changed_files = changed_files.iter().map(OsString::from).collect::<Vec<_>>();
Ok(filtered_changed_files)
}
pub(crate) fn get_staged_files(
fs: &DynRef<'_, dyn FileSystem>,
) -> Result<Vec<OsString>, CliDiagnostic> {
let staged_files = fs.get_staged_files()?;
let filtered_staged_files = staged_files.iter().map(OsString::from).collect::<Vec<_>>();
Ok(filtered_staged_files)
}