Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
spbro
OpenXG-RAN
Commits
d0079ce5
Commit
d0079ce5
authored
Jul 25, 2022
by
Robert Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add clang-format specific pre-commit hook
parent
030e0c40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
pre-commit-clang
pre-commit-clang
+54
-0
No files found.
pre-commit-clang
0 → 100644
View file @
d0079ce5
#!/usr/bin/env bash
#
# Runs clang-format on changed regions before commit.
#
# To install this, copy it to .git/hooks/pre-commit in your repo.
# Remaining installation checks/instructions will be printed when you commit.
#
read
-d
''
help
<<-
EOF
This repository requires you to install the clang-format command. This hook has
been tested with clang-format-10, so remove all previous versions and reinstall:
$
sudo apt-get remove clang-format-*
$
sudo apt-get install clang-format-10
You should now have clang-format-10 installed. Then, update the configuration
as follows:
$
git config --global clangFormat.binary clang-format-10
$
git config --global clangFormat.style file
$
git config --global alias.clang-format clang-format-10
EOF
check_clang_format
()
{
if
hash
git clang-format 2>/dev/null
;
then
return
else
echo
"SETUP ERROR: no git clang-format executable found, or it is not executable"
echo
"
$help
"
exit
1
fi
}
check_git_config
()
{
if
[[
"
$(
git config
--get
clangFormat.binary
)
"
!=
"clang-format-10"
]]
;
then
echo
"SETUP ERROR: git config clangFormat.binary should be
\"
clang-format-10
\"
."
echo
"
$help
"
exit
1
fi
if
[[
"
$(
git config
--get
clangFormat.style
)
"
!=
"file"
]]
;
then
echo
"SETUP ERROR: git config clangFormat.style should be
\"
file
\"
."
echo
"
$help
"
exit
1
fi
}
check_clang_format
check_git_config
readonly
out
=
$(
git clang-format
-v
--diff
)
if
[[
"
$out
"
==
*
"no modified files to format"
*
]]
;
then
exit
0
;
fi
if
[[
"
$out
"
==
*
"clang-format did not modify any files"
*
]]
;
then
exit
0
;
fi
echo
"ERROR: the code to be committed is not formatted properly"
echo
"you need to run
\"
git clang-format
\"
on your commit"
exit
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment