nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pre-commit/pre-commit
Pull request #375 (2016-05-25 09:22:26)

only consider forward diff in changed files
Consider we have a branch A.
I create two branches B, C from A and make changes independently.
I merge changes from C into A.
Now if I run pre-commit between A and B, diff shows the changes from branch C also.


Patch:
diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py
index 9c21900..424e295 100644
--- a/pre_commit/commands/run.py
+++ b/pre_commit/commands/run.py
@@ -51,7 +51,7 @@ def _print_user_skipped(hook, write, args):
 
 def get_changed_files(new, old):
     return cmd_output(
-        'git', 'diff', '--name-only', '{0}..{1}'.format(old, new),
+        'git', 'diff', '--name-only', '{0}...{1}'.format(old, new),
     )[1].splitlines()
 
 


Test patch:
diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py
index f85468c..ae8b523 100644
--- a/tests/commands/run_test.py
+++ b/tests/commands/run_test.py
@@ -401,6 +401,10 @@ def test_get_changed_files():
     )
     assert files == ['CHANGELOG.md', 'setup.py']
 
+    # files changed in source but not in origin should not be returned
+    files = get_changed_files('HEAD~10', 'HEAD')
+    assert files == []
+
 
 def test_lots_of_files(mock_out_store_directory, tempdir_factory):
     # windows xargs seems to have a bug, here's a regression test for
Repository: pre-commit/pre-commit
Pull request #513 (2017-03-27 14:40:09)

Fix regression in 0.13.5 with always_run + files


Patch:
diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py
index 58031e8..23d662a 100644
--- a/pre_commit/clientlib.py
+++ b/pre_commit/clientlib.py
@@ -38,7 +38,7 @@ MANIFEST_HOOK_DICT = schema.Map(
 
     schema.Conditional(
         'files', schema.check_and(schema.check_string, schema.check_regex),
-        condition_key='always_run', condition_value=False, ensure_absent=True,
+        condition_key='always_run', condition_value=False,
     ),
 
     schema.Optional(


Test patch:
diff --git a/tests/clientlib_test.py b/tests/clientlib_test.py
index deaa7e9..454824a 100644
--- a/tests/clientlib_test.py
+++ b/tests/clientlib_test.py
@@ -187,6 +187,20 @@ def test_validate_manifest_main(args, expected_output):
             }],
             True,
         ),
+        (
+            # A regression in 0.13.5: always_run and files are permissible
+            # together (but meaningless).  In a future version upgrade this to
+            # an error
+            [{
+                'id': 'a',
+                'name': 'b',
+                'entry': 'c',
+                'language': 'python',
+                'files': '',
+                'always_run': True,
+            }],
+            True,
+        ),
     )
 )
 def test_valid_manifests(manifest_obj, expected):
Repository: pre-commit/pre-commit
Pull request #538 (2017-05-13 22:49:53)

Add pass_filenames hook option
This option controls whether filenames are passed along as arguments to
the hook program.


Patch:
diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py
index d386dcd..bceecaa 100644
--- a/pre_commit/clientlib.py
+++ b/pre_commit/clientlib.py
@@ -46,6 +46,7 @@ MANIFEST_HOOK_DICT = schema.Map(
     ),
     schema.Optional('args', schema.check_array(schema.check_string), []),
     schema.Optional('always_run', schema.check_bool, False),
+    schema.Optional('pass_filenames', schema.check_bool, True),
     schema.Optional('description', schema.check_string, ''),
     schema.Optional(
         'exclude',
diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py
index 40917e1..3039b66 100644
--- a/pre_commit/commands/run.py
+++ b/pre_commit/commands/run.py
@@ -86,7 +86,10 @@ def _run_single_hook(hook, repo, args, skips, cols):
     sys.stdout.flush()
 
     diff_before = cmd_output('git', 'diff', retcode=None, encoding=None)
-    retcode, stdout, stderr = repo.run_hook(hook, tuple(filenames))
+    retcode, stdout, stderr = repo.run_hook(
+        hook,
+        tuple(filenames) if hook['pass_filenames'] else (),
+    )
     diff_after = cmd_output('git', 'diff', retcode=None, encoding=None)
 
     file_modifications = diff_before != diff_after


Test patch:
diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py
index 984ac6b..d8522da 100644
--- a/tests/commands/run_test.py
+++ b/tests/commands/run_test.py
@@ -731,3 +731,29 @@ def test_files_running_subdir(
                 tempdir_factory=tempdir_factory,
             )
         assert 'subdir/foo.py'.replace('/', os.sep) in stdout
+
+
+@pytest.mark.parametrize(
+    ('pass_filenames', 'hook_args', 'expected_out'),
+    (
+        (True, [], b'foo.py'),
+        (False, [], b''),
+        (True, ['some', 'args'], b'some args foo.py'),
+        (False, ['some', 'args'], b'some args'),
+    )
+)
+def test_pass_filenames(
+        cap_out, repo_with_passing_hook, mock_out_store_directory,
+        pass_filenames,
+        hook_args,
+        expected_out,
+):
+    with modify_config() as config:
+        config[0]['hooks'][0]['pass_filenames'] = pass_filenames
+        config[0]['hooks'][0]['args'] = hook_args
+    stage_a_file()
+    ret, printed = _do_run(
+        cap_out, repo_with_passing_hook, _get_opts(verbose=True),
+    )
+    assert expected_out + b'\nHello World' in printed
+    assert (b'foo.py' in printed) == pass_filenames
diff --git a/tests/manifest_test.py b/tests/manifest_test.py
index 1296b21..47e7fa3 100644
--- a/tests/manifest_test.py
+++ b/tests/manifest_test.py
@@ -32,6 +32,7 @@ def test_manifest_contents(manifest):
         'log_file': '',
         'minimum_pre_commit_version': '0',
         'name': 'Bash hook',
+        'pass_filenames': True,
         'stages': [],
     }]
 
