I'm trying to use the subprocess
module to perform a git pull
operation in a repository. The problem is that other commands, such as git status
work fine, but the git pull
doesn't. No output is generated.
This is where I'm stuck:
import subprocess
subprocess.check_output(
['git', 'pull', 'origin', 'main']
)
When executed, the following error is thrown:
[WinError 6] The handle is invalid
I also used the os.chdir
and cwd
to change the dir context to the target repository, but it didn't work as expected:
import os
import subprocess
os.chdir(my_repository_dir)
subprocess.check_output(
['git', 'pull', 'origin', 'main'],
cwd=my_repository_dir
)
None of the following subprocess
methods worked: check_output
, check_call
, run
and Popen
. Either using the shell
attribute or not.
Furthermore, I reached the GitPython module, but it didn't work either.
My Python script runs on a Windows Server 2022, and the installed Python version is 3.6.8
. The git pull
instruction is evaluated when the exposed Flask
app handles an incoming HTTP request.
The target dir is a valid Git repository.
I've already included the SSH key on Gitlab, and the account credentials are stored in the Windows Credentials Manager.
If git pull
isn't intended to be invoked from scripts, I'd like to understand the proper way to do this.