Skip to content

Commit 2bf15e4

Browse files
committed
Modify condition to exclude git ignore file
1 parent 43c6687 commit 2bf15e4

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/fosslight_prechecker/_precheck.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,19 @@ def exclude_gitignore_files(current_path, path):
5252
global DEFAULT_EXCLUDE_EXTENSION_FILES
5353
try:
5454
root_path = VCSStrategyGit.find_root(current_path)
55-
if os.path.isfile(os.path.join(root_path, '.gitignore')):
56-
cmd_result = subprocess.check_output(['git',
57-
'ls-files',
58-
'-ci',
59-
'--exclude-from=.gitignore'],
60-
universal_newlines=True)
61-
cmd_result = cmd_result.split('\n')
62-
cmd_result.remove('')
63-
if not path.endswith(f"{os.sep}"):
64-
path += f"{os.sep}"
65-
cmd_result = [file.replace(path, '', 1) for file in cmd_result]
66-
DEFAULT_EXCLUDE_EXTENSION_FILES.extend(cmd_result)
67-
else:
68-
return
55+
if root_path:
56+
if os.path.isfile(os.path.join(root_path, '.gitignore')):
57+
cmd_result = subprocess.check_output(['git',
58+
'ls-files',
59+
'-ci',
60+
'--exclude-from=.gitignore'],
61+
universal_newlines=True)
62+
cmd_result = cmd_result.split('\n')
63+
cmd_result.remove('')
64+
if not path.endswith(f"{os.sep}"):
65+
path += f"{os.sep}"
66+
cmd_result = [file.replace(path, '', 1) for file in cmd_result]
67+
DEFAULT_EXCLUDE_EXTENSION_FILES.extend(cmd_result)
6968
except Exception as ex:
7069
logger.warning(f"Error to get git ignored files : {ex}")
7170

0 commit comments

Comments
 (0)