Skip to content
Snippets Groups Projects
Verified Commit 7412205a authored by René Fritze's avatar René Fritze
Browse files

[hooks/symlinks] use git-ls to walk to-be-checked files

fixes #2
parent a18500d4
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,8 @@ with status 1. If none are found exit with status 0. ...@@ -7,6 +7,8 @@ with status 1. If none are found exit with status 0.
import sys import sys
import os import os
from pathlib import Path from pathlib import Path
import subprocess
def _resolve(path): def _resolve(path):
try: try:
...@@ -18,21 +20,21 @@ def _resolve(path): ...@@ -18,21 +20,21 @@ def _resolve(path):
except FileNotFoundError: except FileNotFoundError:
return Path(os.readlink(str(path))) return Path(os.readlink(str(path)))
broken = [] broken = []
for root, dirs, files in os.walk('.'): files = subprocess.check_output(['git', 'ls-files'],
if root.startswith('./.git'): universal_newlines=True)
# Ignore the .git directory. root = os.getcwd()
for filename in files.splitlines():
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 continue
for filename in files:
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
if len(broken) == 0: if len(broken) == 0:
sys.exit(0) sys.exit(0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment