From 97eae2422525ce6db6a78c33f3bc8cdcf13a6c07 Mon Sep 17 00:00:00 2001 From: AKP Date: Mon, 17 Mar 2025 12:27:44 +0000 Subject: [PATCH] Handle deleted files in pre-commit hook --- hooks/pre-commit | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hooks/pre-commit b/hooks/pre-commit index 7fcd482..cf15ca1 100644 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -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))