Python: fatal: not a git repository Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)

mercury

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).
torek

My Python version is a little behind yours, but I was able to reproduce the problem, which is actually pretty simple:

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)

Note the lack of any calls to proc.wait() or similar. This means we spin off a git init and do not wait for it.

Next, we run ls -a. Here we do wait a little bit—long enough to read its output to EOF, which is actually relatively long as EOF only occurs because ls -a finishes—and meanwhile the git init is still running. Depending on how fast git init is doing its work, we may or may not find the .git directory here. If this takes long enough, the git init may also finish. Fortunately the git init on my system is sufficiently slower than the ls -a that I see the same effect as you. (Well, I found that the .git directory sometimes doesn't exist yet.)

Last, we run git add -A. The git init may or may not still be running. As it turns out, it is still running, and has not yet gotten far enough to establish the .git directory as a Git repository. So git add -A complains, with the error you observed.

If we add proc.wait() right after the git init—ideally, we should check the return code, or simply use subprocess.check_call or subprocess.run here—the problem goes away.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

git: fatal: Could not read from remote repository

From Java

Receiving "fatal: Not a git repository" when attempting to remote add a Git repo

From Java

Remove a file from a Git repository without deleting it from the local filesystem

From Java

Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository."

From Java

GIT_DISCOVERY_ACROSS_FILESYSTEM not set

From Dev

git Connection abandoned, fatal: Could not read from remote repository

From Dev

git fatal not a git repository (or any of the parent directories) .git

From Dev

Heroku - Fatal error when pushing to a git repository

From Dev

git clone --bare: fatal: repository does not exist

From Dev

fatal: Not a git repository when installing mod_python

From Dev

SourceTree - git: fatal: remote error: Repository not found

From Dev

How to run git hook script on windows, using repository through filesystem?

From Dev

fatal: Not a git repository: when adding files to git repo

From Dev

unable to look up https fatal error when push to git repository

From Dev

GIT: fatal: 'master' does not appear to be a git repository

From Dev

fatal: Not a git repository (or any of the parent directories): .git in Mac OS

From Dev

Redmine error log fatal:not a git repository

From Dev

fatal error: filesystem: No such file or directory

From Dev

Fatal: not a git repository - after BSoD

From Dev

fatal: Not a git repository (or any of the parent directories): .git (And yet the repository exists)

From Dev

Heroku - Fatal error when pushing to a git repository

From Dev

fatal: Not a git repository when installing mod_python

From Dev

CentOS: Git: "fatal: could not read from the remote repository"

From Dev

fatal: 'jigar/test.git' does not appear to be a git repository fatal: The remote end hung up unexpectedly

From Dev

Set filesystem encoding for python 3 on the Intel Edison

From Dev

Git fatal not valid : is this a git repository?

From Dev

Git: Permission denied (publickey). fatal: Could not read from remote repository

From Dev

fatal: Not a git repository (or any parent up to mount point /)

From Dev

Docker image git clone error "fatal: Not a git repository"

Related Related

  1. 1

    git: fatal: Could not read from remote repository

  2. 2

    Receiving "fatal: Not a git repository" when attempting to remote add a Git repo

  3. 3

    Remove a file from a Git repository without deleting it from the local filesystem

  4. 4

    Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository."

  5. 5

    GIT_DISCOVERY_ACROSS_FILESYSTEM not set

  6. 6

    git Connection abandoned, fatal: Could not read from remote repository

  7. 7

    git fatal not a git repository (or any of the parent directories) .git

  8. 8

    Heroku - Fatal error when pushing to a git repository

  9. 9

    git clone --bare: fatal: repository does not exist

  10. 10

    fatal: Not a git repository when installing mod_python

  11. 11

    SourceTree - git: fatal: remote error: Repository not found

  12. 12

    How to run git hook script on windows, using repository through filesystem?

  13. 13

    fatal: Not a git repository: when adding files to git repo

  14. 14

    unable to look up https fatal error when push to git repository

  15. 15

    GIT: fatal: 'master' does not appear to be a git repository

  16. 16

    fatal: Not a git repository (or any of the parent directories): .git in Mac OS

  17. 17

    Redmine error log fatal:not a git repository

  18. 18

    fatal error: filesystem: No such file or directory

  19. 19

    Fatal: not a git repository - after BSoD

  20. 20

    fatal: Not a git repository (or any of the parent directories): .git (And yet the repository exists)

  21. 21

    Heroku - Fatal error when pushing to a git repository

  22. 22

    fatal: Not a git repository when installing mod_python

  23. 23

    CentOS: Git: "fatal: could not read from the remote repository"

  24. 24

    fatal: 'jigar/test.git' does not appear to be a git repository fatal: The remote end hung up unexpectedly

  25. 25

    Set filesystem encoding for python 3 on the Intel Edison

  26. 26

    Git fatal not valid : is this a git repository?

  27. 27

    Git: Permission denied (publickey). fatal: Could not read from remote repository

  28. 28

    fatal: Not a git repository (or any parent up to mount point /)

  29. 29

    Docker image git clone error "fatal: Not a git repository"

HotTag

Archive