Skip to content

Commit e47976e

Browse files
committed
fix: fix ignored path
1 parent 69bfa9f commit e47976e

File tree

6 files changed

+42
-67
lines changed

6 files changed

+42
-67
lines changed

src/dots.rs

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::paths::DotPaths;
2+
use crate::settings::dotfile_dir;
23
use crate::settings::dots::{Dot, DotOverride};
34
use crate::templating::Variables;
45
use anyhow::Result;
@@ -7,19 +8,20 @@ use std::fs;
78
use std::fs::File;
89
use std::io::Write;
910
use std::path::{Path, PathBuf};
10-
use crate::settings::dotfile_dir;
1111

1212
impl Dot {
13-
pub(crate) fn install(
14-
&self,
15-
vars: &Variables,
16-
auto_ignored: Vec<PathBuf>,
17-
) -> Result<()> {
13+
pub(crate) fn install(&self, vars: &Variables, auto_ignored: Vec<PathBuf>) -> Result<()> {
1814
let source = &self.source()?;
1915
let copy_path = &self.build_copy_path();
2016
let source_str = source.to_str().unwrap_or_default();
21-
let mut ignored_paths = self.get_ignored_paths(source_str)?;
22-
ignored_paths.extend_from_slice(&auto_ignored);
17+
18+
let ignored_paths = if self.ignore.is_empty() {
19+
auto_ignored
20+
} else {
21+
let mut ignored_paths = self.get_ignored_paths(source_str)?;
22+
ignored_paths.extend_from_slice(&auto_ignored);
23+
ignored_paths
24+
};
2325

2426
// Add local vars to the global ones
2527
let mut vars = vars.clone();
@@ -101,10 +103,7 @@ impl Dot {
101103
}
102104

103105
impl DotOverride {
104-
pub(crate) fn resolve_var_path(
105-
&self,
106-
origin: Option<&PathBuf>,
107-
) -> Option<PathBuf> {
106+
pub(crate) fn resolve_var_path(&self, origin: Option<&PathBuf>) -> Option<PathBuf> {
108107
let source = match (self.get_source(), origin) {
109108
(Some(source), _) => source,
110109
(None, Some(origin)) => origin,
@@ -116,9 +115,7 @@ impl DotOverride {
116115
}
117116
}
118117

119-
impl Dot {
120-
121-
}
118+
impl Dot {}
122119

123120
pub(crate) trait DotVar {
124121
fn vars(&self) -> Option<PathBuf>;
@@ -131,11 +128,7 @@ pub(crate) trait DotVar {
131128
self.vars() == Some(Dot::default_vars())
132129
}
133130

134-
fn resolve_from_source(
135-
&self,
136-
source: &Path,
137-
path: &Path,
138-
) -> Option<PathBuf> {
131+
fn resolve_from_source(&self, source: &Path, path: &Path) -> Option<PathBuf> {
139132
let relative_to_dot = dotfile_dir().join(source).join(path);
140133
let relative_to_dotfile_dir = dotfile_dir().join(path);
141134
// FIXME : we should not try to look for path like this
@@ -156,11 +149,7 @@ pub(crate) trait DotVar {
156149
}
157150
}
158151

159-
fn vars_path_not_found(
160-
&self,
161-
source: &Path,
162-
path: &Path,
163-
) -> Option<PathBuf> {
152+
fn vars_path_not_found(&self, source: &Path, path: &Path) -> Option<PathBuf> {
164153
if !self.is_default_var_path() {
165154
eprintln!(
166155
"{} {:?} {} {:?} {} {:?}",
@@ -277,7 +266,6 @@ mod tests {
277266
vars: Dot::default_vars(),
278267
};
279268

280-
281269
// Act
282270
dot.symlink()?;
283271

@@ -307,19 +295,17 @@ mod tests {
307295
&Variables::default(),
308296
)?;
309297

310-
run_cmd!(tree -a)?;
311-
312-
298+
run_cmd!(tree - a)?;
313299

314300
// Assert
315-
let file_one = PathBuf::from("dotfiles_with_multiple_nested_dir/.dots/dir/subdir_one/subfile");
316-
let file_two = PathBuf::from("dotfiles_with_multiple_nested_dir/.dots/dir/subdir_two/subfile");
301+
let file_one =
302+
PathBuf::from("dotfiles_with_multiple_nested_dir/.dots/dir/subdir_one/subfile");
303+
let file_two =
304+
PathBuf::from("dotfiles_with_multiple_nested_dir/.dots/dir/subdir_two/subfile");
317305
assert_that!(file_one).exists();
318306
assert_that!(file_two).exists();
319-
assert_that!(fs::read_to_string(file_one)?)
320-
.is_equal_to(&"Hello From subdir 1".to_string());
321-
assert_that!(fs::read_to_string(file_two)?)
322-
.is_equal_to(&"Hello From subdir 2".to_string());
307+
assert_that!(fs::read_to_string(file_one)?).is_equal_to(&"Hello From subdir 1".to_string());
308+
assert_that!(fs::read_to_string(file_two)?).is_equal_to(&"Hello From subdir 2".to_string());
323309
Ok(())
324310
}
325311

@@ -342,7 +328,7 @@ mod tests {
342328
&Variables::default(),
343329
)?;
344330

345-
run_cmd!(tree -a)?;
331+
run_cmd!(tree - a)?;
346332

347333
assert_that!(PathBuf::from("dotfiles_non_utf8/.dots/ferris.png")).exists();
348334
Ok(())
@@ -465,7 +451,7 @@ mod tests {
465451
vars.insert("name", "Tom Bombadil");
466452

467453
// Act
468-
dot.install( &vars, vec![])?;
454+
dot.install(&vars, vec![])?;
469455
let dot = PathBuf::from(".dots/dotfiles/dot");
470456

471457
// Assert
@@ -533,7 +519,7 @@ mod tests {
533519
};
534520

535521
// Arrange
536-
dot.install( &Variables::default(), vec![])?;
522+
dot.install(&Variables::default(), vec![])?;
537523

538524
// Assert
539525
let content = fs::read_to_string(PathBuf::from(

src/git.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn clone(remote: &str, path: &Path) -> Result<(), git2::Error> {
7070
cb.transfer_progress(|stats| {
7171
let mut state = state.borrow_mut();
7272
state.progress = Some(stats.to_owned());
73-
print_clone_progress(&mut *state);
73+
print_clone_progress(&mut state);
7474
true
7575
});
7676

@@ -80,7 +80,7 @@ pub(crate) fn clone(remote: &str, path: &Path) -> Result<(), git2::Error> {
8080
state.path = path.map(|p| p.to_path_buf());
8181
state.current = cur;
8282
state.total = total;
83-
print_clone_progress(&mut *state);
83+
print_clone_progress(&mut state);
8484
});
8585

8686
let mut fo = FetchOptions::new();

src/lib.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::state::BombadilState;
77
use crate::templating::Variables;
88
use anyhow::{anyhow, Result};
99
use colored::*;
10+
use ignore_files::IgnoreFilter;
1011
use settings::dots::Dot;
1112
use settings::Settings;
1213
use std::collections::HashMap;
@@ -16,7 +17,6 @@ use std::path::{Path, PathBuf};
1617
use std::sync::Arc;
1718
use std::time::Duration;
1819
use std::{fs, io};
19-
use ignore_files::IgnoreFilter;
2020
use watchexec::{
2121
action::{Action, Outcome},
2222
config::{InitConfig, RuntimeConfig},
@@ -29,14 +29,14 @@ use watchexec::{
2929
use watchexec_filterer_ignore::IgnoreFilterer;
3030

3131
mod dots;
32+
mod error;
3233
mod git;
3334
mod gpg;
3435
mod hook;
35-
mod state;
36-
mod templating;
3736
pub mod paths;
3837
pub mod settings;
39-
mod error;
38+
mod state;
39+
mod templating;
4040

4141
pub(crate) const BOMBADIL_CONFIG: &str = "bombadil.toml";
4242

@@ -86,7 +86,7 @@ impl Bombadil {
8686
pub fn link_self_config(dotfiles_path: Option<PathBuf>) -> Result<()> {
8787
let xdg_config_dir = dirs::config_dir();
8888
match xdg_config_dir {
89-
None => return Err(anyhow!("$XDG_CONFIG does not exist")),
89+
None => Err(anyhow!("$XDG_CONFIG does not exist")),
9090
Some(config_dir) => {
9191
let bombadil_xdg_config = config_dir.join(BOMBADIL_CONFIG);
9292

@@ -166,10 +166,7 @@ impl Bombadil {
166166
// Render current settings and create symlinks
167167
fs::create_dir(dot_copy_dir)?;
168168
for (key, dot) in self.dots.iter() {
169-
if let Err(err) = dot.install(
170-
&self.vars,
171-
self.get_auto_ignored_files(key),
172-
) {
169+
if let Err(err) = dot.install(&self.vars, self.get_auto_ignored_files(key)) {
173170
eprintln!("{}", err);
174171
continue;
175172
}
@@ -229,7 +226,6 @@ impl Bombadil {
229226

230227
/// Watch dotfiles and automatically run link on changes
231228
pub async fn watch(profiles: Vec<String>) -> Result<()> {
232-
233229
let mut bombadil = Bombadil::from_settings(Mode::Gpg)?;
234230
bombadil.enable_profiles(profiles.iter().map(String::as_str).collect())?;
235231

@@ -569,10 +565,7 @@ impl Bombadil {
569565
.filter_map(|dot| dot.resolve_var_path(origin_source))
570566
.collect();
571567

572-
let _ = dot_origin.map(|dot| {
573-
dot.resolve_var_path()
574-
.map(|path| ignored.push(path))
575-
});
568+
let _ = dot_origin.map(|dot| dot.resolve_var_path().map(|path| ignored.push(path)));
576569

577570
ignored
578571
}
@@ -650,7 +643,7 @@ mod tests {
650643
fn install_should_fail_and_continue() -> Result<()> {
651644
// Act
652645
Bombadil::from_settings(NoGpg)?.install()?;
653-
run_cmd!(tree -a)?;
646+
run_cmd!(tree - a)?;
654647
// Assert
655648
assert_that!(PathBuf::from(".config/template.css")).exists();
656649
assert_that!(PathBuf::from(".config/invalid")).does_not_exist();

src/paths/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use crate::error::Error::{
2-
SourceNotFound, Symlink, TargetNotFound, TemplateNotFound, Unlink,
3-
};
1+
use crate::error::Error::{SourceNotFound, Symlink, TargetNotFound, TemplateNotFound, Unlink};
2+
use crate::error::*;
43
use crate::settings::dotfile_dir;
54
use crate::{Dot, DotVar};
65
use colored::*;
76
use dirs::home_dir;
8-
use crate::error::*;
97
use std::fs;
108
use std::os::unix;
119
use std::path::{Path, PathBuf};

src/settings/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::settings::imports::ImportPath;
22
use crate::settings::profiles::ActiveProfile;
3-
use crate::{Profile, BOMBADIL_CONFIG, Gpg};
3+
use crate::{Gpg, Profile, BOMBADIL_CONFIG};
44
use anyhow::anyhow;
55
use colored::*;
66
use config::Config;
77
use config::{ConfigError, File};
8+
use dirs::home_dir;
89
use lazy_static::lazy_static;
910
use serde::{Deserialize, Serialize};
1011
use std::collections::HashMap;
1112
use std::path::PathBuf;
12-
use dirs::home_dir;
1313

1414
pub mod dots;
1515
pub mod imports;
@@ -34,7 +34,8 @@ pub fn profiles() -> Vec<&'static str> {
3434
}
3535

3636
pub fn dotfile_dir() -> PathBuf {
37-
home_dir().expect("$HOME should be set")
37+
home_dir()
38+
.expect("$HOME should be set")
3839
.join(&SETTINGS.dotfiles_dir)
3940
}
4041

src/templating.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::gpg::{Gpg, GPG_PREFIX};
2+
use crate::settings::GPG;
23
use anyhow::{anyhow, Result};
34
use colored::Colorize;
45
use std::collections::HashMap;
@@ -7,7 +8,6 @@ use std::io::prelude::*;
78
use std::io::BufReader;
89
use std::path::{Path, PathBuf};
910
use tera::Tera;
10-
use crate::settings::GPG;
1111

1212
#[derive(Clone, Debug, Default)]
1313
pub struct Variables {
@@ -19,10 +19,7 @@ pub struct Variables {
1919
}
2020

2121
impl Variables {
22-
pub(crate) fn from_paths(
23-
base_path: &Path,
24-
var_paths: &[PathBuf],
25-
) -> Result<Self> {
22+
pub(crate) fn from_paths(base_path: &Path, var_paths: &[PathBuf]) -> Result<Self> {
2623
let mut out = Self::default();
2724
for path in var_paths {
2825
let variables = Self::from_toml(&base_path.join(path))?;

0 commit comments

Comments
 (0)