Title: [294748] trunk/Tools/Scripts/hooks/pre-commit
Revision
294748
Author
[email protected]
Date
2022-05-24 08:38:44 -0700 (Tue, 24 May 2022)

Log Message

[GitHub] git-webkit pr doesn't sort Xcode project files before uploading
https://bugs.webkit.org/show_bug.cgi?id=239975
<rdar://92976140>

Reviewed by Chris Dumez.

* Tools/Scripts/hooks/pre-commit: Sort Xcode project files on commit.

Canonical link: https://commits.webkit.org/250916@main

Added Paths

Diff

Added: trunk/Tools/Scripts/hooks/pre-commit (0 => 294748)


--- trunk/Tools/Scripts/hooks/pre-commit	                        (rev 0)
+++ trunk/Tools/Scripts/hooks/pre-commit	2022-05-24 15:38:44 UTC (rev 294748)
@@ -0,0 +1,38 @@
+#!/usr/bin/env {{ python }}
+
+import os
+import subprocess
+import sys
+
+LOCATION = '{{ location }}'
+SCRIPTS = os.path.dirname(os.path.dirname(LOCATION))
+
+
+def files(staged=True):
+    try:
+        lines = []
+        for line in subprocess.check_output(
+            ['{{ git }}', 'diff', '--name-only'] + (['--staged'] if staged else []),
+            encoding='utf-8',
+        ).splitlines():
+            if line:
+                lines.append(line)
+        return lines
+    except subprocess.CalledProcessError:
+        return []
+
+
+staged = files(staged=True)
+unstaged = files(staged=False)
+
+project_files = []
+for line in staged or unstaged:
+    if line.endswith('pbxproj'):
+        project_files.append(line)
+
+if project_files:
+    code = subprocess.run([os.path.join(SCRIPTS, 'sort-Xcode-project-file')] + project_files).returncode
+    if staged:
+        code += subprocess.run(['{{ git }}', 'add'] + project_files).returncode
+    sys.exit(code)
+sys.exit(0)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to