Skip to content

Add .venv gitignore tests #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
105 changes: 105 additions & 0 deletions crates/oxide/tests/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,4 +748,109 @@ mod scanner {
]
);
}

#[test]
fn it_includes_explicit_source_when_ignored_by_top_level_gitignore() {
use std::fs;
use tempfile::tempdir;

// Create a temporary working directory
let dir = tempdir().unwrap().into_path();

// Initialize as a git repository so that .gitignore handling takes effect
let _ = std::process::Command::new("git")
.arg("init")
.current_dir(&dir)
.output();

// Create a directory "template" with a file and a .gitignore at the root ignoring "template"
create_files_in(
&dir,
&[
(".gitignore", ".venv"),
(".venv/template/index.html", "content-['index.html']"),
],
);

// Set up a glob source entry for scanning the "template" directory.
let sources = vec![GlobEntry {
base: dir.join(".venv/template").to_string_lossy().to_string(),
pattern: "**/*".to_owned(),
}];

// Even though the directory is ignored via the top-level .gitignore, it should still be scanned as an explicit source
let candidates_without_gitignore = Scanner::new(Some(sources)).scan();
assert_eq!(candidates_without_gitignore, vec!["content-['index.html']".to_owned()]);
}

#[test]
fn it_includes_explicit_source_when_ignored_by_top_level_gitignore_glob() {
use std::fs;
use tempfile::tempdir;

// Create a temporary working directory
let dir = tempdir().unwrap().into_path();

// Initialize as a git repository so that .gitignore handling takes effect
let _ = std::process::Command::new("git")
.arg("init")
.current_dir(&dir)
.output();

// Create a directory "template" with a file and a .gitignore at the root ignoring "template"
create_files_in(
&dir,
&[
(".gitignore", ".venv/**/*"),
(".venv/template/index.html", "content-['index.html']"),
],
);

// Set up a glob source entry for scanning the "template" directory.
let sources = vec![GlobEntry {
base: dir.join(".venv/template").to_string_lossy().to_string(),
pattern: "**/*".to_owned(),
}];

// Even though the directory is ignored via the top-level .gitignore, it should still be scanned as an explicit source
let candidates_without_gitignore = Scanner::new(Some(sources)).scan();
assert_eq!(candidates_without_gitignore, vec!["content-['index.html']".to_owned()]);
}

#[test]
fn it_includes_explicit_source_overriding_nested_gitignore() {
use std::fs;
use tempfile::tempdir;

// Create a temporary working directory
let dir = tempdir().unwrap().into_path();

// Initialize as a git repository so that .gitignore handling takes effect
let _ = std::process::Command::new("git")
.arg("init")
.current_dir(&dir)
.output();

// Create a directory "template" with a file and both a root .gitignore ignoring "template"
// and a nested .gitignore that ignores all contents in the "template" folder.
create_files_in(
&dir,
&[
(".gitignore", ".venv"),
(".venv/template/index.html", "content-['index.html']"),
(".venv/.gitignore", "*"),
],
);

// Set up a glob source entry for scanning the "template" directory.
let sources = vec![GlobEntry {
base: dir.join(".venv/template").to_string_lossy().to_string(),
pattern: "**/*".to_owned(),
}];

// Even though the nested .gitignore ignores all files, the explicit source should override it.
let candidates_without_gitignore = Scanner::new(Some(sources)).scan();
assert_eq!(candidates_without_gitignore, vec!["content-['index.html']".to_owned()]);
}

}
Loading