Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mkdocs-material
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Janne Mareike Koschinski
mkdocs-material
Commits
fc024da6
Commit
fc024da6
authored
Dec 27, 2016
by
squidfunk
Browse files
Options
Downloads
Patches
Plain Diff
Refactored githook for pre-commit linting
parent
b812c54f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
.githooks/pre-commit/lint.sh
+19
-39
19 additions, 39 deletions
.githooks/pre-commit/lint.sh
with
19 additions
and
39 deletions
.githooks/pre-commit/lint.sh
+
19
−
39
View file @
fc024da6
...
...
@@ -20,51 +20,31 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
Check, if all changes are added to the index
CWD_CLEAN
=
"
$(
git diff-index HEAD
--
)
"
#
Patch file to store unindexed changes
PATCH_FILE
=
".working-tree.patch
"
# This variables stores the state of the stash.
# 0 = not restored yet.
# 1 = stash was already reset
STASH_POPPED
=
0
# Pop the stash in case of trap
# Revert changes that have been registered in the patch file
function
cleanup
{
if
test
-n
"
$CWD_CLEAN
"
;
then
if
test
"
$STASH_POPPED
"
!=
1
;
then
# Pop the changes (= stash) back to the work space
git stash pop
-q
fi
EXIT_CODE
=
$?
if
[
-f
"
$PATCH_FILE
"
]
;
then
git apply
"
$PATCH_FILE
"
2> /dev/null
rm
"
$PATCH_FILE
"
fi
exit
exit
$EXIT_CODE
}
# Register signal handler
trap
cleanup
SIGHUP
SIGINT SIG
TERM
# Register signal handler
s
trap
cleanup
EXIT
SIGINT SIG
HUP
# Stash all changes that were not added to the commit
if
test
-n
"
$CWD_CLEAN
"
;
then
git stash
-q
--keep-index
--include-untracked
fi
# Cancel any changes to the working tree that are not going to be committed
git diff
>
"
$PATCH_FILE
"
git checkout
--
.
# Filter relevant files for linting
FILES
=
$(
git diff
--cached
--name-only
--diff-filter
=
ACMR |
grep
"
\.
js
\|
scss$"
)
# Run the check and print indicator
if
[
"
$FILES
"
]
;
then
echo
"Hook[pre-commit]: Running linter..."
STD_OUT
=
$(
npm run lint
--silent
)
# Grab exit code of check
HAD_ERROR
=
$?
# Pop the changes (= stash) back to the work space
if
test
-n
"
$CWD_CLEAN
"
;
then
git stash pop
-q
STASH_POPPED
=
1
fi
# In case of error, print output of check
if
test
"
$HAD_ERROR
"
!=
0
;
then
echo
${
STD_OUT
}
exit
1
npm run lint
--silent
||
exit
1
fi
# Reset indicator and exit
exit
0
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