nebius/SWE-bench-extra huggingface dataset:
Repository: pre-commit/pre-commit-hooks

Issue:
`check-vcs-permalinks` - Add support for different branch names
Not all repositories use `master` for their branch name so it would be great if this hook could support other branch names.

Preferably, this would match any blob link that doesn't contain a full hash (so *only* matching 0-f with len of 40 or 64) but if you don't consider that to be a good solution, then being able to specify a list of branches to match would also work, though it would be a lot more likely to lead to non-permalinks not getting matched.

Comments:

Patch:
diff --git a/pre_commit_hooks/check_vcs_permalinks.py b/pre_commit_hooks/check_vcs_permalinks.py
index a30277c..5231d7a 100644
--- a/pre_commit_hooks/check_vcs_permalinks.py
+++ b/pre_commit_hooks/check_vcs_permalinks.py
@@ -8,7 +8,10 @@ from typing import Sequence
 
 
 def _get_pattern(domain: str) -> Pattern[bytes]:
-    regex = rf'https://{domain}/[^/ ]+/[^/ ]+/blob/master/[^# ]+#L\d+'
+    regex = (
+        rf'https://{domain}/[^/ ]+/[^/ ]+/blob/'
+        r'(?![a-fA-F0-9]{4,64}/)([^/. ]+)/[^# ]+#L\d+'
+    )
     return re.compile(regex.encode())
 
 


Test patch:
diff --git a/tests/check_vcs_permalinks_test.py b/tests/check_vcs_permalinks_test.py
index 7d5f86c..ad59151 100644
--- a/tests/check_vcs_permalinks_test.py
+++ b/tests/check_vcs_permalinks_test.py
@@ -11,6 +11,8 @@ def test_passing(tmpdir):
     f.write_binary(
         # permalinks are ok
         b'https://github.com/asottile/test/blob/649e6/foo%20bar#L1\n'
+        # tags are ok
+        b'https://github.com/asottile/test/blob/1.0.0/foo%20bar#L1\n'
         # links to files but not line numbers are ok
         b'https://github.com/asottile/test/blob/master/foo%20bar\n'
         # regression test for overly-greedy regex
@@ -23,7 +25,8 @@ def test_failing(tmpdir, capsys):
     with tmpdir.as_cwd():
         tmpdir.join('f.txt').write_binary(
             b'https://github.com/asottile/test/blob/master/foo#L1\n'
-            b'https://example.com/asottile/test/blob/master/foo#L1\n',
+            b'https://example.com/asottile/test/blob/master/foo#L1\n'
+            b'https://example.com/asottile/test/blob/main/foo#L1\n',
         )
 
         assert main(('f.txt', '--additional-github-domain', 'example.com'))
@@ -31,6 +34,7 @@ def test_failing(tmpdir, capsys):
         assert out == (
             'f.txt:1:https://github.com/asottile/test/blob/master/foo#L1\n'
             'f.txt:2:https://example.com/asottile/test/blob/master/foo#L1\n'
+            'f.txt:3:https://example.com/asottile/test/blob/main/foo#L1\n'
             '\n'
             'Non-permanent github link detected.\n'
             'On any page on github press [y] to load a permalink.\n'
Repository: pre-commit/pre-commit-hooks

Issue:
`file-contents-sorter` adds an extra blank line if the file to be sorted is empty
I am on `v.4.4.0`, Python `3.11.4`, macOS Ventura `13.4.1`.

My `.pre-commit-config.yaml`:

```yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: "v4.4.0"
    hooks:
      - id: end-of-file-fixer
      - id: file-contents-sorter
        files: ^requirements\/.+\.in$
        # args: [--unique, --ignore-case]
```

The files are intentionally **empty** &ndash; I'm in the planning stage, they are just placeholders for requriements[^1].

To the point: `file-contents-sorter` adds an extra blank to them, what results in a confict with `end-of-file-fixer`. I am not sure if that is the expected behavior... Updating `args` doesn't have any effect.

```bash
$ git:(install-and-configure-pre-commit) : pre-commit run --all-files
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing requirements/build.in
Fixing requirements/lint.in
Fixing requirements/test.in

file contents sorter.....................................................Failed
- hook id: file-contents-sorter
- exit code: 1
- files were modified by this hook

Sorting requirements/build.in
Sorting requirements/lint.in
Sorting requirements/test.in
```

[^1]: Yes, I know that I can use `requirements-txt-fixer` particularly for requirements. 😄 I will do. For that issue it doesn't matter.

Comments:

Patch:
diff --git a/pre_commit_hooks/file_contents_sorter.py b/pre_commit_hooks/file_contents_sorter.py
index c5691f0..02bdbcc 100644
--- a/pre_commit_hooks/file_contents_sorter.py
+++ b/pre_commit_hooks/file_contents_sorter.py
@@ -37,7 +37,10 @@ def sort_file_contents(
     after = sorted(lines, key=key)
 
     before_string = b''.join(before)
-    after_string = b'\n'.join(after) + b'\n'
+    after_string = b'\n'.join(after)
+
+    if after_string:
+        after_string += b'\n'
 
     if before_string == after_string:
         return PASS


Test patch:
diff --git a/tests/file_contents_sorter_test.py b/tests/file_contents_sorter_test.py
index 5e79e40..49b3b79 100644
--- a/tests/file_contents_sorter_test.py
+++ b/tests/file_contents_sorter_test.py
@@ -10,7 +10,9 @@ from pre_commit_hooks.file_contents_sorter import PASS
 @pytest.mark.parametrize(
     ('input_s', 'argv', 'expected_retval', 'output'),
     (
-        (b'', [], FAIL, b'\n'),
+        (b'', [], PASS, b''),
+        (b'\n', [], FAIL, b''),
+        (b'\n\n', [], FAIL, b''),
         (b'lonesome\n', [], PASS, b'lonesome\n'),
         (b'missing_newline', [], FAIL, b'missing_newline\n'),
         (b'newline\nmissing', [], FAIL, b'missing\nnewline\n'),