Skip to content

Problem when checking for ignored files #1543

Closed
@Lightborne

Description

@Lightborne

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions