Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vcsetup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
ag-ohlberger
dune-community
vcsetup
Commits
a18500d4
Verified
Commit
a18500d4
authored
7 years ago
by
René Fritze
Browse files
Options
Downloads
Patches
Plain Diff
refactor broken link detection
parent
07ae812b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hooks/pre-commit.d/02-detect-broken-symlinks.py
+15
-15
15 additions, 15 deletions
hooks/pre-commit.d/02-detect-broken-symlinks.py
with
15 additions
and
15 deletions
hooks/pre-commit.d/02-detect-broken-symlinks.py
+
15
−
15
View file @
a18500d4
...
...
@@ -6,18 +6,17 @@ with status 1. If none are found exit with status 0.
"""
import
sys
import
os
from
pathlib
import
Path
def
_target
(
path
):
"""
Resolve relative symlinks
"""
def
_resolve
(
path
):
try
:
from
pathlib
import
Path
return
Path
(
path
).
resolve
()
except
ImportError
:
pass
target_path
=
os
.
readlink
(
path
)
if
not
os
.
path
.
isabs
(
target_path
):
target_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
path
),
target_path
)
return
str
(
target_path
)
return
path
.
resolve
(
False
)
except
TypeError
:
# fallback for py < 3.6
try
:
return
path
.
resolve
()
except
FileNotFoundError
:
return
Path
(
os
.
readlink
(
str
(
path
)))
broken
=
[]
for
root
,
dirs
,
files
in
os
.
walk
(
'
.
'
):
...
...
@@ -25,11 +24,12 @@ for root, dirs, files in os.walk('.'):
# Ignore the .git directory.
continue
for
filename
in
files
:
path
=
os
.
path
.
join
(
root
,
filename
)
if
os
.
path
.
islink
(
path
):
target_path
=
_target
(
path
)
if
not
os
.
path
.
exists
(
target_path
):
broken
.
append
(
'
{} --> {}
'
.
format
(
path
,
target_path
))
path
=
Path
(
os
.
path
.
join
(
root
,
filename
))
if
path
.
is_symlink
():
target
=
_resolve
(
path
)
# exists already checks if the pointed to file is there
if
not
path
.
exists
():
broken
.
append
(
'
{} --> {}
'
.
format
(
path
,
target
))
else
:
# If it's not a symlink we're not interested.
continue
...
...
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