Handle deleted files in pre-commit hook

This commit is contained in:
akp 2025-03-17 12:27:44 +00:00
parent 2073c5e907
commit 97eae24225
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import sys
import os
import subprocess
from pathlib import Path
@ -8,6 +9,10 @@ staged_fnames = subprocess.check_output(["git", "diff", "--name-only", "--cached
contains_gps = []
for fname in staged_fnames:
try:
os.stat(fname)
except FileNotFoundError: # deleted in this commit
continue
cont = subprocess.check_output(["exiftool", "-gpslatitude", "-gpslongitude", "-T", fname]).decode()
if cont != "-\t-\n": # output where there is no result
contains_gps.append((fname, cont))