Alexandre
Alexandre

Reputation: 97

How to get the files that were changed, added or modified in the repository directory

Is it possible to get all the changed/added/removed files from a repository, and then stage those files? If yes, how?

I was doing something like this:

foreach (string file in Directory.GetFiles("dir/repo", "*", SearchOption.AllDirectories))
{
    repo.Stage(file);
}

However, it does not satisfy me because I stage all of the untracked files. But I want to stage all of the modified/added/deleted files.

Upvotes: 2

Views: 1611

Answers (2)

nulltoken
nulltoken

Reputation: 67589

Is it possible to get all the changed/added/removed files from a repository, and then stage those files? If yes, how?

"Use the wildcard, Luke!" ;-)

repo.Stage("*") will mimic git add --all (from git documentation: "Update the index not only where the working tree has a file matching but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree.")

See CanMimicGitAddAll() test from IndexFixture.cs for some additional insights.

Upvotes: 2

Can Baycay
Can Baycay

Reputation: 875

You can use git command line tools to get lists of changed/added/removed files. Just Google it and you will find plenty of resources.

Take a look at how to run a command line tool and get the output as a string:

How To: Execute command line in C#, get STD OUT results

I think that's all you need.

Upvotes: -1

Related Questions