jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1162826?usp=email )

Change subject: Tests: Fix git commands for copyright_fixer.py
......................................................................

Tests: Fix git commands for copyright_fixer.py

- use "git diff --name-only" and "git show --format= --name-only HEAD"
  to catch changed files
- set require_serial for this patch to prohibit multiple git commands
  during pre-commit run which otherwise uses multiprocessing by default

Change-Id: I8027ba6d3cf9e3824312dddc9488f3620799f170
---
M .pre-commit-config.yaml
M tests/hooks/copyright_fixer.py
2 files changed, 16 insertions(+), 4 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a8da2f5..0b74aac 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -63,6 +63,7 @@
         entry: tests/hooks/copyright_fixer.py
         files: .+\.py$
         language: python
+        require_serial: true
   - repo: https://github.com/astral-sh/ruff-pre-commit
     rev: v0.12.2
     hooks:
diff --git a/tests/hooks/copyright_fixer.py b/tests/hooks/copyright_fixer.py
index 93eeb81..f725190 100755
--- a/tests/hooks/copyright_fixer.py
+++ b/tests/hooks/copyright_fixer.py
@@ -22,10 +22,21 @@

 def get_patched_files():
     """Return the PatchSet for the latest commit."""
-    out = subprocess.run(['git', 'diff', '--unified=0'],
-                         stdout=subprocess.PIPE,
-                         check=True, encoding='utf-8', text=True).stdout
-    return {Path(path) for path in re.findall(r'(?m)^\+\+\+ b/(.+)$', out)
+    cmd_opts = ' --name-only --diff-filter=AMR'
+    diff_cmd = f'git diff {cmd_opts}'.split()
+    show_cmd = f'git show --format= {cmd_opts}'.split()
+
+    captures = []
+    captures.append(
+        subprocess.check_output(diff_cmd, encoding='utf-8')
+    )
+    captures.append(
+        subprocess.check_output(diff_cmd + ['--staged'], encoding='utf-8')
+    )
+    captures.append(
+        subprocess.check_output(show_cmd + ['HEAD'], encoding='utf-8')
+    )
+    return {Path(path) for capture in captures for path in capture.splitlines()
             if path.endswith('.py')}



--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1162826?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I8027ba6d3cf9e3824312dddc9488f3620799f170
Gerrit-Change-Number: 1162826
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to