Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/commands/edge_app/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
}

fn is_included(entry: &DirEntry, ignore: &Ignorer) -> bool {
if entry.depth() == 0 {
return true;
}

let exclusion_list = ["screenly.js", "screenly.yml", ".ignore", "instance.yml"];
if exclusion_list.contains(&entry.file_name().to_str().unwrap_or_default()) {
return false;
Expand Down Expand Up @@ -266,7 +270,7 @@
tree.insert(relative_path.to_owned(), file.signature.clone());
}

debug!("File tree: {:?}", &tree);

Check warning on line 273 in src/commands/edge_app/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant reference in `debug!` argument

warning: redundant reference in `debug!` argument --> src/commands/edge_app/utils.rs:273:31 | 273 | debug!("File tree: {:?}", &tree); | ^^^^^ help: remove the redundant `&`: `tree` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.98.0/index.html#useless_borrows_in_formatting

tree
}
Expand Down Expand Up @@ -738,7 +742,7 @@
.unwrap();
File::create(dir_path.join(".ignore"))
.unwrap()
.write_all(b"file2.txt")
.write_all(b"file2.txt\n\n")
.unwrap();
File::create(dir_path.join("instance.yml"))
.unwrap()
Expand Down
18 changes: 18 additions & 0 deletions src/commands/ignorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ impl Ignorer {

for line in content.lines() {
let pattern = line.trim();
if pattern.is_empty() {
continue;
}
if pattern.ends_with('/') {
patterns.push(format!("^{}.*$", regex::escape(pattern)));
} else if pattern.contains('*') {
Expand Down Expand Up @@ -78,6 +81,21 @@ mod tests {
assert!(!ignorer.is_ignored(Path::new("other_file.txt")));
}

#[test]
fn test_ignore_when_file_has_blank_line_should_not_ignore_root() {
let dir = tempdir().unwrap();

File::create(dir.path().join(".ignore"))
.unwrap()
.write_all(b"node_modules/\n\n")
.unwrap();

let ignorer = Ignorer::new(dir.path()).unwrap();

assert!(!ignorer.is_ignored(dir.path()));
assert!(ignorer.is_ignored(&dir.path().join("node_modules/react")));
}

#[test]
fn test_ignore_when_pattern_specified_should_ignore_files_matching_that_pattern() {
let dir = tempdir().unwrap();
Expand Down
Loading