Skip to content

Commit 8f75aa7

Browse files
committed
Add clang formatting for submodule as well.
1 parent 38613be commit 8f75aa7

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

.clang-format

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BasedOnStyle: LLVM
2+
3+
TabWidth: 2
4+
ColumnLimit: 100
5+
UseTab: Never
6+
7+
CommentPragmas: '^/'
8+
ReflowComments: true
9+
AlignTrailingComments: true
10+
SpacesBeforeTrailingComments: 1
11+
12+
SpaceBeforeParens: ControlStatements
13+
SpacesInSquareBrackets: false
14+
BreakBeforeBraces: Allman
15+
PointerAlignment: Middle
16+
17+
BinPackParameters: false
18+
BinPackArguments: false
19+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
20+
AllowShortBlocksOnASingleLine: false
21+
AllowShortFunctionsOnASingleLine: true
22+
AllowShortIfStatementsOnASingleLine: false
23+
AllowShortLoopsOnASingleLine: false
24+
25+
SortIncludes: false
26+
IndentCaseLabels: true
27+
ConstructorInitializerIndentWidth: 2
28+
AlwaysBreakAfterDefinitionReturnType: TopLevel
29+
AlwaysBreakTemplateDeclarations: true

scripts/install-format-hook.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# Main repo hook file
4+
5+
REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../"
6+
hookfile="$REPO_DIR/.git/hooks/pre-commit"
7+
8+
if [[ -f $hookfile ]]; then
9+
echo "'$hookfile' already exists - aborting" 1>&2
10+
else
11+
echo '#!/bin/bash
12+
patch=$(git clang-format --diff)
13+
if [[ "$patch" =~ "no modified files to format" || "$patch" =~ "clang-format did not modify any files" ]]; then
14+
echo "" > /dev/null
15+
else
16+
echo ""
17+
echo "Your code has bad style." >&2
18+
echo "Run 'git clang-format' to resolve the following issues:" >&2
19+
echo ""
20+
echo "$patch"
21+
exit 1
22+
fi
23+
' > $hookfile
24+
chmod a+x $hookfile
25+
fi
26+
27+
# Squirrel submodule hook file
28+
29+
squirrel_hookfile="$REPO_DIR/.git/modules/squirrel/hooks/pre-commit"
30+
31+
if [[ -f $squirrel_hookfile ]]; then
32+
echo "'$squirrel_hookfile' already exists - aborting" 1>&2
33+
exit 1
34+
fi
35+
36+
echo '#!/bin/bash
37+
patch=$(git clang-format --diff)
38+
if [[ "$patch" =~ "no modified files to format" || "$patch" =~ "clang-format did not modify any files" ]]; then
39+
echo "" > /dev/null
40+
else
41+
echo ""
42+
echo "Your code has bad style." >&2
43+
echo "Run 'git clang-format' to resolve the following issues:" >&2
44+
echo ""
45+
echo "$patch"
46+
exit 1
47+
fi
48+
' > $squirrel_hookfile
49+
50+
chmod a+x $squirrel_hookfile

0 commit comments

Comments
 (0)