Skip to content

Problem when checking for ignored files #1543

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

Closed
Lightborne opened this issue Jan 20, 2023 · 4 comments
Closed

Problem when checking for ignored files #1543

Lightborne opened this issue Jan 20, 2023 · 4 comments

Comments

@Lightborne
Copy link
Contributor

Hello,
I stumbled on an issue that i think calls for an update to the GitPython's ignored function.

I have a script that performs certain format checks on all files in a repository. Simple things like removing trailing whitespace. This script is written to only run on files that have been added to the repository, and it is written to not run on any untracked or ignored files.

My script generates a list of all the files in the workspace, and then it removes untracked and ignored files from that list. something like this

self.file_list # all the files in the repo
self.ignored_files = repo.ignored(self.file_list) # should return all ignored files 

Our company's working environment requires us to run several tools within the workspace that holds the repo. These tools all put their output into directories that we have ignored with .gitignore. But some of these tools create symbolic links within these directories.

Now, GitPython's implementation of repo.ignored is basically a wrapper around git's built in check-ignore sub-command. When you try to check if a file behind a symbolic link is ignored using this sub-command, git throws a fatal error:

# This is the good case - git correctly tells me that both of these are ignored.
git check-ignore ignore_file.txt ignore/target/ignore.txt 
ignore_file.txt
ignore/target/ignore.txt

# This is the bad case - git simply bails with a fatal error
git check-ignore ignore_file.txt ignore/link/ignore.txt 
fatal: pathspec 'ignore/link/ignore.txt' is beyond a symbolic link

GitPython's repo.ignored implementation does not catch this fatal error. What it does is return an empty list.

So my script was failing because it was trying to format_check a bunch of stuff that was buried in an ignored directory!

I think what needs to happen is that the repo.ignored function needs to be enhanced to raise an exception when git throws this fatal error. Then, I could trap that exception and parse my file list, removing any entries that are hidden behind symbolic links.

@Byron
Copy link
Member

Byron commented Jan 21, 2023

Thanks for the detailed description of the issue.

I totally agree that it shouldn't squelch errors, and a PR to address that would be much appreciated.

@Lightborne
Copy link
Contributor Author

Lightborne commented Jan 21, 2023

Sounds good, I think I can get something put together.

@Lightborne
Copy link
Contributor Author

Pull request is here:

#1545

@Byron Byron added this to the v3.1.31 - Bugfixes milestone Jan 22, 2023
@Byron
Copy link
Member

Byron commented Jan 22, 2023

Thanks a lot!

Closing as the PR was merged.

@Byron Byron closed this as completed Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants