-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal: add clang-format git hook to devcontainer (#2226)
- Loading branch information
Showing
7 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM mcr.microsoft.com/devcontainers/javascript-node:22 | ||
|
||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
clang-format-15 \ | ||
# Clean cache | ||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ | ||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* \ | ||
&& mv /usr/bin/clang-format-15 /usr/bin/clang-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"name": "Node.js Codespace", | ||
"image": "mcr.microsoft.com/devcontainers/javascript-node:22", | ||
"postCreateCommand": "yarn", | ||
"remoteUser": "node" | ||
"name": "SkyMP Codespace", | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
}, | ||
"postCreateCommand": "mkdir -p .git/hooks && ln -sf $(pwd)/misc/git-hooks/pre-commit .git/hooks/pre-commit && chmod +x misc/git-hooks/pre-commit && cd misc/git-hooks && npm install simple-git", | ||
"remoteUser": "node" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { execSync } = require("child_process"); | ||
const simpleGit = require("simple-git"); | ||
|
||
const extensions = [".cpp", ".h", ".hpp", ".cxx", ".cc"]; | ||
|
||
(async () => { | ||
try { | ||
const git = simpleGit(); | ||
const changedFiles = await git.diff(["--name-only", "--cached"]); | ||
|
||
const filesToFormat = changedFiles | ||
.split("\n") | ||
.filter( | ||
(file) => | ||
extensions.some((ext) => file.endsWith(ext)) && file.trim() !== "" | ||
); | ||
|
||
if (filesToFormat.length === 0) { | ||
console.log("No files to format."); | ||
process.exit(0); | ||
} | ||
|
||
console.log("Formatting files:"); | ||
filesToFormat.forEach((file) => { | ||
console.log(` - ${file}`); | ||
execSync(`clang-format -i ${file}`, { stdio: "inherit" }); | ||
execSync(`git add ${file}`); | ||
}); | ||
|
||
console.log("Formatting completed and changes staged."); | ||
} catch (err) { | ||
console.error("Error during formatting:", err.message); | ||
console.error("Autofix failed. Commit aborted."); | ||
process.exit(1); | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"simple-git": "^3.27.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
node misc/git-hooks/clang-format-hook.js |