本文整理汇总了C#中NGit.Api.Git.Log方法的典型用法代码示例。如果您正苦于以下问题:C# Git.Log方法的具体用法?C# Git.Log怎么用?C# Git.Log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NGit.Api.Git
的用法示例。
在下文中一共展示了Git.Log方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRevert
public virtual void TestRevert()
{
Git git = new Git(db);
WriteTrashFile("a", "first line\nsec. line\nthird line\n");
git.Add().AddFilepattern("a").Call();
git.Commit().SetMessage("create a").Call();
WriteTrashFile("b", "content\n");
git.Add().AddFilepattern("b").Call();
git.Commit().SetMessage("create b").Call();
WriteTrashFile("a", "first line\nsec. line\nthird line\nfourth line\n");
git.Add().AddFilepattern("a").Call();
git.Commit().SetMessage("enlarged a").Call();
WriteTrashFile("a", "first line\nsecond line\nthird line\nfourth line\n");
git.Add().AddFilepattern("a").Call();
RevCommit fixingA = git.Commit().SetMessage("fixed a").Call();
WriteTrashFile("b", "first line\n");
git.Add().AddFilepattern("b").Call();
git.Commit().SetMessage("fixed b").Call();
git.Revert().Include(fixingA).Call();
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "b").Exists());
CheckFile(new FilePath(db.WorkTree, "a"), "first line\nsec. line\nthird line\nfourth line\n"
);
Iterator<RevCommit> history = git.Log().Call().Iterator();
RevCommit revertCommit = history.Next();
string expectedMessage = "Revert \"fixed a\"\n\n" + "This reverts commit " + fixingA
.Id.GetName() + ".\n";
NUnit.Framework.Assert.AreEqual(expectedMessage, revertCommit.GetFullMessage());
NUnit.Framework.Assert.AreEqual("fixed b", history.Next().GetFullMessage());
NUnit.Framework.Assert.AreEqual("fixed a", history.Next().GetFullMessage());
NUnit.Framework.Assert.AreEqual("enlarged a", history.Next().GetFullMessage());
NUnit.Framework.Assert.AreEqual("create b", history.Next().GetFullMessage());
NUnit.Framework.Assert.AreEqual("create a", history.Next().GetFullMessage());
NUnit.Framework.Assert.IsFalse(history.HasNext());
}
示例2: TestCherryPick
public virtual void TestCherryPick()
{
Git git = new Git(db);
WriteTrashFile("a", "first line\nsec. line\nthird line\n");
git.Add().AddFilepattern("a").Call();
RevCommit firstCommit = git.Commit().SetMessage("create a").Call();
WriteTrashFile("b", "content\n");
git.Add().AddFilepattern("b").Call();
git.Commit().SetMessage("create b").Call();
WriteTrashFile("a", "first line\nsec. line\nthird line\nfourth line\n");
git.Add().AddFilepattern("a").Call();
git.Commit().SetMessage("enlarged a").Call();
WriteTrashFile("a", "first line\nsecond line\nthird line\nfourth line\n");
git.Add().AddFilepattern("a").Call();
RevCommit fixingA = git.Commit().SetMessage("fixed a").Call();
git.BranchCreate().SetName("side").SetStartPoint(firstCommit).Call();
CheckoutBranch("refs/heads/side");
WriteTrashFile("a", "first line\nsec. line\nthird line\nfeature++\n");
git.Add().AddFilepattern("a").Call();
git.Commit().SetMessage("enhanced a").Call();
git.CherryPick().Include(fixingA).Call();
NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists());
CheckFile(new FilePath(db.WorkTree, "a"), "first line\nsecond line\nthird line\nfeature++\n"
);
Iterator<RevCommit> history = git.Log().Call().Iterator();
NUnit.Framework.Assert.AreEqual("fixed a", history.Next().GetFullMessage());
NUnit.Framework.Assert.AreEqual("enhanced a", history.Next().GetFullMessage());
NUnit.Framework.Assert.AreEqual("create a", history.Next().GetFullMessage());
NUnit.Framework.Assert.IsFalse(history.HasNext());
}
示例3: TestSomeCommits
public virtual void TestSomeCommits()
{
// do 4 commits
Git git = new Git(db);
git.Commit().SetMessage("initial commit").Call();
git.Commit().SetMessage("second commit").SetCommitter(committer).Call();
git.Commit().SetMessage("third commit").SetAuthor(author).Call();
git.Commit().SetMessage("fourth commit").SetAuthor(author).SetCommitter(committer
).Call();
Iterable<RevCommit> commits = git.Log().Call();
// check that all commits came in correctly
PersonIdent defaultCommitter = new PersonIdent(db);
PersonIdent[] expectedAuthors = new PersonIdent[] { defaultCommitter, committer,
author, author };
PersonIdent[] expectedCommitters = new PersonIdent[] { defaultCommitter, committer
, defaultCommitter, committer };
string[] expectedMessages = new string[] { "initial commit", "second commit", "third commit"
, "fourth commit" };
int l = expectedAuthors.Length - 1;
foreach (RevCommit c in commits)
{
NUnit.Framework.Assert.AreEqual(expectedAuthors[l].GetName(), c.GetAuthorIdent().
GetName());
NUnit.Framework.Assert.AreEqual(expectedCommitters[l].GetName(), c.GetCommitterIdent
().GetName());
NUnit.Framework.Assert.AreEqual(c.GetFullMessage(), expectedMessages[l]);
l--;
}
NUnit.Framework.Assert.AreEqual(l, -1);
ReflogReader reader = db.GetReflogReader(Constants.HEAD);
NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("commit:"
));
}
示例4: TestMultipleInvocations
public virtual void TestMultipleInvocations()
{
Git git = new Git(db);
CommitCommand commitCmd = git.Commit();
commitCmd.SetMessage("initial commit").Call();
try
{
// check that setters can't be called after invocation
commitCmd.SetAuthor(author);
NUnit.Framework.Assert.Fail("didn't catch the expected exception");
}
catch (InvalidOperationException)
{
}
// expected
LogCommand logCmd = git.Log();
logCmd.Call();
try
{
// check that call can't be called twice
logCmd.Call();
NUnit.Framework.Assert.Fail("didn't catch the expected exception");
}
catch (InvalidOperationException)
{
}
}
示例5: TestLogWithFilter
public virtual void TestLogWithFilter()
{
Git git = new Git(db);
// create first file
FilePath file = new FilePath(db.WorkTree, "a.txt");
FileUtils.CreateNewFile(file);
PrintWriter writer = new PrintWriter(file);
writer.Write("content1");
writer.Close();
// First commit - a.txt file
git.Add().AddFilepattern("a.txt").Call();
git.Commit().SetMessage("commit1").SetCommitter(committer).Call();
// create second file
file = new FilePath(db.WorkTree, "b.txt");
FileUtils.CreateNewFile(file);
writer = new PrintWriter(file);
writer.Write("content2");
writer.Close();
// Second commit - b.txt file
git.Add().AddFilepattern("b.txt").Call();
git.Commit().SetMessage("commit2").SetCommitter(committer).Call();
// First log - a.txt filter
int count = 0;
foreach (RevCommit c in git.Log().AddPath("a.txt").Call())
{
NUnit.Framework.Assert.AreEqual("commit1", c.GetFullMessage());
count++;
}
NUnit.Framework.Assert.AreEqual(1, count);
// Second log - b.txt filter
count = 0;
foreach (RevCommit c_1 in git.Log().AddPath("b.txt").Call())
{
NUnit.Framework.Assert.AreEqual("commit2", c_1.GetFullMessage());
count++;
}
NUnit.Framework.Assert.AreEqual(1, count);
// Third log - without filter
count = 0;
foreach (RevCommit c_2 in git.Log().Call())
{
NUnit.Framework.Assert.AreEqual(committer, c_2.GetCommitterIdent());
count++;
}
NUnit.Framework.Assert.AreEqual(2, count);
}
示例6: TestCommitRange
public virtual void TestCommitRange()
{
// do 4 commits and set the range to the second and fourth one
Git git = new Git(db);
git.Commit().SetMessage("first commit").Call();
RevCommit second = git.Commit().SetMessage("second commit").SetCommitter(committer
).Call();
git.Commit().SetMessage("third commit").SetAuthor(author).Call();
RevCommit last = git.Commit().SetMessage("fourth commit").SetAuthor(author).SetCommitter
(committer).Call();
Iterable<RevCommit> commits = git.Log().AddRange(second.Id, last.Id).Call();
// check that we have the third and fourth commit
PersonIdent defaultCommitter = new PersonIdent(db);
PersonIdent[] expectedAuthors = new PersonIdent[] { author, author };
PersonIdent[] expectedCommitters = new PersonIdent[] { defaultCommitter, committer
};
string[] expectedMessages = new string[] { "third commit", "fourth commit" };
int l = expectedAuthors.Length - 1;
foreach (RevCommit c in commits)
{
NUnit.Framework.Assert.AreEqual(expectedAuthors[l].GetName(), c.GetAuthorIdent().
GetName());
NUnit.Framework.Assert.AreEqual(expectedCommitters[l].GetName(), c.GetCommitterIdent
().GetName());
NUnit.Framework.Assert.AreEqual(c.GetFullMessage(), expectedMessages[l]);
l--;
}
NUnit.Framework.Assert.AreEqual(l, -1);
}
示例7: TestCommitAmend
public virtual void TestCommitAmend()
{
Git git = new Git(db);
git.Commit().SetMessage("first comit").Call();
// typo
git.Commit().SetAmend(true).SetMessage("first commit").Call();
Iterable<RevCommit> commits = git.Log().Call();
int c = 0;
foreach (RevCommit commit in commits)
{
NUnit.Framework.Assert.AreEqual("first commit", commit.GetFullMessage());
c++;
}
NUnit.Framework.Assert.AreEqual(1, c);
ReflogReader reader = db.GetReflogReader(Constants.HEAD);
NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("commit (amend):"
));
reader = db.GetReflogReader(db.GetBranch());
NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("commit (amend):"
));
}
示例8: TestSuccessfulContentMergeAndDirtyworkingTree
public virtual void TestSuccessfulContentMergeAndDirtyworkingTree()
{
Git git = new Git(db);
WriteTrashFile("a", "1\na\n3\n");
WriteTrashFile("b", "1\nb\n3\n");
WriteTrashFile("d", "1\nd\n3\n");
WriteTrashFile("c/c/c", "1\nc\n3\n");
git.Add().AddFilepattern("a").AddFilepattern("b").AddFilepattern("c/c/c").AddFilepattern
("d").Call();
RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
CreateBranch(initialCommit, "refs/heads/side");
CheckoutBranch("refs/heads/side");
WriteTrashFile("a", "1(side)\na\n3\n");
WriteTrashFile("b", "1\nb(side)\n3\n");
git.Add().AddFilepattern("a").AddFilepattern("b").Call();
RevCommit secondCommit = git.Commit().SetMessage("side").Call();
NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree,
"b")));
CheckoutBranch("refs/heads/master");
NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b"))
);
WriteTrashFile("a", "1\na\n3(main)\n");
WriteTrashFile("c/c/c", "1\nc(main)\n3\n");
git.Add().AddFilepattern("a").AddFilepattern("c/c/c").Call();
RevCommit thirdCommit = git.Commit().SetMessage("main").Call();
WriteTrashFile("d", "--- dirty ---");
MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
.RESOLVE).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
NUnit.Framework.Assert.AreEqual("1(side)\na\n3(main)\n", Read(new FilePath(db.WorkTree
, "a")));
NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree,
"b")));
NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree,
"c/c/c")));
NUnit.Framework.Assert.AreEqual("--- dirty ---", Read(new FilePath(db.WorkTree, "d"
)));
NUnit.Framework.Assert.AreEqual(null, result.GetConflicts());
NUnit.Framework.Assert.IsTrue(2 == result.GetMergedCommits().Length);
NUnit.Framework.Assert.AreEqual(thirdCommit, result.GetMergedCommits()[0]);
NUnit.Framework.Assert.AreEqual(secondCommit, result.GetMergedCommits()[1]);
Iterator<RevCommit> it = git.Log().Call().Iterator();
RevCommit newHead = it.Next();
NUnit.Framework.Assert.AreEqual(newHead, result.GetNewHead());
NUnit.Framework.Assert.AreEqual(2, newHead.ParentCount);
NUnit.Framework.Assert.AreEqual(thirdCommit, newHead.GetParent(0));
NUnit.Framework.Assert.AreEqual(secondCommit, newHead.GetParent(1));
NUnit.Framework.Assert.AreEqual("Merge commit '064d54d98a4cdb0fed1802a21c656bfda67fe879'"
, newHead.GetFullMessage());
NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
}
示例9: TestSuccessfulContentMerge
public virtual void TestSuccessfulContentMerge()
{
Git git = new Git(db);
WriteTrashFile("a", "1\na\n3\n");
WriteTrashFile("b", "1\nb\n3\n");
WriteTrashFile("c/c/c", "1\nc\n3\n");
git.Add().AddFilepattern("a").AddFilepattern("b").AddFilepattern("c/c/c").Call();
RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
CreateBranch(initialCommit, "refs/heads/side");
CheckoutBranch("refs/heads/side");
WriteTrashFile("a", "1(side)\na\n3\n");
WriteTrashFile("b", "1\nb(side)\n3\n");
git.Add().AddFilepattern("a").AddFilepattern("b").Call();
RevCommit secondCommit = git.Commit().SetMessage("side").Call();
NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree,
"b")));
CheckoutBranch("refs/heads/master");
NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b"))
);
WriteTrashFile("a", "1\na\n3(main)\n");
WriteTrashFile("c/c/c", "1\nc(main)\n3\n");
git.Add().AddFilepattern("a").AddFilepattern("c/c/c").Call();
RevCommit thirdCommit = git.Commit().SetMessage("main").Call();
MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
.RESOLVE).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
NUnit.Framework.Assert.AreEqual("1(side)\na\n3(main)\n", Read(new FilePath(db.WorkTree
, "a")));
NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree,
"b")));
NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree,
"c/c/c")));
NUnit.Framework.Assert.AreEqual(null, result.GetConflicts());
NUnit.Framework.Assert.AreEqual(2, result.GetMergedCommits().Length);
NUnit.Framework.Assert.AreEqual(thirdCommit, result.GetMergedCommits()[0]);
NUnit.Framework.Assert.AreEqual(secondCommit, result.GetMergedCommits()[1]);
Iterator<RevCommit> it = git.Log().Call().Iterator();
RevCommit newHead = it.Next();
NUnit.Framework.Assert.AreEqual(newHead, result.GetNewHead());
NUnit.Framework.Assert.AreEqual(2, newHead.ParentCount);
NUnit.Framework.Assert.AreEqual(thirdCommit, newHead.GetParent(0));
NUnit.Framework.Assert.AreEqual(secondCommit, newHead.GetParent(1));
NUnit.Framework.Assert.AreEqual("Merge commit '3fa334456d236a92db020289fe0bf481d91777b4'"
, newHead.GetFullMessage());
// @TODO fix me
NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
}
示例10: TestCommitAmend
public virtual void TestCommitAmend()
{
Git git = new Git(db);
git.Commit().SetMessage("first comit").Call();
// typo
git.Commit().SetAmend(true).SetMessage("first commit").Call();
Iterable<RevCommit> commits = git.Log().Call();
int c = 0;
foreach (RevCommit commit in commits)
{
NUnit.Framework.Assert.AreEqual("first commit", commit.GetFullMessage());
c++;
}
NUnit.Framework.Assert.AreEqual(1, c);
}
示例11: ConvertFileInfoToElement
Element ConvertFileInfoToElement(Git git, string project, FileInfo fileInfo)
{
var element = new Element
{
Name = Path.GetFileNameWithoutExtension(fileInfo.Name),
File = GetRelativePathForFile(project, fileInfo),
Author = "Unknown",
LastChanged = "Unknown"
};
var logCommand = git.Log ();
logCommand.AddPath (element.File);
var result = logCommand.Call ();
var commit = result.FirstOrDefault();
if( commit != null )
{
element.Author = commit.GetCommitterIdent().GetName();
}
return element;
}