1
How to get the file path of my last commit? I have this example method:
private static void RepoListFiles()
{
if (!arguments.ContainsKey("repository"))
{
Error("O repositório ainda não foi informado.");
return;
}
using (repo)
{
if (repo.Head.Commits.Count() < 1)
{
Error("Nenhum Commit existente.");
return;
}
Commit commit = repo.Commits.First();
Tree tree = repo.Lookup<Commit>(commit.Sha).Tree;
Console.WriteLine("\nSha: " + commit.Sha);
if (commit.Author.Name != "Unknow") Console.WriteLine("Autor: " + commit.Author.Name);
if (commit.Committer.Name != "Unknow") Console.WriteLine("Commiter: " + commit.Committer.Name);
Console.WriteLine("Data: " + commit.Author.When); //Commit-Date
Console.WriteLine("Mensagem: " + commit.Message);
Console.WriteLine("---------------------------------");
arquivos = new List<string>();
GetFiles(tree);
/*foreach (TreeEntry treeEntry in tree)
{
Console.WriteLine("Path: " + treeEntry.Path);
Console.WriteLine("Name: " + treeEntry.Name);
Console.WriteLine("---------");
}*/
foreach (string file in arquivos)
{
Console.WriteLine(file);
}
Console.WriteLine("---------------------------------");
}
}
static void CompareTrees()
{
using (repo)
{
Tree commitTree = repo.Head.Tip.Tree;
Tree parentCommitTree = repo.Head.Tip.Parents.Single().Tree;
var changes = repo.Diff.Compare<TreeChanges>(parentCommitTree, commitTree);
TreeEntryChanges treeEntryChanges = changes.Single(c => c.Path == "1.txt");
var patch = repo.Diff.Compare<Patch>(parentCommitTree, commitTree);
}
}
Program:
But the exit doesn’t bring me all the way.
Structure of the directory
c:/teste
| - octocat.txt
| - parentoctocat.txt
| - /outros
| | - octocatblue.txt
| | - octored.txt
In my commit has only the files c:/teste/outros/octored.txt
and c:/teste/outros/octocatblue.txt
added.
But on output comes all the files.
How do I get only the files added to my commit:
/outros/octocatblue.txt
/outros/octored.txt
[Edited]
Note: I already managed to get the full path of the file. However I only need the files I added to commit as $ git add outros/octocatblue.txt
.
So man, I don’t know much about C#, this "Assert object" doesn’t have in my project, it must be something from their test. That
1.txt
is the file he’s comparing?– KaduAmaral
I updated my code and print there on the question. I couldn’t test this "example" because I didn’t understand it, I don’t know if this
1.txt
is the file being compared, or if it is the file from where it stores the result.– KaduAmaral
@Kaduamaral
Assert
is a set of sets for comparison. It is used to write unit tests.1.txt
is any file he has versioned and is checking for changes.– Leonel Sanches da Silva