本文整理汇总了C#中NGit.Api.Git.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# Git.Merge方法的具体用法?C# Git.Merge怎么用?C# Git.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NGit.Api.Git
的用法示例。
在下文中一共展示了Git.Merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMergeInItself
public virtual void TestMergeInItself()
{
Git git = new Git(db);
git.Commit().SetMessage("initial commit").Call();
MergeCommandResult result = git.Merge().Include(db.GetRef(Constants.HEAD)).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.ALREADY_UP_TO_DATE, result.GetMergeStatus
());
}
示例2: 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());
}
示例3: TestMergeInItself
public virtual void TestMergeInItself()
{
Git git = new Git(db);
git.Commit().SetMessage("initial commit").Call();
MergeCommandResult result = git.Merge().Include(db.GetRef(Constants.HEAD)).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.ALREADY_UP_TO_DATE, result.GetMergeStatus
());
// no reflog entry written by merge
NUnit.Framework.Assert.AreEqual("commit: initial commit", db.GetReflogReader(Constants
.HEAD).GetLastEntry().GetComment());
NUnit.Framework.Assert.AreEqual("commit: initial commit", db.GetReflogReader(db.GetBranch
()).GetLastEntry().GetComment());
}
示例4: TestSquashMergeConflict
public virtual void TestSquashMergeConflict()
{
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");
WriteTrashFile("file2", "master");
git.Add().AddFilepattern("file2").Call();
RevCommit second = git.Commit().SetMessage("second commit").Call();
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
CheckoutBranch("refs/heads/branch1");
WriteTrashFile("file2", "branch");
git.Add().AddFilepattern("file2").Call();
RevCommit third = git.Commit().SetMessage("third commit").Call();
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
CheckoutBranch("refs/heads/master");
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
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.CONFLICTING, result.GetMergeStatus());
NUnit.Framework.Assert.IsNull(result.GetNewHead());
NUnit.Framework.Assert.AreEqual(second, db.Resolve(Constants.HEAD + "^{commit}"));
NUnit.Framework.Assert.AreEqual("Squashed commit of the following:\n\ncommit " +
third.GetName() + "\nAuthor: " + third.GetAuthorIdent().GetName() + " <" + third
.GetAuthorIdent().GetEmailAddress() + ">\nDate: " + dateFormatter.FormatDate(third
.GetAuthorIdent()) + "\n\n\tthird commit\n", db.ReadSquashCommitMsg());
NUnit.Framework.Assert.AreEqual("\nConflicts:\n\tfile2\n", db.ReadMergeCommitMsg(
));
Status stat = git.Status().Call();
NUnit.Framework.CollectionAssert.AreEquivalent(StatusCommandTest.Set("file2"), stat.GetConflicting
());
}
示例5: TestSingleDeletion
public virtual void TestSingleDeletion()
{
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");
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "b").Delete());
git.Add().AddFilepattern("b").SetUpdate(true).Call();
RevCommit secondCommit = git.Commit().SetMessage("side").Call();
NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists());
CheckoutBranch("refs/heads/master");
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "b").Exists());
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();
// We are merging a deletion into our branch
MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
.RESOLVE).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
NUnit.Framework.Assert.AreEqual("1\na\n3(main)\n", Read(new FilePath(db.WorkTree,
"a")));
NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists());
NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree,
"c/c/c")));
NUnit.Framework.Assert.AreEqual("1\nd\n3\n", Read(new FilePath(db.WorkTree, "d"))
);
// Do the opposite, be on a branch where we have deleted a file and
// merge in a old commit where this file was not deleted
CheckoutBranch("refs/heads/side");
NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists());
result = git.Merge().Include(thirdCommit.Id).SetStrategy(MergeStrategy.RESOLVE).Call
();
NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
NUnit.Framework.Assert.AreEqual("1\na\n3(main)\n", Read(new FilePath(db.WorkTree,
"a")));
NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists());
NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree,
"c/c/c")));
NUnit.Framework.Assert.AreEqual("1\nd\n3\n", Read(new FilePath(db.WorkTree, "d"))
);
}
示例6: TestMultipleDeletions
public virtual void TestMultipleDeletions()
{
Git git = new Git(db);
WriteTrashFile("a", "1\na\n3\n");
git.Add().AddFilepattern("a").Call();
RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
CreateBranch(initialCommit, "refs/heads/side");
CheckoutBranch("refs/heads/side");
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "a").Delete());
git.Add().AddFilepattern("a").SetUpdate(true).Call();
RevCommit secondCommit = git.Commit().SetMessage("side").Call();
NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "a").Exists());
CheckoutBranch("refs/heads/master");
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "a").Exists());
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "a").Delete());
git.Add().AddFilepattern("a").SetUpdate(true).Call();
git.Commit().SetMessage("main").Call();
// We are merging a deletion into our branch
MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
.RESOLVE).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
}
示例7: TestMultipleCreations
public virtual void TestMultipleCreations()
{
Git git = new Git(db);
WriteTrashFile("a", "1\na\n3\n");
git.Add().AddFilepattern("a").Call();
RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
CreateBranch(initialCommit, "refs/heads/side");
CheckoutBranch("refs/heads/side");
WriteTrashFile("b", "1\nb(side)\n3\n");
git.Add().AddFilepattern("b").Call();
RevCommit secondCommit = git.Commit().SetMessage("side").Call();
CheckoutBranch("refs/heads/master");
WriteTrashFile("b", "1\nb(main)\n3\n");
git.Add().AddFilepattern("b").Call();
git.Commit().SetMessage("main").Call();
MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
.RESOLVE).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
}
示例8: TestMergeSuccessAllStrategies
// expected this exception
/// <exception cref="System.Exception"></exception>
// [Theory]
public virtual void TestMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
{
Git git = new Git(db);
RevCommit first = git.Commit().SetMessage("first").Call();
CreateBranch(first, "refs/heads/side");
WriteTrashFile("a", "a");
git.Add().AddFilepattern("a").Call();
git.Commit().SetMessage("second").Call();
CheckoutBranch("refs/heads/side");
WriteTrashFile("b", "b");
git.Add().AddFilepattern("b").Call();
git.Commit().SetMessage("third").Call();
MergeCommandResult result = git.Merge().SetStrategy(mergeStrategy).Include(db.GetRef
(Constants.MASTER)).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
NUnit.Framework.Assert.AreEqual("merge refs/heads/master: Merge made by " + mergeStrategy
.GetName() + ".", db.GetReflogReader(Constants.HEAD).GetLastEntry().GetComment()
);
NUnit.Framework.Assert.AreEqual("merge refs/heads/master: Merge made by " + mergeStrategy
.GetName() + ".", db.GetReflogReader(db.GetBranch()).GetLastEntry().GetComment()
);
}
示例9: TestMergeNonVersionedPaths
public virtual void TestMergeNonVersionedPaths()
{
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\na(side)\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(main)\n3\n");
WriteTrashFile("c/c/c", "1\nc(main)\n3\n");
git.Add().AddFilepattern("a").AddFilepattern("c/c/c").Call();
git.Commit().SetMessage("main").Call();
WriteTrashFile("d", "1\nd\n3\n");
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "e").Mkdir());
MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
.RESOLVE).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
NUnit.Framework.Assert.AreEqual("1\n<<<<<<< HEAD\na(main)\n=======\na(side)\n>>>>>>> 86503e7e397465588cc267b65d778538bffccb83\n3\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("1\nd\n3\n", Read(new FilePath(db.WorkTree, "d"))
);
FilePath dir = new FilePath(db.WorkTree, "e");
NUnit.Framework.Assert.IsTrue(dir.IsDirectory());
NUnit.Framework.Assert.AreEqual(1, result.GetConflicts().Count);
NUnit.Framework.Assert.AreEqual(3, result.GetConflicts().Get("a")[0].Length);
NUnit.Framework.Assert.AreEqual(RepositoryState.MERGING, db.GetRepositoryState());
}
示例10: TestConflictingMergeFailsDueToDirtyWorktree
public virtual void TestConflictingMergeFailsDueToDirtyWorktree()
{
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 file a
Write(fileA, "a(modified)");
// do not add and 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_WORKTREE, indexState
, fileA);
}
示例11: TestSuccessfulMergeFailsDueToDirtyIndex
public virtual void TestSuccessfulMergeFailsDueToDirtyIndex()
{
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");
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);
}
示例12: 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());
}
示例13: Merge
public void Merge (string branch, GitUpdateOptions options, IProgressMonitor monitor)
{
IEnumerable<DiffEntry> statusList = null;
Stash stash = null;
StashCollection stashes = GetStashes (RootRepository);
NGit.Api.Git git = new NGit.Api.Git (RootRepository);
try {
monitor.BeginTask (GettextCatalog.GetString ("Merging"), 5);
List<string> UpdateSubmodules = new List<string> ();
// TODO: Fix stash so we don't have to do update before the main repo update.
if ((options & GitUpdateOptions.UpdateSubmodules) == GitUpdateOptions.UpdateSubmodules) {
monitor.Log.WriteLine (GettextCatalog.GetString ("Checking repository submodules"));
if (!GetSubmodulesToUpdate (UpdateSubmodules))
return;
monitor.Log.WriteLine (GettextCatalog.GetString ("Updating repository submodules"));
var submoduleUpdate = git.SubmoduleUpdate ();
foreach (var submodule in UpdateSubmodules)
submoduleUpdate.AddPath (submodule);
submoduleUpdate.Call ();
monitor.Step (1);
}
// Get a list of files that are different in the target branch
statusList = GitUtil.GetChangedFiles (RootRepository, branch);
monitor.Step (1);
if ((options & GitUpdateOptions.SaveLocalChanges) != GitUpdateOptions.SaveLocalChanges) {
const VersionStatus unclean = VersionStatus.Modified | VersionStatus.ScheduledAdd | VersionStatus.ScheduledDelete;
bool modified = false;
if (GetDirectoryVersionInfo (RootPath, false, true).Any (v => (v.Status & unclean) != VersionStatus.Unversioned))
modified = true;
if (modified) {
if (MessageService.GenericAlert (
MonoDevelop.Ide.Gui.Stock.Question,
GettextCatalog.GetString ("You have uncommitted changes"),
GettextCatalog.GetString ("What do you want to do?"),
AlertButton.Cancel,
new AlertButton ("Stash")) == AlertButton.Cancel)
return;
options |= GitUpdateOptions.SaveLocalChanges;
}
}
if ((options & GitUpdateOptions.SaveLocalChanges) == GitUpdateOptions.SaveLocalChanges) {
monitor.Log.WriteLine (GettextCatalog.GetString ("Saving local changes"));
using (var gm = new GitMonitor (monitor))
stash = stashes.Create (gm, GetStashName ("_tmp_"));
monitor.Step (1);
}
// Apply changes
ObjectId branchId = RootRepository.Resolve (branch);
MergeCommandResult mergeResult = git.Merge ().SetStrategy (MergeStrategy.RESOLVE).Include (branchId).Call ();
if (mergeResult.GetMergeStatus () == MergeStatus.CONFLICTING || mergeResult.GetMergeStatus () == MergeStatus.FAILED) {
var conflicts = mergeResult.GetConflicts ();
bool commit = true;
if (conflicts != null) {
foreach (string conflictFile in conflicts.Keys) {
ConflictResult res = ResolveConflict (RootRepository.FromGitPath (conflictFile));
if (res == ConflictResult.Abort) {
GitUtil.HardReset (RootRepository, GetHeadCommit (RootRepository));
commit = false;
break;
} else if (res == ConflictResult.Skip) {
Revert (RootRepository.FromGitPath (conflictFile), false, monitor);
break;
}
}
}
if (commit)
git.Commit ().Call ();
}
if ((options & GitUpdateOptions.UpdateSubmodules) == GitUpdateOptions.UpdateSubmodules) {
monitor.Log.WriteLine (GettextCatalog.GetString ("Updating repository submodules"));
var submoduleUpdate = git.SubmoduleUpdate ();
foreach (var submodule in CachedSubmodules)
submoduleUpdate.AddPath (submodule.Item1);
submoduleUpdate.Call ();
monitor.Step (1);
}
} finally {
if ((options & GitUpdateOptions.SaveLocalChanges) == GitUpdateOptions.SaveLocalChanges)
monitor.Step (1);
// Restore local changes
if (stash != null) {
monitor.Log.WriteLine (GettextCatalog.GetString ("Restoring local changes"));
using (var gm = new GitMonitor (monitor))
stash.Apply (gm);
stashes.Remove (stash);
//.........这里部分代码省略.........
示例14: TestResetHard
public virtual void TestResetHard()
{
Git git = new Git(db);
WriteTrashFile("f", "f()");
WriteTrashFile("D/g", "g()");
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("inital").Call();
AssertIndex(Mkmap("f", "f()", "D/g", "g()"));
git.BranchCreate().SetName("topic").Call();
WriteTrashFile("f", "f()\nmaster");
WriteTrashFile("D/g", "g()\ng2()");
WriteTrashFile("E/h", "h()");
git.Add().AddFilepattern(".").Call();
RevCommit master = git.Commit().SetMessage("master-1").Call();
AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()"));
CheckoutBranch("refs/heads/topic");
AssertIndex(Mkmap("f", "f()", "D/g", "g()"));
WriteTrashFile("f", "f()\nside");
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "D/g").Delete());
WriteTrashFile("G/i", "i()");
git.Add().AddFilepattern(".").Call();
git.Add().AddFilepattern(".").SetUpdate(true).Call();
RevCommit topic = git.Commit().SetMessage("topic-1").Call();
AssertIndex(Mkmap("f", "f()\nside", "G/i", "i()"));
WriteTrashFile("untracked", "untracked");
ResetHard(master);
AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()"));
ResetHard(topic);
AssertIndex(Mkmap("f", "f()\nside", "G/i", "i()"));
AssertWorkDir(Mkmap("f", "f()\nside", "G/i", "i()", "untracked", "untracked"));
NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, git.Merge().Include(master
).Call().GetMergeStatus());
NUnit.Framework.Assert.AreEqual("[D/g, mode:100644, stage:1][D/g, mode:100644, stage:3][E/h, mode:100644][G/i, mode:100644][f, mode:100644, stage:1][f, mode:100644, stage:2][f, mode:100644, stage:3]"
, IndexState(0));
ResetHard(master);
AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()"));
AssertWorkDir(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()", "untracked"
, "untracked"));
}
示例15: TestHardResetAfterSquashMerge
public virtual void TestHardResetAfterSquashMerge()
{
Git g = new Git(db);
WriteTrashFile("file1", "file1");
g.Add().AddFilepattern("file1").Call();
RevCommit first = g.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");
g.Add().AddFilepattern("file2").Call();
g.Commit().SetMessage("second commit").Call();
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
CheckoutBranch("refs/heads/master");
MergeCommandResult result = g.Merge().Include(db.GetRef("branch1")).SetSquash(true
).Call();
NUnit.Framework.Assert.AreEqual(MergeStatus.FAST_FORWARD_SQUASHED, result.GetMergeStatus
());
NUnit.Framework.Assert.IsNotNull(db.ReadSquashCommitMsg());
g.Reset().SetMode(ResetCommand.ResetType.HARD).SetRef(first.GetName()).Call();
NUnit.Framework.Assert.IsNull(db.ReadSquashCommitMsg());
}