本文整理汇总了C#中NGit.Api.Git.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# Git.Commit方法的具体用法?C# Git.Commit怎么用?C# Git.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NGit.Api.Git
的用法示例。
在下文中一共展示了Git.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: FailingPathsShouldNotResultInOKReturnValue
public virtual void FailingPathsShouldNotResultInOKReturnValue()
{
FilePath folder1 = new FilePath(db.WorkTree, "folder1");
FileUtils.Mkdir(folder1);
FilePath file = new FilePath(folder1, "file1.txt");
Write(file, "folder1--file1.txt");
file = new FilePath(folder1, "file2.txt");
Write(file, "folder1--file2.txt");
Git git = new Git(db);
git.Add().AddFilepattern(folder1.GetName()).Call();
RevCommit @base = git.Commit().SetMessage("adding folder").Call();
RecursiveDelete(folder1);
git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
Call();
RevCommit other = git.Commit().SetMessage("removing folders on 'other'").Call();
git.Checkout().SetName(@base.Name).Call();
file = new FilePath(db.WorkTree, "unrelated.txt");
Write(file, "unrelated");
git.Add().AddFilepattern("unrelated").Call();
RevCommit head = git.Commit().SetMessage("Adding another file").Call();
// Untracked file to cause failing path for delete() of folder1
file = new FilePath(folder1, "file3.txt");
Write(file, "folder1--file3.txt");
ResolveMerger merger = new ResolveMerger(db, false);
merger.SetCommitNames(new string[] { "BASE", "HEAD", "other" });
merger.SetWorkingTreeIterator(new FileTreeIterator(db));
bool ok = merger.Merge(head.Id, other.Id);
NUnit.Framework.Assert.IsFalse(merger.GetFailingPaths().IsEmpty());
NUnit.Framework.Assert.IsFalse(ok);
}
示例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: ResolveUnnamedCurrentBranchCommits
public virtual void ResolveUnnamedCurrentBranchCommits()
{
Git git = new Git(db);
WriteTrashFile("file.txt", "content");
git.Add().AddFilepattern("file.txt").Call();
RevCommit c1 = git.Commit().SetMessage("create file").Call();
WriteTrashFile("file.txt", "content2");
git.Add().AddFilepattern("file.txt").Call();
RevCommit c2 = git.Commit().SetMessage("edit file").Call();
NUnit.Framework.Assert.AreEqual(c2, db.Resolve("[email protected]{0}"));
NUnit.Framework.Assert.AreEqual(c1, db.Resolve("[email protected]{1}"));
git.Checkout().SetCreateBranch(true).SetName("newbranch").SetStartPoint(c1).Call(
);
// same as current branch, e.g. master
NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{0}"));
try
{
NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{1}"));
NUnit.Framework.Assert.Fail();
}
catch (RevisionSyntaxException e)
{
// Looking at wrong ref, e.g HEAD
NUnit.Framework.Assert.IsNotNull(e);
}
// detached head, read HEAD reflog
git.Checkout().SetName(c2.GetName()).Call();
NUnit.Framework.Assert.AreEqual(c2, db.Resolve("@{0}"));
NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{1}"));
NUnit.Framework.Assert.AreEqual(c2, db.Resolve("@{2}"));
}
示例5: 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());
}
示例6: TestLastModifiedTimes
public virtual void TestLastModifiedTimes()
{
Git git = new Git(db);
string path = "file";
WriteTrashFile(path, "content");
string path2 = "file2";
WriteTrashFile(path2, "content2");
git.Add().AddFilepattern(path).Call();
git.Add().AddFilepattern(path2).Call();
git.Commit().SetMessage("commit").Call();
DirCache dc = db.ReadDirCache();
DirCacheEntry entry = dc.GetEntry(path);
DirCacheEntry entry2 = dc.GetEntry(path);
NUnit.Framework.Assert.IsTrue(entry.LastModified != 0, "last modified shall not be zero!"
);
NUnit.Framework.Assert.IsTrue(entry2.LastModified != 0, "last modified shall not be zero!"
);
WriteTrashFile(path, "new content");
git.Add().AddFilepattern(path).Call();
git.Commit().SetMessage("commit2").Call();
dc = db.ReadDirCache();
entry = dc.GetEntry(path);
entry2 = dc.GetEntry(path);
NUnit.Framework.Assert.IsTrue(entry.LastModified != 0, "last modified shall not be zero!"
);
NUnit.Framework.Assert.IsTrue(entry2.LastModified != 0, "last modified shall not be zero!"
);
}
示例7: TestTagging
public virtual void TestTagging()
{
Git git = new Git(db);
git.Commit().SetMessage("initial commit").Call();
RevCommit commit = git.Commit().SetMessage("second commit").Call();
git.Commit().SetMessage("third commit").Call();
RevTag tag = git.Tag().SetObjectId(commit).SetName("tag").Call();
NUnit.Framework.Assert.AreEqual(commit.Id, tag.GetObject().Id);
}
示例8: SetUp
public override void SetUp()
{
base.SetUp();
Git git = new Git(db);
git.Commit().SetMessage("initial commit").Call();
WriteTrashFile("Test.txt", "Hello world");
git.Add().AddFilepattern("Test.txt").Call();
git.Commit().SetMessage("Initial commit").Call();
bareRepo = Git.CloneRepository().SetBare(true).SetURI(db.Directory.ToURI().ToString
()).SetDirectory(CreateUniqueTestGitDir(true)).Call().GetRepository();
}
示例9: SetUp
public override void SetUp()
{
base.SetUp();
git = new Git(db);
// commit something
WriteTrashFile(FILE, "Hello world");
git.Add().AddFilepattern(FILE).Call();
commit1 = git.Commit().SetMessage("Initial commit").Call();
git.Rm().AddFilepattern(FILE).Call();
commit2 = git.Commit().SetMessage("Removed file").Call();
git.NotesAdd().SetObjectId(commit1).SetMessage("data").Call();
}
示例10: ResolveMasterCommits
public virtual void ResolveMasterCommits()
{
Git git = new Git(db);
WriteTrashFile("file.txt", "content");
git.Add().AddFilepattern("file.txt").Call();
RevCommit c1 = git.Commit().SetMessage("create file").Call();
WriteTrashFile("file.txt", "content2");
git.Add().AddFilepattern("file.txt").Call();
RevCommit c2 = git.Commit().SetMessage("edit file").Call();
NUnit.Framework.Assert.AreEqual(c2, db.Resolve("[email protected]{0}"));
NUnit.Framework.Assert.AreEqual(c1, db.Resolve("[email protected]{1}"));
}
示例11: TestAlreadyUpToDate
public virtual void TestAlreadyUpToDate()
{
Git git = new Git(db);
RevCommit first = git.Commit().SetMessage("initial commit").Call();
CreateBranch(first, "refs/heads/branch1");
RevCommit second = git.Commit().SetMessage("second commit").Call();
MergeCommandResult result = git.Merge().Include(db.GetRef("refs/heads/branch1")).
Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.ALREADY_UP_TO_DATE, result.GetMergeStatus
());
NUnit.Framework.Assert.AreEqual(second, result.GetNewHead());
}
示例12: SetupRepository
/// <exception cref="System.IO.IOException"></exception>
/// <exception cref="NGit.Api.Errors.NoFilepatternException"></exception>
/// <exception cref="NGit.Api.Errors.NoHeadException"></exception>
/// <exception cref="NGit.Api.Errors.NoMessageException"></exception>
/// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"></exception>
/// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
/// <exception cref="NGit.Api.Errors.WrongRepositoryStateException"></exception>
public virtual void SetupRepository()
{
// create initial commit
git = new Git(db);
initialCommit = git.Commit().SetMessage("initial commit").Call();
// create file
indexFile = new FilePath(db.WorkTree, "a.txt");
FileUtils.CreateNewFile(indexFile);
PrintWriter writer = new PrintWriter(indexFile);
writer.Write("content");
writer.Flush();
// add file and commit it
git.Add().AddFilepattern("a.txt").Call();
secondCommit = git.Commit().SetMessage("adding a.txt").Call();
prestage = DirCache.Read(db.GetIndexFile(), db.FileSystem).GetEntry(indexFile.GetName
());
// modify file and add to index
writer.Write("new content");
writer.Close();
git.Add().AddFilepattern("a.txt").Call();
// create a file not added to the index
untrackedFile = new FilePath(db.WorkTree, "notAddedToIndex.txt");
FileUtils.CreateNewFile(untrackedFile);
PrintWriter writer2 = new PrintWriter(untrackedFile);
writer2.Write("content");
writer2.Close();
}
示例13: TestPush
public virtual void TestPush()
{
// create other repository
Repository db2 = CreateWorkRepository();
// setup the first repository
StoredConfig config = ((FileBasedConfig)db.GetConfig());
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
URIish uri = new URIish(db2.Directory.ToURI().ToURL());
remoteConfig.AddURI(uri);
remoteConfig.Update(config);
config.Save();
Git git1 = new Git(db);
// create some refs via commits and tag
RevCommit commit = git1.Commit().SetMessage("initial commit").Call();
Ref tagRef = git1.Tag().SetName("tag").Call();
try
{
db2.Resolve(commit.Id.GetName() + "^{commit}");
NUnit.Framework.Assert.Fail("id shouldn't exist yet");
}
catch (MissingObjectException)
{
}
// we should get here
RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
git1.Push().SetRemote("test").SetRefSpecs(spec).Call();
NUnit.Framework.Assert.AreEqual(commit.Id, db2.Resolve(commit.Id.GetName() + "^{commit}"
));
NUnit.Framework.Assert.AreEqual(tagRef.GetObjectId(), db2.Resolve(tagRef.GetObjectId
().GetName()));
}
示例14: CommitAfterSquashMerge
public virtual void CommitAfterSquashMerge()
{
Git git = new Git(db);
WriteTrashFile("file1", "file1");
git.Add().AddFilepattern("file1").Call();
RevCommit first = git.Commit().SetMessage("initial commit").Call();
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
CreateBranch(first, "refs/heads/branch1");
CheckoutBranch("refs/heads/branch1");
WriteTrashFile("file2", "file2");
git.Add().AddFilepattern("file2").Call();
git.Commit().SetMessage("second commit").Call();
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
CheckoutBranch("refs/heads/master");
MergeCommandResult result = git.Merge().Include(db.GetRef("branch1")).SetSquash(true
).Call();
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
NUnit.Framework.Assert.AreEqual(MergeStatus.FAST_FORWARD_SQUASHED, result.GetMergeStatus
());
// comment not set, should be inferred from SQUASH_MSG
RevCommit squashedCommit = git.Commit().Call();
NUnit.Framework.Assert.AreEqual(1, squashedCommit.ParentCount);
NUnit.Framework.Assert.IsNull(db.ReadSquashCommitMsg());
NUnit.Framework.Assert.AreEqual("commit: Squashed commit of the following:", db.GetReflogReader
(Constants.HEAD).GetLastEntry().GetComment());
NUnit.Framework.Assert.AreEqual("commit: Squashed commit of the following:", db.GetReflogReader
(db.GetBranch()).GetLastEntry().GetComment());
}
示例15: TestAddUnstagedChanges
public virtual void TestAddUnstagedChanges()
{
FilePath file = new FilePath(db.WorkTree, "a.txt");
FileUtils.CreateNewFile(file);
PrintWriter writer = new PrintWriter(file);
writer.Write("content");
writer.Close();
Git git = new Git(db);
git.Add().AddFilepattern("a.txt").Call();
RevCommit commit = git.Commit().SetMessage("initial commit").Call();
TreeWalk tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", tw.GetObjectId
(0).GetName());
writer = new PrintWriter(file);
writer.Write("content2");
writer.Close();
commit = git.Commit().SetMessage("second commit").Call();
tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", tw.GetObjectId
(0).GetName());
commit = git.Commit().SetAll(true).SetMessage("third commit").SetAll(true).Call();
tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
NUnit.Framework.Assert.AreEqual("db00fd65b218578127ea51f3dffac701f12f486a", tw.GetObjectId
(0).GetName());
}