Skip to content

Commit

Permalink
Stop ignore .git folders by default
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs committed Apr 29, 2024
1 parent 8eb0479 commit e10a4ea
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- Add `dir` as an alias to `directory` when using `-t` \ `--type`, see #1460 and #1464 (@Ato2207).
- Add support for @%s date format in time filters similar to GNU date (seconds since Unix epoch for --older/--newer), see #1493 (@nabellows)
- Breaking: No longer automatically ignore `.git` when using `--hidden` with vcs ignore enabled. This reverts the change in v9.0.0. While this feature
was often useful, it also broke some existing workflows, and there wasn't a good way to opt out of it. And there isn't really a good way for us to add
a way to opt out of it. And you can easily get similar behavior by adding `.git/` to your global fdignore file.
See #1457.

## Bugfixes

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ If you want `fd` to ignore these patterns globally, you can put them in `fd`'s g
This is usually located in `~/.config/fd/ignore` in macOS or Linux, and `%APPDATA%\fd\ignore` in
Windows.

You may wish to include `.git/` in your `fd/ignore` file so that `.git` directories, and their contents
are not included in output if you use the `--hidden` option.

### Deleting files

You can use `fd` to remove all files and directories that are matched by your search pattern.
Expand Down
28 changes: 23 additions & 5 deletions doc/fd.1
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ with the '\-\-glob' option.
By default
.B fd
will exclude hidden files and directories, as well as any files that match gitignore rules
or ignore rules in .ignore or .fdignore files. For convenenience, '.git' is treated as if it
was always included in gitignore rules. These files can be included with options such as
'\-\-hidden' and '\-\-no\-ignore'.
or ignore rules in .ignore or .fdignore files.
.SH OPTIONS
.TP
.B \-H, \-\-hidden
Include hidden files and directories in the search results
(default: hidden files and directories are skipped). The flag can be overridden with '--no-hidden'.
.IP
Ignored files and .git/ are still excluded unless \-\-no\-ignore or \-\-no\-ignore\-vcs
Ignored files are still excluded unless \-\-no\-ignore or \-\-no\-ignore\-vcs
is also used.
.TP
.B \-I, \-\-no\-ignore
Expand Down Expand Up @@ -79,7 +77,6 @@ and the global gitignore configuration
.RI ( core.excludesFile
git setting, which defaults to
.IR $HOME/.config/git/ignore ).
The pattern ".git/" is automatically added to the list of VCS ignore rules.
The flag can be overridden with '--ignore-vcs'.
.TP
.B \-\-no\-require\-git
Expand Down Expand Up @@ -494,6 +491,17 @@ is set, use
.IR $XDG_CONFIG_HOME/fd/ignore .
Otherwise, use
.IR $HOME/.config/fd/ignore .
.SH FILES
.TP
.B .fdignore
This file works similarly to a .gitignore file anywhere in the searched tree and specifies patterns
that should be excluded from the search. However, this file is specific to fd, and will be used even
if the --no-ignore-vcs option is used.
.TP
.B $XDG_CONFIG_HOME/fd/ignore
Global ignore file. Unless ignore mode is turned off (such as with --no-ignore)
ignore entries in this file will be ignored, as if it was an .fdignore file in the
current directory.
.SH EXAMPLES
.TP
.RI "Find files and directories that match the pattern '" needle "':"
Expand All @@ -507,6 +515,16 @@ $ fd -e py
.TP
.RI "Open all search results with vim:"
$ fd pattern -X vim
.SH Tips and Tricks
.IP \[bu]
If you add ".git/" to your global ignore file ($XDG_CONFIG_HOME/fd/ignore), then
".git" folders will be ignored by default, even when the --hidden option is used.
.IP \[bu]
You can use a shell alias or a wrapper script in order to pass desired flags to fd
by default. For example if you do not like the default behavior of respecting gitignore,
you can use
`alias fd="/usr/bin/fd --no-ignore-vcs"`
in your .bashrc to create an alias for fd that doesn't ignore git files by default.
.SH BUGS
Bugs can be reported on GitHub: https://github.com/sharkdp/fd/issues
.SH SEE ALSO
Expand Down
5 changes: 2 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ pub struct Opts {
no_hidden: (),

/// Show search results from files and directories that would otherwise be
/// ignored by '.gitignore', '.ignore', '.fdignore', the global ignore file,
/// or the default rule that excludes .git/.
/// ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file,
/// The flag can be overridden with --ignore.
#[arg(
long,
Expand All @@ -64,7 +63,7 @@ pub struct Opts {
#[arg(long, overrides_with = "no_ignore", hide = true, action = ArgAction::SetTrue)]
ignore: (),

///Show search results from '.git/' folders and files and directories that
///Show search results from files and directories that
///would otherwise be ignored by '.gitignore' files.
///The flag can be overridden with --ignore-vcs.
#[arg(
Expand Down
4 changes: 0 additions & 4 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,6 @@ impl WorkerState {
.map_err(|e| anyhow!("Malformed exclude pattern: {}", e))?;
}

if config.read_vcsignore {
builder.add("!.git/").expect("Invalid exclude pattern");
}

builder
.build()
.map_err(|_| anyhow!("Mismatch in exclude patterns"))
Expand Down
9 changes: 8 additions & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2573,7 +2573,14 @@ fn test_git_dir() {
],
);

te.assert_output(&["--hidden", "foo"], "");
te.assert_output(
&["--hidden", "foo"],
".git/one/foo.a
.git/.foo
.git/a.foo
other_dir/.git/foo1
nested/dir/.git/foo2",
);
te.assert_output(&["--no-ignore", "foo"], "");
te.assert_output(
&["--hidden", "--no-ignore", "foo"],
Expand Down

0 comments on commit e10a4ea

Please sign in to comment.