When I run
proc = subprocess.Popen(['git', 'add', '-A'], stdout=subprocess.PIPE)
I get this error
fatal: not a git repository (or any parent up to mount point /media)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
But running
os.system('git add -A')
Does the job perfectly.
If you think the folder does not have a .git
file,
proc = subprocess.Popen(['ls', '-a'], stdout=subprocess.PIPE)
shows that it is already in the cwd.
Why Popen
cannot stage the files, nor can it do the commit while os.system
does both?
Update:
Here is my failed MWE
import subprocess
import os
cwd = os.getcwd()
proj_path = os.path.join(cwd, 'newproj')
os.makedirs(proj_path)
os.chdir(proj_path)
proc = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE)
proc = subprocess.Popen(['ls', '-a'], stdout=subprocess.PIPE)
print(proc.stdout.read().decode('ascii'))
proc = subprocess.Popen(['git', 'add', '-A'], stdout=subprocess.PIPE)
out, err = proc.communicate()
if err:
print('Error:\n', err.decode())
print(out.decode('ascii'))
output
.
..
.git
fatal: not a git repository (or any parent up to mount point /media)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).