Skip to content
Myr

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

7 files+88 added−2 removed

modified:src/cli.rs+22 added
72 unmodified lines
73 /// Overrides --no-ignore-vcs74 #[arg(long, overrides_with = "no_ignore_vcs", hide = true, action = ArgAction::SetTrue)]75 ignore_vcs: (),7677 /// 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,9495 /// Overrides --no-require-git96 #[arg(long, overrides_with = "no_require_git", hide = true, action = ArgAction::SetTrue)]97 require_git: (),9899 /// 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 lines
modified:src/config.rs+3 added
28 unmodified lines
2930 /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.31 pub read_vcsignore: bool,3233 /// Whether to require a `.git` directory to respect gitignore files.34 pub require_git_to_read_vcsignore: bool,3536 /// Whether to respect the global ignore file or not.37 pub read_global_ignore: bool,3839 /// Whether to follow symlinks or not.
93 unmodified lines
modified:src/main.rs+1 added
237 unmodified lines
238 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 lines
modified:src/walk.rs+1 added
75 unmodified lines
76 .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 lines
modified:tests/tests.rs+57 added
806 unmodified lines
807808 te.assert_output(&["--no-ignore", "foo"], "inner/foo");809}810811/// Don't require git to respect gitignore (--no-require-git)812#[test]813fn test_respect_ignore_files() {814 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);815816 // Not in a git repo anymore817 fs::remove_dir(te.test_root().join(".git")).unwrap();818819 // 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 );830831 // 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 );841842 // 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 );853854 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}866867/// VCS ignored files (--no-ignore-vcs)868#[test]869fn test_no_ignore_vcs() {870 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
1590 unmodified lines
24612462#[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 lines
modified:CHANGELOG.md+2 added
1# Upcoming release23## Features45- Add flag --no-require-git to always respect gitignore files, see #1216 (@vegerot)67## Bugfixes89- 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 lines
modified:CONTRIBUTING.md+2 added-2 removed