@@ -51,6 +52,7 @@ def test_hooks(manifest):
         'log_file': '',
         'minimum_pre_commit_version': '0',
         'name': 'Bash hook',
+        'pass_filenames': True,
         'stages': [],
     }
Repository: pre-commit/pre-commit
Pull request #574 (2017-08-01 03:26:00)

Fix patch applying when apply.whitespace=error


Patch:
diff --git a/pre_commit/staged_files_only.py b/pre_commit/staged_files_only.py
index 862c6bd..151e924 100644
--- a/pre_commit/staged_files_only.py
+++ b/pre_commit/staged_files_only.py
@@ -45,7 +45,10 @@ def staged_files_only(cmd_runner):
         finally:
             # Try to apply the patch we saved
             try:
-                cmd_runner.run(('git', 'apply', patch_filename), encoding=None)
+                cmd_runner.run(
+                    ('git', 'apply', '--whitespace=nowarn', patch_filename),
+                    encoding=None,
+                )
             except CalledProcessError:
                 logger.warning(
                     'Stashed changes conflicted with hook auto-fixes... '
@@ -55,7 +58,10 @@ def staged_files_only(cmd_runner):
                 # by hooks.
                 # Roll back the changes made by hooks.
                 cmd_runner.run(['git', 'checkout', '--', '.'])
-                cmd_runner.run(('git', 'apply', patch_filename), encoding=None)
+                cmd_runner.run(
+                    ('git', 'apply', patch_filename, '--whitespace=nowarn'),
+                    encoding=None,
+                )
             logger.info('Restored changes from {}.'.format(patch_filename))
     else:
         # There weren't any staged files so we don't need to do anything


Test patch:
diff --git a/tests/staged_files_only_test.py b/tests/staged_files_only_test.py
index e066c27..ecaee81 100644
--- a/tests/staged_files_only_test.py
+++ b/tests/staged_files_only_test.py
@@ -340,7 +340,7 @@ bool_product = tuple(itertools.product((True, False), repeat=2))
 def test_crlf(in_git_dir, cmd_runner, crlf_before, crlf_after, autocrlf):
     cmd_output('git', 'config', '--local', 'core.autocrlf', autocrlf)
 
-    before, after = b'1\n2\n', b'3\n4\n'
+    before, after = b'1\n2\n', b'3\n4\n\n'
     before = before.replace(b'\n', b'\r\n') if crlf_before else before
     after = after.replace(b'\n', b'\r\n') if crlf_after else after
 
@@ -349,3 +349,8 @@ def test_crlf(in_git_dir, cmd_runner, crlf_before, crlf_after, autocrlf):
     _write(after)
     with staged_files_only(cmd_runner):
         assert_no_diff()
+
+
+def test_whitespace_errors(in_git_dir, cmd_runner):
+    cmd_output('git', 'config', '--local', 'apply.whitespace', 'error')
+    test_crlf(in_git_dir, cmd_runner, True, True, 'true')
Repository: pre-commit/pre-commit
Pull request #586 (2017-08-11 03:40:39)

Upgrade the sample-config output


Patch:
diff --git a/pre_commit/commands/sample_config.py b/pre_commit/commands/sample_config.py
index f38d655..b74e427 100644
--- a/pre_commit/commands/sample_config.py
+++ b/pre_commit/commands/sample_config.py
@@ -11,7 +11,7 @@ SAMPLE_CONFIG = '''\
 # See http://pre-commit.com for more information
 # See http://pre-commit.com/hooks.html for more hooks
 -   repo: https://github.com/pre-commit/pre-commit-hooks
-    sha: v0.7.1
+    sha: v0.9.1
     hooks:
     -   id: trailing-whitespace
     -   id: end-of-file-fixer


Test patch:
diff --git a/tests/commands/sample_config_test.py b/tests/commands/sample_config_test.py
index 88a90d9..122d7bf 100644
--- a/tests/commands/sample_config_test.py
+++ b/tests/commands/sample_config_test.py
@@ -12,7 +12,7 @@ def test_sample_config(capsys):
 # See http://pre-commit.com for more information
 # See http://pre-commit.com/hooks.html for more hooks
 -   repo: https://github.com/pre-commit/pre-commit-hooks
-    sha: v0.7.1
+    sha: v0.9.1
     hooks:
     -   id: trailing-whitespace
     -   id: end-of-file-fixer