Skip to content
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

Simplify getting dirty files in repository #2004

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

clyvari
Copy link

@clyvari clyvari commented Jan 7, 2023

A simple PR to help getting the dirty files in the repository.

Background: When getting a RepositoryStatus, we can use the IsDirty property to tell if the repository is dirty.
However, we don't have the same convenience to get the list of those dirty files.

Indeed, getting the actual list of dirty files would imply some duplicated logic in the client code, the same code that is present in the RepositoryStatus ctor to initialize the IsDirty prop.

What I propose is two parts (and 2 independent commits):

  1. Most importantly, we move the IsDirty detection inside a StatusEntry, by adding a property of the same name. Before, the detection was done inside the RepositoryStatus ctor, analyzing each StatusEntry FileStatus. Now each StatusEntry has the responsibility of telling whether it is dirty.

  2. Least importantly, but I think it's nice, we add a Dirty collection inside RepositoryStatus, that is initialized with all the IsDirty StatusEntries

Before thos changes, a client code working with dirty files could look like this:

if(repositoryStatus.IsDirty)
{
    var dirtyFiles = repositoryStatus
                         .Where(file => file.State != FileStatus.Ignored
                                     && file.State != FileStatus.Unaltered) // Duplicated Logic
}

With those two modifications, the client code would look like this:

if(repositoryStatus.IsDirty)
{
    var dirtyFiles = repositoryStatus.Dirty;
}

I appreciate any feedback, let me know if anything need to be changed.

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

Successfully merging this pull request may close these issues.

None yet

1 participant