0

I wish to get the current commit hash in my python script using the following command:

subprocess.check_output(['git', 'rev-parse', 'HEAD'])

It returns an empty string for some reason. When run on another system it seems to return the commit hash as expected. Does anyone know why?

vgalin
  • 491
  • 4
  • 18
  • Try some additional tests: run `pwd` instead of `git rev-parse HEAD`, for instance, or run some command that definitely *must* produce output. Reduce this to a [mcve] that demonstrates the bug on the system in question. – torek Mar 12 '22 at 05:06
  • When I ran `pwd` I got an error -> FileNotFoundError: [WinError 2] The system cannot find the file specified – DesperateCoder Mar 15 '22 at 12:08
  • Interesting. That would cause problems for Git! Not sure how that can happen on Windows (I know how to make it happen on Unix/Linux systems, but I believe this method doesn't work on Windows). (On a Linux-like system, you make that happen by removing the directory while you're in it. The directory still exists, it's just no longer in the file system, and is now its own self-referential bubble that can never be used anywhere else.) – torek Mar 16 '22 at 02:00

0 Answers0