Skip to content

Commit 93b5ca3

Browse files
committed
Fix Command class to use args for file detection in tests
The get_added_files() method was using sys.argv to find files, which doesn't work in test environments where files are passed via args parameter. Changed to use self.args first (for testing), falling back to sys.argv for normal hook execution. This fixes test_cfg_files_are_filtered test.
1 parent 88d7969 commit 93b5ca3

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

hooks/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def check_installed(self):
3737

3838
def get_added_files(self):
3939
"""Find added files using git."""
40-
added_files = sys.argv[1:] # 1: don't include the hook file
40+
# Use self.args if available (for testing), otherwise fall back to sys.argv
41+
added_files = self.args[1:] if self.args else sys.argv[1:]
4142
# cfg files are used by uncrustify and won't be source files
4243
added_files = [f for f in added_files if os.path.exists(f) and not f.endswith(".cfg")]
4344

0 commit comments

Comments
 (0)