I am watching an arbitrary folder with inotifywait. When a file changes, I want to determine which git repo (if any) is relevant to that file.
I see this answer: How to tell if a file is git tracked (by shell exit code)?
The difference here is - I don't really care if git is tracking the file or not, I just want to know - if git were to track that file, which git existing git repo would it be for. That is my question.
Is the best way to do this simply:
#!/usr/bin/env bash
cd "$(dirname "$changed_file")" && git rev-parse --show-toplevel
? is that about right? will that git rev-parse --show-toplevel
command always given the relevant repo for that file?