I've found a number of similar questions, but not this exact one. For reference, here are some similar issues:
if git index.lock exist, can I safely delete it, or are more actions needed to verify integrity?
Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists
I am programmatically using git across a number of repos, and the (Windows) app sits in a loop doing "git pull", "git commit" and "git push", keeping a number of repos in sync with local and remote data changes.
On occasion my app runs into the "index.lock file exists" problem. The app is used in various environments where the computer may indeed just be shut down randomly...long story.
Question: can I simply code up an attempt to delete index.lock any time the app encounters this error? Is that "safe"?
I am concerned about timing issues. For example, does git hold this file open while it is in use (so my delete attempt will correctly fail) or could deleting a non-orphaned index.lock file succeed and then corrupt my repo? Or will deleting index.lock out from under an index update simply cause that update to fail, and it needs to be attempted again the next time the app loops through the pull?
Other answers say things like "make sure no git processes are running before deleting index.lock", but that doesn't really work in the real world because it introduces timing problems - i.e. the app looks and there are no "git" processes, but before it deletes index.lock a git process starts.
Any insight - or out of the box suggestions - would be much appreciated. Thanks!