Skip to content

Commit a0a4291

Browse files
committed
Run cargo fmt
1 parent 2dbdd7c commit a0a4291

File tree

2 files changed

+88
-78
lines changed

2 files changed

+88
-78
lines changed

crates/oxide/src/scanner/allowed_paths.rs

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ pub fn resolve_allowed_paths(root: &Path) -> impl Iterator<Item = DirEntry> {
3333

3434
#[tracing::instrument(skip_all)]
3535
pub fn resolve_paths(root: &Path) -> impl Iterator<Item = DirEntry> {
36-
create_walk_builder(root)
37-
.build()
38-
.filter_map(Result::ok)
36+
create_walk_builder(root).build().filter_map(Result::ok)
3937
}
4038

4139
pub fn read_dir(root: &Path, depth: Option<usize>) -> impl Iterator<Item = DirEntry> {
@@ -56,58 +54,58 @@ pub fn read_dir(root: &Path, depth: Option<usize>) -> impl Iterator<Item = DirEn
5654
}
5755

5856
fn create_walk_builder(root: &Path) -> WalkBuilder {
59-
let mut builder = WalkBuilder::new(root);
57+
let mut builder = WalkBuilder::new(root);
6058

61-
// Scan hidden files / directories
62-
builder.hidden(false);
59+
// Scan hidden files / directories
60+
builder.hidden(false);
6361

64-
// By default, allow .gitignore files to be used regardless of whether or not
65-
// a .git directory is present. This is an optimization for when projects
66-
// are first created and may not be in a git repo yet.
67-
builder.require_git(false);
62+
// By default, allow .gitignore files to be used regardless of whether or not
63+
// a .git directory is present. This is an optimization for when projects
64+
// are first created and may not be in a git repo yet.
65+
builder.require_git(false);
6866

69-
// Don't descend into .git directories inside the root folder
70-
// This is necessary when `root` contains the `.git` dir.
71-
builder.filter_entry(|entry| entry.file_name() != ".git");
67+
// Don't descend into .git directories inside the root folder
68+
// This is necessary when `root` contains the `.git` dir.
69+
builder.filter_entry(|entry| entry.file_name() != ".git");
7270

73-
// If we are in a git repo then require it to ensure that only rules within
74-
// the repo are used. For example, we don't want to consider a .gitignore file
75-
// in the user's home folder if we're in a git repo.
76-
//
77-
// The alternative is using a call like `.parents(false)` but that will
78-
// prevent looking at parent directories for .gitignore files from within
79-
// the repo and that's not what we want.
80-
//
81-
// For example, in a project with this structure:
82-
//
83-
// home
84-
// .gitignore
85-
// my-project
86-
// .gitignore
87-
// apps
88-
// .gitignore
89-
// web
90-
// {root}
91-
//
92-
// We do want to consider all .gitignore files listed:
93-
// - home/.gitignore
94-
// - my-project/.gitignore
95-
// - my-project/apps/.gitignore
96-
//
97-
// However, if a repo is initialized inside my-project then only the following
98-
// make sense for consideration:
99-
// - my-project/.gitignore
100-
// - my-project/apps/.gitignore
101-
//
102-
// Setting the require_git(true) flag conditionally allows us to do this.
103-
for parent in root.ancestors() {
104-
if parent.join(".git").exists() {
105-
builder.require_git(true);
106-
break;
71+
// If we are in a git repo then require it to ensure that only rules within
72+
// the repo are used. For example, we don't want to consider a .gitignore file
73+
// in the user's home folder if we're in a git repo.
74+
//
75+
// The alternative is using a call like `.parents(false)` but that will
76+
// prevent looking at parent directories for .gitignore files from within
77+
// the repo and that's not what we want.
78+
//
79+
// For example, in a project with this structure:
80+
//
81+
// home
82+
// .gitignore
83+
// my-project
84+
// .gitignore
85+
// apps
86+
// .gitignore
87+
// web
88+
// {root}
89+
//
90+
// We do want to consider all .gitignore files listed:
91+
// - home/.gitignore
92+
// - my-project/.gitignore
93+
// - my-project/apps/.gitignore
94+
//
95+
// However, if a repo is initialized inside my-project then only the following
96+
// make sense for consideration:
97+
// - my-project/.gitignore
98+
// - my-project/apps/.gitignore
99+
//
100+
// Setting the require_git(true) flag conditionally allows us to do this.
101+
for parent in root.ancestors() {
102+
if parent.join(".git").exists() {
103+
builder.require_git(true);
104+
break;
105+
}
107106
}
108-
}
109107

110-
builder
108+
builder
111109
}
112110

113111
pub fn is_allowed_content_path(path: &Path) -> bool {

crates/oxide/tests/scanner.rs

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -598,56 +598,62 @@ mod scanner {
598598
&[
599599
// This file should always be picked up
600600
("home/project/apps/web/index.html", "content-['index.html']"),
601-
602601
// Set up various ignore rules
603602
("home/.gitignore", "ignore-home.html"),
604603
("home/project/.gitignore", "ignore-project.html"),
605604
("home/project/apps/.gitignore", "ignore-apps.html"),
606605
("home/project/apps/web/.gitignore", "ignore-web.html"),
607-
608606
// Some of these should be ignored depending on which dir is the repo root
609-
("home/project/apps/web/ignore-home.html", "content-['ignore-home.html']"),
610-
("home/project/apps/web/ignore-project.html", "content-['ignore-project.html']"),
611-
("home/project/apps/web/ignore-apps.html", "content-['ignore-apps.html']"),
612-
("home/project/apps/web/ignore-web.html", "content-['ignore-web.html']"),
607+
(
608+
"home/project/apps/web/ignore-home.html",
609+
"content-['ignore-home.html']",
610+
),
611+
(
612+
"home/project/apps/web/ignore-project.html",
613+
"content-['ignore-project.html']",
614+
),
615+
(
616+
"home/project/apps/web/ignore-apps.html",
617+
"content-['ignore-apps.html']",
618+
),
619+
(
620+
"home/project/apps/web/ignore-web.html",
621+
"content-['ignore-web.html']",
622+
),
613623
],
614624
);
615625

616-
617-
let sources = vec![
618-
GlobEntry {
619-
base: dir.join("home/project/apps/web").to_string_lossy().to_string(),
620-
pattern: "**/*".to_owned(),
621-
},
622-
];
626+
let sources = vec![GlobEntry {
627+
base: dir
628+
.join("home/project/apps/web")
629+
.to_string_lossy()
630+
.to_string(),
631+
pattern: "**/*".to_owned(),
632+
}];
623633

624634
let candidates = Scanner::new(Some(sources.clone())).scan();
625635

626636
// All ignore files are applied because there's no git repo
627-
assert_eq!(
628-
candidates,
629-
vec![
630-
"content-['index.html']".to_owned(),
631-
]
632-
);
637+
assert_eq!(candidates, vec!["content-['index.html']".to_owned(),]);
633638

634639
// Initialize `home` as a git repository and scan again
635640
// The results should be the same as before
636-
_ = Command::new("git").arg("init").current_dir(dir.join("home")).output();
641+
_ = Command::new("git")
642+
.arg("init")
643+
.current_dir(dir.join("home"))
644+
.output();
637645
let candidates = Scanner::new(Some(sources.clone())).scan();
638646

639-
assert_eq!(
640-
candidates,
641-
vec![
642-
"content-['index.html']".to_owned(),
643-
]
644-
);
647+
assert_eq!(candidates, vec!["content-['index.html']".to_owned(),]);
645648

646649
// Drop the .git folder
647650
fs::remove_dir_all(dir.join("home/.git")).unwrap();
648651

649652
// Initialize `home/project` as a git repository and scan again
650-
_ = Command::new("git").arg("init").current_dir(dir.join("home/project")).output();
653+
_ = Command::new("git")
654+
.arg("init")
655+
.current_dir(dir.join("home/project"))
656+
.output();
651657
let candidates = Scanner::new(Some(sources.clone())).scan();
652658

653659
assert_eq!(
@@ -662,7 +668,10 @@ mod scanner {
662668
fs::remove_dir_all(dir.join("home/project/.git")).unwrap();
663669

664670
// Initialize `home/project/apps` as a git repository and scan again
665-
_ = Command::new("git").arg("init").current_dir(dir.join("home/project/apps")).output();
671+
_ = Command::new("git")
672+
.arg("init")
673+
.current_dir(dir.join("home/project/apps"))
674+
.output();
666675
let candidates = Scanner::new(Some(sources.clone())).scan();
667676

668677
assert_eq!(
@@ -678,7 +687,10 @@ mod scanner {
678687
fs::remove_dir_all(dir.join("home/project/apps/.git")).unwrap();
679688

680689
// Initialize `home/project/apps` as a git repository and scan again
681-
_ = Command::new("git").arg("init").current_dir(dir.join("home/project/apps/web")).output();
690+
_ = Command::new("git")
691+
.arg("init")
692+
.current_dir(dir.join("home/project/apps/web"))
693+
.output();
682694
let candidates = Scanner::new(Some(sources.clone())).scan();
683695

684696
assert_eq!(

0 commit comments

Comments
 (0)