Python:致命:不是一个停止在文件系统边界的git存储库(未设置跨文件系统的git_发现)
当我跑的时候Python:致命:不是一个停止在文件系统边界的git存储库(未设置跨文件系统的git_发现),python,python-3.x,git,git-commit,python-3.8,Python,Python 3.x,Git,Git Commit,Python 3.8,当我跑的时候 proc = subprocess.Popen(['git', 'add', '-A'], stdout=subprocess.PIPE) 我得到这个错误 fatal: not a git repository (or any parent up to mount point /media) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). 但是跑步 os.system('git
proc = subprocess.Popen(['git', 'add', '-A'], stdout=subprocess.PIPE)
我得到这个错误
fatal: not a git repository (or any parent up to mount point /media)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
但是跑步
os.system('git add -A')
这工作做得很好
如果您认为该文件夹没有.git文件
显示它已在cwd中
为什么Popen不能暂存文件,也不能在os.system同时执行提交操作
更新:
这是我失败的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'))
输出
.
..
.git
fatal: not a git repository (or any parent up to mount point /media)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
我的Python版本稍微落后于您的版本,但我能够重现这个问题,实际上非常简单: proc=subprocess.Popen['git','init'],stdout=subprocess.PIPE proc=subprocess.Popen['ls','-a'],stdout=subprocess.PIPE printproc.stdout.read.decode'ascii' proc=subprocess.Popen['git','add','-A'],stdout=subprocess.PIPE 请注意,没有任何对proc.wait或类似程序的调用。这意味着我们可以派生一个git init,而不必等待它 接下来,我们运行ls-a。在这里,我们确实等待了足够长的时间,以便将其输出读取到EOF,这实际上是相对较长的,因为EOF只会发生,因为ls-a完成,同时git init仍在运行。根据git init的工作速度,我们可能在这里找到.git目录,也可能找不到。如果这需要足够长的时间,git init也可能完成。幸运的是,我的系统上的git init比ls-a慢得多,因此我看到了与您相同的效果。嗯,我发现.git目录有时还不存在 最后,我们运行git add-A。git init可能仍在运行,也可能尚未运行。事实证明,它仍然在运行,并且还没有足够的能力将.git目录建立为git存储库。所以GitAdd-A抱怨您观察到的错误
如果我们在git init之后添加proc.wait,理想情况下,我们应该检查返回代码,或者简单地使用subprocess.check_调用或subprocess.run,问题就会消失。我的Python版本比你的稍晚,但我能够重现问题,这实际上相当简单: proc=subprocess.Popen['git','init'],stdout=subprocess.PIPE proc=subprocess.Popen['ls','-a'],stdout=subprocess.PIPE printproc.stdout.read.decode'ascii' proc=subprocess.Popen['git','add','-A'],stdout=subprocess.PIPE 请注意,没有任何对proc.wait或类似程序的调用。这意味着我们可以派生一个git init,而不必等待它 接下来,我们运行ls-a。在这里,我们确实等待了足够长的时间,以便将其输出读取到EOF,这实际上是相对较长的,因为EOF只会发生,因为ls-a完成,同时git init仍在运行。根据git init的工作速度,我们可能在这里找到.git目录,也可能找不到。如果这需要足够长的时间,git init也可能完成。幸运的是,我的系统上的git init比ls-a慢得多,因此我看到了与您相同的效果。嗯,我发现.git目录有时还不存在 最后,我们运行git add-A。git init可能仍在运行,也可能尚未运行。事实证明,它仍然在运行,并且还没有足够的能力将.git目录建立为git存储库。所以GitAdd-A抱怨您观察到的错误
如果我们在git init之后添加proc.wait,理想情况下,我们应该检查返回代码,或者简单地使用subprocess.check\u调用或subprocess.run,问题就会消失。这有帮助吗@lesmana,如果cwd没有设置,那么ls-a怎么会在cwd上工作呢?那就是。。。古怪的“你有吗?”托雷克补充道,“我不知道这会有什么帮助。”。另一个问题类似于git-add不起作用。这是在黑暗中拍摄的。我无法再现你的问题,感到困惑。这是在添加最小工作示例之前。现在很明显,这是一个比赛条件。您必须通信或等待每个子流程。这有帮助吗@lesmana,如果cwd没有设置,那么ls-a怎么会在cwd上工作呢?那就是。。。古怪的“你有吗?”托雷克补充道,“我不知道这会有什么帮助。”。另一个问题类似于git-add不起作用。这是在黑暗中拍摄的。我无法再现你的问题,感到困惑。这是在添加最小工作示例之前。现在很明显,这是一个比赛条件。您必须通信或等待每个子流程。
.
..
.git
fatal: not a git repository (or any parent up to mount point /media)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).