Merge pull request #1216 from vegerot/pr1216
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add flag --no-require-git to always respect gitignore files
authored by David Peter · committed by GitHub · parents 503ede7, 08c0d42 · Browse files · 7 files·+88 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+88 added−2 removed
- tests:+57 added−0 removed
- other:+31 added−2 removed
Provenance
- Commit
af9daff- Tree
5c87098- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
503ede7- Parent 2
08c0d42
7 files changed+88 added−2 removed
modified:src/cli.rs+22 added
72 unmodified lines73 /// Overrides --no-ignore-vcs74 #[arg(long, overrides_with = "no_ignore_vcs", hide = true, action = ArgAction::SetTrue)]75 ignore_vcs: (),76 77+ /// Do not require a git repository to respect gitignores.78+ /// By default, fd will only respect global gitignore rules, .gitignore rules,79+ /// and local exclude rules if fd detects that you are searching inside a80+ /// git repository. This flag allows you to relax this restriction such that81+ /// fd will respect all git related ignore rules regardless of whether you're82+ /// searching in a git repository or not.83+ ///84+ ///85+ /// This flag can be disabled with --require-git.86+ #[arg(87+ long,88+ overrides_with = "require_git",89+ hide_short_help = true,90+ // same description as ripgrep's flag: ripgrep/crates/core/app.rs91+ long_help92+ )]93+ pub no_require_git: bool,94+95+ /// Overrides --no-require-git96+ #[arg(long, overrides_with = "no_require_git", hide = true, action = ArgAction::SetTrue)]97+ require_git: (),98+99 /// Show search results from files and directories that would otherwise be100 /// ignored by '.gitignore', '.ignore', or '.fdignore' files in parent directories.101 #[arg(102 long,759 unmodified linesmodified:src/config.rs+3 added
28 unmodified lines29 30 /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.31 pub read_vcsignore: bool,32 33+ /// Whether to require a `.git` directory to respect gitignore files.34+ pub require_git_to_read_vcsignore: bool,35+36 /// Whether to respect the global ignore file or not.37 pub read_global_ignore: bool,38 39 /// Whether to follow symlinks or not.93 unmodified linesmodified:src/main.rs+1 added
237 unmodified lines238 search_full_path: opts.full_path,239 ignore_hidden: !(opts.hidden || opts.rg_alias_ignore()),240 read_fdignore: !(opts.no_ignore || opts.rg_alias_ignore()),241 read_vcsignore: !(opts.no_ignore || opts.rg_alias_ignore() || opts.no_ignore_vcs),242+ require_git_to_read_vcsignore: !opts.no_require_git,243 read_parent_ignore: !opts.no_ignore_parent,244 read_global_ignore: !(opts.no_ignore245 || opts.rg_alias_ignore()246 || opts.no_global_ignore_file),224 unmodified linesmodified:src/walk.rs+1 added
75 unmodified lines76 .parents(config.read_parent_ignore && (config.read_fdignore || config.read_vcsignore))77 .git_ignore(config.read_vcsignore)78 .git_global(config.read_vcsignore)79 .git_exclude(config.read_vcsignore)80+ .require_git(config.require_git_to_read_vcsignore)81 .overrides(overrides)82 .follow_links(config.follow_links)83 // No need to check for supported platforms, option is unavailable on unsupported ones84 .same_file_system(config.one_file_system)474 unmodified linesmodified:tests/tests.rs+57 added
806 unmodified lines807 808 te.assert_output(&["--no-ignore", "foo"], "inner/foo");809 }810 811+/// Don't require git to respect gitignore (--no-require-git)812+#[test]813+fn test_respect_ignore_files() {814+ let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);815+816+ // Not in a git repo anymore817+ fs::remove_dir(te.test_root().join(".git")).unwrap();818+819+ // don't respect gitignore because we're not in a git repo820+ te.assert_output(821+ &["foo"],822+ "a.foo823+ gitignored.foo824+ one/b.foo825+ one/two/c.foo826+ one/two/C.Foo2827+ one/two/three/d.foo828+ one/two/three/directory_foo/",829+ );830+831+ // respect gitignore because we set `--no-require-git`832+ te.assert_output(833+ &["--no-require-git", "foo"],834+ "a.foo835+ one/b.foo836+ one/two/c.foo837+ one/two/C.Foo2838+ one/two/three/d.foo839+ one/two/three/directory_foo/",840+ );841+842+ // make sure overriding works843+ te.assert_output(844+ &["--no-require-git", "--require-git", "foo"],845+ "a.foo846+ gitignored.foo847+ one/b.foo848+ one/two/c.foo849+ one/two/C.Foo2850+ one/two/three/d.foo851+ one/two/three/directory_foo/",852+ );853+854+ te.assert_output(855+ &["--no-require-git", "--no-ignore", "foo"],856+ "a.foo857+ gitignored.foo858+ fdignored.foo859+ one/b.foo860+ one/two/c.foo861+ one/two/C.Foo2862+ one/two/three/d.foo863+ one/two/three/directory_foo/",864+ );865+}866+867 /// VCS ignored files (--no-ignore-vcs)868 #[test]869 fn test_no_ignore_vcs() {870 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);1590 unmodified lines2461 2462 #[test_case("--hidden", &["--no-hidden"] ; "hidden")]2463 #[test_case("--no-ignore", &["--ignore"] ; "no-ignore")]2464 #[test_case("--no-ignore-vcs", &["--ignore-vcs"] ; "no-ignore-vcs")]2465+#[test_case("--no-require-git", &["--require-git"] ; "no-require-git")]2466 #[test_case("--follow", &["--no-follow"] ; "follow")]2467 #[test_case("--absolute-path", &["--relative-path"] ; "absolute-path")]2468 #[test_case("-u", &["--ignore", "--no-hidden"] ; "u")]2469 #[test_case("-uu", &["--ignore", "--no-hidden"] ; "uu")]74 unmodified linesmodified:CHANGELOG.md+2 added
1 # Upcoming release2 3 ## Features4 5+- Add flag --no-require-git to always respect gitignore files, see #1216 (@vegerot)6+7 ## Bugfixes8 9 - Fix logic for when to use global ignore file. There was a bug where the only case where the10 global ignore file wasn't processed was if `--no-ignore` was passed, but neither `--unrestricted`676 unmodified linesmodified:CONTRIBUTING.md+2 added-2 removed
11 unmodified lines12131415161617181920202122232413 unmodified lines11 unmodified lines
## Add an entry to the changelog
If your contribution changes the behavior of `fd` (as opposed to a typo-fixin the documentation), please update the [`CHANGELOG.md`](CHANGELOG.md) filein the documentation), please update the [`CHANGELOG.md`](CHANGELOG.md#upcoming-release) fileand describe your changes. This makes the release process much easier andtherefore helps to get your changes into a new `fd` release faster.
The top of the `CHANGELOG` contains a *"unreleased"* section with a fewThe top of the `CHANGELOG` contains an *"Upcoming release"* section with a fewsubsections (Features, Bugfixes, …). Please add your entry to the subsectionthat best describes your change.
Entries follow this format:13 unmodified lines