Skip to content

Commit

Permalink
Fix issue with new files
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Jan 22, 2024
1 parent 4521238 commit a525f00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rapids_pre_commit_hooks/copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ def the_check(linter, args):
except KeyError:
return

old_content = changed_file.data_stream.read().decode("utf-8")
old_content = (
changed_file.data_stream.read().decode("utf-8")
if changed_file is not None
else None
)
apply_copyright_check(linter, old_content)

return the_check
Expand Down
12 changes: 12 additions & 0 deletions test/rapids_pre_commit_hooks/test_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ def file_contents_modified(num):
git_repo.index.move(["file2.txt", "file5.txt"])
git_repo.index.commit("Rename file2.txt to file5.txt")

write_file("file6.txt", file_contents(6))

def mock_repo_cwd():
return patch("os.getcwd", Mock(return_value=git_repo.working_tree_dir))

Expand Down Expand Up @@ -724,6 +726,11 @@ def mock_apply_copyright_check():
copyright_checker(linter, None)
apply_copyright_check.assert_called_once_with(linter, file_contents(4))

linter = Linter("file6.txt", file_contents(6))
with mock_apply_copyright_check() as apply_copyright_check:
copyright_checker(linter, None)
apply_copyright_check.assert_called_once_with(linter, None)

#############################
# branch-2 is target branch
#############################
Expand All @@ -750,3 +757,8 @@ def mock_apply_copyright_check():
with mock_apply_copyright_check() as apply_copyright_check:
copyright_checker(linter, None)
apply_copyright_check.assert_called_once_with(linter, file_contents(4))

linter = Linter("file6.txt", file_contents(6))
with mock_apply_copyright_check() as apply_copyright_check:
copyright_checker(linter, None)
apply_copyright_check.assert_called_once_with(linter, None)

0 comments on commit a525f00

Please sign in to comment.