Repository: gitpython-developers/GitPython

Issue #138: untracked_files no longer detected
Created: 2014-02-23T17:05:33Z
Hi,
The output of git status is no longer in the format expected by python-git, in
particular the Repo.untracked_files property parses the git status output
expecting a:
# Untracked files:

while later versions of git droped the #, also there are some subtleties in
the management of the file names (avoid the use of replace and rstrip
removes spaces not only '\n').
Here is a patch that fixes the untracked_files property. There might be other parts affected by the change in the git output.
diff -Naru python-git/git/repo/base.py python-git.new/git/repo/base.py
--- python-git/git/repo/base.py 2011-07-05 21:50:02.000000000 +0200
+++ python-git.new/git/repo/base.py 2014-02-23 17:54:32.157547255 +0100
@@ -512,35 +512,33 @@
                return True
        # END untracked files
        return False
-       
+
    @property
    def untracked_files(self):
        """
        :return:
            list(str,...)
-           
+
            Files currently untracked as they have not been staged yet. Paths 
            are relative to the current working directory of the git command.
-           
+
        :note:
            ignored files will not appear here, i.e. files mentioned in .gitignore"""
        # make sure we get all files, no only untracked directores
-       proc = self.git.status(untracked_files=True, as_process=True)
-       stream = iter(proc.stdout)
+       proc = self.git.status(porcelain=True,
+           untracked_files=True,
+           as_process=True)
+       # Untracked files preffix in porcelain mode
+       preffix = "?? "
        untracked_files = list()
-       for line in stream:
-           if not line.startswith("# Untracked files:"):
+       for line in proc.stdout:
+           if not line.startswith(preffix):
                continue
-           # skip two lines
-           stream.next()
-           stream.next()
-           
-           for untracked_info in stream:
-               if not untracked_info.startswith("#\t"):
-                   break
-               untracked_files.append(untracked_info.replace("#\t", "").rstrip())
-           # END for each utracked info line
-       # END for each line
+                        filename = line[len(preffix):].rstrip('\n')
+                        # Special characters are escaped
+                        if filename[0] == filename[-1] == '"':
+                            filename = filename[1:-1].decode('string_escape')
+           untracked_files.append(filename)
        return untracked_files

    @property

Duplicate issue #247: Problem with getting untracked files
Created: 2015-01-27T15:27:42Z
On my Fedora 21 I have installed those packages:
$ rpm -q GitPython
GitPython-0.3.2-0.7.RC1.fc21.noarch
$ rpm -q git
git-2.1.0-4.fc21.x86_64
If I call repo.untracked_files then list is empty.
Unfortunatelly git status returns me:

Untracked files:
(use "git add ..." to include in what will be committed)
.gitignore
COPYING
Makefile
README
README.lnstat
bridge/
configure
doc/


As you can see as untracked files as alone files do not begins with #.
https://github.com/gitpython-developers/GitPython/blob/master/git/repo/base.py#L592

Closing comment (2015-01-27T16:09:33Z): The issue you describe seems to be related to #138 , which was indeed present in the version you are using.
However, it has been fixed in the meanwhile, and I recommend installing the latest version using pip.
Please let me know if that worked for you, so I can close this ticket.
Thanks