Skip to content

Add way to get only topmost untracked folders/files #996

Description

@BeayemX

Let's say I have a new folder with three new files in it.

When I use git status it will show like this:

MyProject/New Folder/

But when I use GitPython's repo.untracked_files it will show like this:

MyProject/New Folder/file_a.txt
MyProject/New Folder/file_b.txt
MyProject/New Folder/file_c.txt

Is there a way to get the same result as the git status version?

Activity

  1. Byron commented on Mar 8, 2020

    @Byron
    Member

    Indeed it would be nice to have additional options to make GitPython more like 'porcelain', and less like the 'plumbing' it was intended to be.

    The recommended action is to transform the returned set of untracked files into the form that Git provides. This algorithm could potentially be donated back to GitPython, which supports it using an additional function, maybe along the line of repo.status.

    Thanks for understanding that GitPython is in maintenance mode and thus is hesitant to take on feature requests unless they are accompanied by a PR implementing them.

    Please feel free to comment on the closed issue if there are any follow-up questions.

  2. BeayemX commented on Mar 8, 2020

    @BeayemX
    ContributorAuthor

    Hello, thanks for the response.

    For the time being I Implemented a workaround that calls git directly.
    I am not sure if this is useful for you, but here is the code:

    import subprocess
    command = ["git", "ls-files", "--others", "--directory", "--exclude-standard", "--no-empty-directory"]
    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    untracked_files_and_folders = [u.decode().strip() for u in process.stdout]
    
  3. reopened this on Feb 26, 2021
  4. locked and limited conversation to collaborators on Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions