I'm using hooks to call and write the Commit-Number of the submodule to a file.
Using Git Bash:
git submodule
This works just fine, and returns Commit-No, Name and branch.
But when I try to use Python's subprocess module, it fails. Getting the same result using CMD, PowerShell or calling the Hooks file from my IDE.
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.check_output(['git','submodule']).decode()
git: 'submodule' is not a git command. See 'git --help'.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python310\lib\subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Python310\lib\subprocess.py", line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'submodule']' returned non-zero exit status 1.
This is working on other PC's using the same Hooks file, so I think there is a access problem...
I have also tried
git.Repo('submodule').head.submodule.hexsha
without luck.
The Windows system PATH
and Git worktree seems to be correct. But I'm open to suggestion.
Using:
subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode()
on the parent folder to get the Commit-No of the project woks just fine.