Skip to content
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

Incorrect behavior of --git-ignore flag #614

Closed
micouy opened this issue Dec 15, 2019 · 4 comments
Closed

Incorrect behavior of --git-ignore flag #614

micouy opened this issue Dec 15, 2019 · 4 comments

Comments

@micouy
Copy link

micouy commented Dec 15, 2019

I've tested it in a dir with such structure:

.
├── a      // dir
├── b      // dir
│  └── a   // file
├── c      // dir
│  └── a   // dir
└── d      // dir

I ran exa --tree --git-ignore with different versions of .gitignore. There are 2 problems

exa doesn't exclude directories if there's a backslash at the end of the line.

IMO this one is the most annoying. git's docs say:

For example, a pattern doc/frotz/ matches doc/frotz directory, but not a/doc/frotz directory; however frotz/ matches frotz and a/frotz that is a directory (all paths are relative from the .gitignore file).

and

If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories.

It seems like the backslash at the end is a valid path in .gitignore but exa doesn't exclude it.

.gitignore:

a/

Output:

.
├── a      // dir not excluded
├── b
│  └── a
├── c
│  └── a   // subdir not excluded
└── d

exa only excludes directories and files if they are at the same level as .gitignore.

Docs say:

If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.

However, exa doesn't exclude files nor dirs inside other dirs.

.gitignore:

a # notice that there's no backslash at the end of the line

Output:

.          // the `a` dir was properly excluded
├── b
│  └── a   // file not excluded
├── c
│  └── a   // subdir not excluded
└── d

I've also tested what happens if I put .gitignore in a dir and exa takes it into account. The behavior is expected (the same files are/are not excluded) but still not correct.

This issue is related to #369.

I use this flag quite often and I'd be very happy if a shortened version was added :).

@ghost
Copy link

ghost commented Apr 21, 2020

I can confirm that this is an issue.
Screenshot from 2020-04-21 12-10-55
As you can see from my screenshot, directories like .idea don't get ignored because of the slash (I've tested it without the slash and it filters properly).

Not only that, but I can also confirm the point about filtering of files if they're in a subdirectory
Screenshot from 2020-04-21 12-07-24
because *.iml doesn't get picked up, yet the git column is aware that it's an ignored file.

@epwalsh
Copy link

epwalsh commented Aug 26, 2020

Still an issue...

@Alrefai
Copy link

Alrefai commented Sep 15, 2020

I added the following to my ~/.zshrc as a workaround for this issue:

alias lt='exa -lahT --ignore-glob=".git|$(ignore)"'

ignore() {
  if [[ -f .gitignore ]]; then
    local GIT_IGNORE='.gitignore'
  else
    local GIT_IGNORE="${HOME}/.gitignore_global"
  fi

  grep '\S' "${GIT_IGNORE}" 2>/dev/null |
    tr -d '\r' |
    grep -v '^#' |
    sed 's/^\///;s/\/$//' |
    paste -sd '|' -
}

@ariasuni
Copy link
Collaborator

This has been fixed by #653.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants