0

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    `git: 'submodule' is not a git command.` looks very suspiciously. Do you have multiple `git`s on your machine? Try `which git` on Git Bash and `subprocess.check_output(['where', 'git'])` on python. – psarka Mar 09 '22 at 09:26
  • In case `['where', 'git']` does not work, see this for some more ideas https://stackoverflow.com/questions/11928561/where-is-git-exe-located – psarka Mar 09 '22 at 09:29
  • Sounds like definitely a `PATH` problem if you are sure the tools are installed; but there is not enough information here to tell you how to fix it, or mark this as a duplicate of any particular question (which this almost certainly is, once you add more details). – tripleee Mar 09 '22 at 09:32
  • Bach:$ which git /mingw64/bin/git – Andreas Solheim Mar 09 '22 at 09:44
  • >>> import subprocess >>> subprocess.check_output(['where','git']) b'C:\\cygwin64\\bin\\git.exe\r\n' – Andreas Solheim Mar 09 '22 at 09:44
  • It looks like its using cygwins build in git. But I need cygwin, and I have tried to uninstall the git packet from cygwin, without lock apparently. Can I change which git the script or windows in general is using? – Andreas Solheim Mar 09 '22 at 09:47
  • Augment the `PATH` to put `/mingw64/bin` before `cygwin64\bin` – tripleee Mar 09 '22 at 09:50
  • Sorry, not a stellar duplicate; I'll see if I can find a better one still. – tripleee Mar 09 '22 at 09:55
  • thanks @tripleee, Augment the PATH worked :) – Andreas Solheim Mar 09 '22 at 10:22

0 Answers0