summaryrefslogtreecommitdiffstats
path: root/misc/scripts/dotnet_format.py
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2024-03-02 10:48:25 +0100
committerGitHub <noreply@github.com>2024-03-02 10:48:25 +0100
commitf2045ba822bff7d34964901393581a3117c394a9 (patch)
treeef4d0bac04a7831fc203679500c22d92f29a4e33 /misc/scripts/dotnet_format.py
parentdad6c774b019ef8c5dccb4a1955c6a77b41a323e (diff)
parent97851f03401537b7fa0affc50a5800eda351c4b8 (diff)
downloadredot-engine-f2045ba822bff7d34964901393581a3117c394a9.tar.gz
Merge pull request #88933 from raulsntos/dotnet/pre-commit
Move dotnet-format script to pre-commit
Diffstat (limited to 'misc/scripts/dotnet_format.py')
-rw-r--r--misc/scripts/dotnet_format.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/misc/scripts/dotnet_format.py b/misc/scripts/dotnet_format.py
new file mode 100644
index 0000000000..de414bbe30
--- /dev/null
+++ b/misc/scripts/dotnet_format.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import glob
+import os
+import sys
+
+# Create dummy generated files.
+for path in [
+ "modules/mono/SdkPackageVersions.props",
+]:
+ os.makedirs(os.path.dirname(path), exist_ok=True)
+ with open(path, "w") as f:
+ f.write("<Project />")
+
+# Avoid importing GeneratedIncludes.props.
+os.environ["GodotSkipGenerated"] = "true"
+
+# Match all the input files to their respective C# project.
+input_files = [os.path.normpath(x) for x in sys.argv]
+projects = {
+ path: [f for f in sys.argv if os.path.commonpath([f, path]) == path]
+ for path in [os.path.dirname(f) for f in glob.glob("**/*.csproj", recursive=True)]
+}
+
+# Run dotnet format on all projects with more than 0 modified files.
+for path, files in projects.items():
+ if len(files) > 0:
+ command = f"dotnet format {path} --include {' '.join(files)}"
+ os.system(command)