Skip to content

untracked_files no longer detected #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
maxyz opened this issue Feb 23, 2014 · 8 comments
Closed

untracked_files no longer detected #138

maxyz opened this issue Feb 23, 2014 · 8 comments
Assignees

Comments

@maxyz
Copy link
Contributor

maxyz commented Feb 23, 2014

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
@joshvillbrandt
Copy link

+1 for a fix!

@marknorgren
Copy link

Is this patch currently in a release?

@Byron
Copy link
Member

Byron commented May 6, 2014

I don' think so. However, if there would be a pull request for the patch, I would merge it rather quickly.
From there it will be some time to a new release on pypi though, as plenty of issues want fixing beforehand.

Thanks to pip, it's easy though to fetch releases directly from github, which should be an option for you.

maxyz added a commit to maxyz/GitPython that referenced this issue May 6, 2014
maxyz added a commit to maxyz/GitPython that referenced this issue May 6, 2014
Byron added a commit that referenced this issue May 6, 2014
Fix for untracked_files no longer detected #138
@maxyz
Copy link
Contributor Author

maxyz commented May 6, 2014

I've just added two pull requests for this issue, one for the 0.3 branch and the other for the master branch. I'm not sure if that's the expected way to submit the pull requests, please tell if I just submit them in any other form.

Byron added a commit that referenced this issue May 6, 2014
Fix for untracked_files no longer detected #138
@Byron
Copy link
Member

Byron commented May 6, 2014

Thanks for your contribution, and for going the extra mile of merging it into master as well.

Would you be interested in bringing some other pull requests into 0.3 as well ? For some reason, I felt the urge to convert the project from tabs to spaces a few months ago, which is why most of the existing pull requests don't merge anymore.

The goal is to merge as much as possible, and then fix the unit-tests. For the latter, I have a strong incentive to do so.

To facilitate this, I would be glad to make you a contributor with full write access to the git-python repository.

Please let me know what you think.

@Utumno
Copy link

Utumno commented Sep 19, 2014

I think this breaks the Repo.is_dirty(untracked_files=True) too ?

@maxyz
Copy link
Contributor Author

maxyz commented Oct 1, 2014

¡Hola Sebastian!

Sorry for the delay.

El 2014-05-06 a las 03:32 -0700, Sebastian Thiel escribió:

Thanks for your contribution, and for going the extra mile of merging it into
master as well.

Thanks to you for developing and maintaining this project.

Would you be interested in bringing some other pull requests into 0.3 as well?

Yes, I could probably do this. I've been playing a bit with
https://github.com/sociomantic/git-hub that sort of helps with this. And
upgraded some old pull requests with it (#192, #193 and #194).

Please let me know if updating the pull requests this was is good enough for
you.

To facilitate this, I would be glad to make you a contributor with full write
access to the git-python repository.

Please let me know what you think.

I'll be glad to have commit access, but I'll still bother you about which
pull requests should be pushed till I'm confident enough with the codebase.

Happy hacking,

"If a thing is done wrong often enough, it becomes right" -- Leahy's Law
Saludos //\ /\ >< `/

@Byron Byron added this to the v0.3.5 - bugfixes milestone Nov 14, 2014
@Byron Byron self-assigned this Jan 7, 2015
@Byron
Copy link
Member

Byron commented Jan 7, 2015

As the patch was already merged, as there is a test-case, and as I manually verified this is working, I believe there is no reason to keep this one open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants