本文整理汇总了C#中NGit.Api.Git类的典型用法代码示例。如果您正苦于以下问题:C# Git类的具体用法?C# Git怎么用?C# Git使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Git类属于NGit.Api命名空间,在下文中一共展示了Git类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IdOffset
public virtual void IdOffset()
{
Git git = new Git(db);
WriteTrashFile("fileAinfsonly", "A");
FilePath fileBinindex = WriteTrashFile("fileBinindex", "B");
FsTick(fileBinindex);
git.Add().AddFilepattern("fileBinindex").Call();
WriteTrashFile("fileCinfsonly", "C");
TreeWalk tw = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
tw.AddTree(indexIter);
tw.AddTree(workTreeIter);
workTreeIter.SetDirCacheIterator(tw, 0);
AssertEntry("d46c305e85b630558ee19cc47e73d2e5c8c64cdc", "a,", tw);
AssertEntry("58ee403f98538ec02409538b3f80adf610accdec", "a,b", tw);
AssertEntry("0000000000000000000000000000000000000000", "a", tw);
AssertEntry("b8d30ff397626f0f1d3538d66067edf865e201d6", "a0b", tw);
// The reason for adding this test. Check that the id is correct for
// mixed
AssertEntry("8c7e5a667f1b771847fe88c01c3de34413a1b220", "fileAinfsonly", tw);
AssertEntry("7371f47a6f8bd23a8fa1a8b2a9479cdd76380e54", "fileBinindex", tw);
AssertEntry("96d80cd6c4e7158dbebd0849f4fb7ce513e5828c", "fileCinfsonly", tw);
NUnit.Framework.Assert.IsFalse(tw.Next());
}
示例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: TestConflictingMergeFailsDueToDirtyIndex
public virtual void TestConflictingMergeFailsDueToDirtyIndex()
{
Git git = new Git(db);
FilePath fileA = WriteTrashFile("a", "a");
RevCommit initialCommit = AddAllAndCommit(git);
// switch branch
CreateBranch(initialCommit, "refs/heads/side");
CheckoutBranch("refs/heads/side");
// modify file a
Write(fileA, "a(side)");
WriteTrashFile("b", "b");
RevCommit sideCommit = AddAllAndCommit(git);
// switch branch
CheckoutBranch("refs/heads/master");
// modify file a - this will cause a conflict during merge
Write(fileA, "a(master)");
WriteTrashFile("c", "c");
AddAllAndCommit(git);
// modify and add file a
Write(fileA, "a(modified)");
git.Add().AddFilepattern("a").Call();
// do not commit
// get current index state
string indexState = IndexState(CONTENT);
// merge
MergeCommandResult result = git.Merge().Include(sideCommit.Id).SetStrategy(MergeStrategy
.RESOLVE).Call();
CheckMergeFailedResult(result, ResolveMerger.MergeFailureReason.DIRTY_INDEX, indexState
, fileA);
}
示例5: 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!"
);
}
示例6: 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()));
}
示例7: NGitTransaction
internal NGitTransaction(string path)
{
_path = path;
_git = Git.Open(path);
Clean();
}
示例8: 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();
}
示例9: 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}"));
}
示例10: TestTaggingOnHead
public virtual void TestTaggingOnHead()
{
Git git = new Git(db);
RevCommit commit = git.Commit().SetMessage("initial commit").Call();
RevTag tag = git.Tag().SetName("tag").Call();
NUnit.Framework.Assert.AreEqual(commit.Id, tag.GetObject().Id);
}
示例11: Pull
public ICommandResponse Pull (string path, string destPath)
{
var git = new Git(new FileRepository(ToGitDirString(path)));
var pullCommand = git.Pull();
ICommandResponse result = new NGitPullResultAdapter(pullCommand);
return result;
}
示例12: SetUp
public override void SetUp()
{
base.SetUp();
dbTarget = CreateWorkRepository();
source = new Git(db);
target = new Git(dbTarget);
// put some file in the source repo
sourceFile = new FilePath(db.WorkTree, "SomeFile.txt");
WriteToFile(sourceFile, "Hello world");
// and commit it
source.Add().AddFilepattern("SomeFile.txt").Call();
source.Commit().SetMessage("Initial commit for source").Call();
// configure the target repo to connect to the source via "origin"
StoredConfig targetConfig = ((FileBasedConfig)dbTarget.GetConfig());
targetConfig.SetString("branch", "master", "remote", "origin");
targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
RemoteConfig config = new RemoteConfig(targetConfig, "origin");
config.AddURI(new URIish(source.GetRepository().WorkTree.GetPath()));
config.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
config.Update(targetConfig);
targetConfig.Save();
targetFile = new FilePath(dbTarget.WorkTree, "SomeFile.txt");
// make sure we have the same content
target.Pull().Call();
target.Checkout().SetStartPoint("refs/remotes/origin/master").SetName("master").Call
();
targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
targetConfig.SetBoolean("branch", "master", "rebase", true);
targetConfig.Save();
AssertFileContentsEqual(targetFile, "Hello world");
}
示例13: 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());
}
示例14: 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());
}
示例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());
}