@@ -39,6 +39,24 @@ def test_add_something_giant(temp_git_dir):
3939 # Should pass with higher bound
4040 assert find_large_added_files (['f.py' ], 10 ) == 0
4141
42+ # Should fail, irrespective of check_only_staged when staged
43+ assert find_large_added_files (['f.py' ], 0 , enforce_all = True ) == 1
44+ assert find_large_added_files (['f.py' ], 0 , enforce_all = False ) == 1
45+
46+ # File is committed hence no longer staged
47+ cmd_output ('git' , 'commit' , '-m' , 'log' )
48+
49+
50+ def test_enforce_all (temp_git_dir ):
51+ with temp_git_dir .as_cwd ():
52+ temp_git_dir .join ('f.py' ).write ('a' * 10000 )
53+
54+ # Should fail, when not staged with enforce_all
55+ assert find_large_added_files (['f.py' ], 0 , enforce_all = True ) == 1
56+
57+ # Should pass, when not staged without enforce_all
58+ assert find_large_added_files (['f.py' ], 0 , enforce_all = False ) == 0
59+
4260
4361def test_added_file_not_in_pre_commits_list (temp_git_dir ):
4462 with temp_git_dir .as_cwd ():
@@ -80,8 +98,10 @@ def test_allows_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
8098 temp_git_dir .join ('f.py' ).write ('a' * 10000 )
8199 cmd_output ('git' , 'lfs' , 'track' , 'f.py' )
82100 cmd_output ('git' , 'add' , '--' , '.' )
83- # Should succeed
101+ # Without --enforce-all large files on git lfs should succeed
84102 assert main (('--maxkb' , '9' , 'f.py' )) == 0
103+ # With --enforce-all large files on git lfs should succeed
104+ assert main (('--enforce-all' , '--maxkb' , '9' , 'f.py' )) == 0
85105
86106
87107@xfailif_no_gitlfs
@@ -97,3 +117,18 @@ def test_moves_with_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
97117 # Now move it and make sure the hook still succeeds
98118 cmd_output ('git' , 'mv' , 'a.bin' , 'b.bin' )
99119 assert main (('--maxkb' , '9' , 'b.bin' )) == 0
120+
121+
122+ @xfailif_no_gitlfs
123+ def test_enforce_all_gitlfs (temp_git_dir , monkeypatch ): # pragma: no cover
124+ with temp_git_dir .as_cwd ():
125+ monkeypatch .setenv ('HOME' , str (temp_git_dir ))
126+ cmd_output ('git' , 'lfs' , 'install' )
127+ cmd_output ('git' , 'lfs' , 'track' , 'a.bin' , 'b.bin' )
128+ # First add the file we're going to move
129+ temp_git_dir .join ('a.bin' ).write ('a' * 10000 )
130+ cmd_output ('git' , 'add' , '--' , '.' )
131+ cmd_output ('git' , 'commit' , '--no-gpg-sign' , '-am' , 'foo' )
132+ # Now move it and make sure the hook still succeeds
133+ cmd_output ('git' , 'mv' , 'a.bin' , 'b.bin' )
134+ assert main (('--enforce-all' , '--maxkb' , '9' , 'b.bin' )) == 0
0 commit comments