Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openairinterface5G
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mingxuan Li
openairinterface5G
Commits
d0079ce5
Commit
d0079ce5
authored
2 years ago
by
Robert Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Add clang-format specific pre-commit hook
parent
030e0c40
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pre-commit-clang
+54
-0
54 additions, 0 deletions
pre-commit-clang
with
54 additions
and
0 deletions
pre-commit-clang
0 → 100644
+
54
−
0
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment