public virtual void TestInsertChangeId() { Git git = new Git(db); string messageHeader = "Some header line\n\nSome detail explanation\n"; string changeIdTemplate = "\nChange-Id: I" + ObjectId.ZeroId.GetName() + "\n"; string messageFooter = "Some foooter lines\nAnother footer line\n"; RevCommit commit = git.Commit().SetMessage(messageHeader + messageFooter).SetInsertChangeId (true).Call(); // we should find a real change id (at the end of the file) byte[] chars = Sharpen.Runtime.GetBytesForString(commit.GetFullMessage()); int lastLineBegin = RawParseUtils.PrevLF(chars, chars.Length - 2); string lastLine = RawParseUtils.Decode(chars, lastLineBegin + 1, chars.Length); NUnit.Framework.Assert.IsTrue(lastLine.Contains("Change-Id:")); NUnit.Framework.Assert.IsFalse(lastLine.Contains("Change-Id: I" + ObjectId.ZeroId .GetName())); commit = git.Commit().SetMessage(messageHeader + changeIdTemplate + messageFooter ).SetInsertChangeId(true).Call(); // we should find a real change id (in the line as dictated by the // template) chars = Sharpen.Runtime.GetBytesForString(commit.GetFullMessage()); int lineStart = 0; int lineEnd = 0; for (int i = 0; i < 4; i++) { lineStart = RawParseUtils.NextLF(chars, lineStart); } lineEnd = RawParseUtils.NextLF(chars, lineStart); string line = RawParseUtils.Decode(chars, lineStart, lineEnd); NUnit.Framework.Assert.IsTrue(line.Contains("Change-Id:")); NUnit.Framework.Assert.IsFalse(line.Contains("Change-Id: I" + ObjectId.ZeroId.GetName ())); commit = git.Commit().SetMessage(messageHeader + changeIdTemplate + messageFooter ).SetInsertChangeId(false).Call(); // we should find the untouched template chars = Sharpen.Runtime.GetBytesForString(commit.GetFullMessage()); lineStart = 0; lineEnd = 0; for (int i_1 = 0; i_1 < 4; i_1++) { lineStart = RawParseUtils.NextLF(chars, lineStart); } lineEnd = RawParseUtils.NextLF(chars, lineStart); line = RawParseUtils.Decode(chars, lineStart, lineEnd); NUnit.Framework.Assert.IsTrue(commit.GetFullMessage().Contains("Change-Id: I" + ObjectId .ZeroId.GetName())); }
/// <summary>Core validation to be performed on all stashed commits</summary> /// <param name="commit"></param> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> private void ValidateStashedCommit(RevCommit commit) { NUnit.Framework.Assert.IsNotNull(commit); Ref stashRef = db.GetRef(Constants.R_STASH); NUnit.Framework.Assert.IsNotNull(stashRef); NUnit.Framework.Assert.AreEqual(commit, stashRef.GetObjectId()); NUnit.Framework.Assert.IsNotNull(commit.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(commit.GetAuthorIdent(), commit.GetCommitterIdent ()); NUnit.Framework.Assert.AreEqual(2, commit.ParentCount); // Load parents RevWalk walk = new RevWalk(db); try { foreach (RevCommit parent in commit.Parents) { walk.ParseBody(parent); } } finally { walk.Release(); } NUnit.Framework.Assert.AreEqual(1, commit.GetParent(1).ParentCount); NUnit.Framework.Assert.AreEqual(head, commit.GetParent(1).GetParent(0)); NUnit.Framework.Assert.IsFalse(commit.Tree.Equals(head.Tree), "Head tree matches stashed commit tree" ); NUnit.Framework.Assert.AreEqual(head, commit.GetParent(0)); NUnit.Framework.Assert.IsFalse(commit.GetFullMessage().Equals(commit.GetParent(1) .GetFullMessage())); }
public virtual void Test023_createCommitNonAnullii() { ObjectId emptyId = InsertEmptyBlob(); Tree almostEmptyTree = new Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString ("empty"), false)); ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree); NGit.CommitBuilder commit = new NGit.CommitBuilder(); commit.TreeId = almostEmptyTreeId; commit.Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L , 60); commit.Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L , 60); commit.SetEncoding("UTF-8"); commit.Message = "\u00dcbergeeks"; ObjectId cid = InsertCommit(commit); NUnit.Framework.Assert.AreEqual("4680908112778718f37e686cbebcc912730b3154", cid.Name ); RevCommit loadedCommit = ParseCommit(cid); NUnit.Framework.Assert.AreEqual(commit.Message, loadedCommit.GetFullMessage()); }
public override CommitInfo GetLatestCommit() { using (var repository = GetRepository()) { var repo = (FileRepository)repository; var branch = repo.GetBranch(); if (branch == null) { return(null); } var objId = repo.Resolve(branch); if (objId == null) { return(null); } RevWalk walk = new RevWalk(repo); RevCommit commit = walk.ParseCommit(objId); if (commit == null) { return(null); } return(new CommitInfo { Message = commit.GetFullMessage(), Date = commit.GetCommitterIdent().GetWhen().ToLocalTime() }); } }
public static string message(this RevCommit revCommit) { if (revCommit.notNull()) { return(revCommit.GetFullMessage()); } return(null); }
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()); }
public string GetFullMessage(string hash) { var walk = new RevWalk(this.git.GetRepository()); RevCommit commit = walk.ParseCommit(ObjectId.FromString(hash)); walk.Dispose(); return(commit.GetFullMessage()); }
private ListViewItem CreateListItem(RevCommit c) { var commitTime = c.GetAuthorIdent().GetWhen().ToLocalTime(); ListViewItem item = new ListViewItem($"{commitTime.ToShortDateString()} {commitTime.ToShortTimeString()}"); item.SubItems.Add(c.GetFullMessage()); item.Tag = c; return(item); }
public virtual void TestStopOnConflictCommitAndContinue() { // create file1 on master RevCommit firstInMaster = WriteFileAndCommit(FILE1, "Add file1", "1", "2", "3"); // change in master WriteFileAndCommit(FILE1, "change file1 in master", "1master", "2", "3"); CheckFile(FILE1, "1master", "2", "3"); // create a topic branch based on the first commit CreateBranch(firstInMaster, "refs/heads/topic"); CheckoutBranch("refs/heads/topic"); // we have the old content again CheckFile(FILE1, "1", "2", "3"); // add a line (non-conflicting) WriteFileAndCommit(FILE1, "add a line to file1 in topic", "1", "2", "3", "4topic" ); // change first line (conflicting) WriteFileAndCommit(FILE1, "change file1 in topic\n\nThis is conflicting", "1topic" , "2", "3", "4topic"); // change second line (not conflicting) WriteFileAndCommit(FILE1, "change file1 in topic again", "1topic", "2", "3topic", "4topic"); RebaseResult res = git.Rebase().SetUpstream("refs/heads/master").Call(); NUnit.Framework.Assert.AreEqual(RebaseResult.Status.STOPPED, res.GetStatus()); // continue should throw a meaningful exception try { res = git.Rebase().SetOperation(RebaseCommand.Operation.CONTINUE).Call(); NUnit.Framework.Assert.Fail("Expected Exception not thrown"); } catch (UnmergedPathsException) { } // expected // merge the file; the second topic commit should go through WriteFileAndCommit(FILE1, "A different commit message", "1topic", "2", "3", "4topic" ); res = git.Rebase().SetOperation(RebaseCommand.Operation.CONTINUE).Call(); NUnit.Framework.Assert.IsNotNull(res); NUnit.Framework.Assert.AreEqual(RebaseResult.Status.OK, res.GetStatus()); NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState()); ObjectId headId = db.Resolve(Constants.HEAD); RevWalk rw = new RevWalk(db); RevCommit rc = rw.ParseCommit(headId); RevCommit parent = rw.ParseCommit(rc.GetParent(0)); NUnit.Framework.Assert.AreEqual("A different commit message", parent.GetFullMessage ()); }
/// <exception cref="System.IO.IOException"></exception> private RebaseResult Stop(RevCommit commitToPick) { PersonIdent author = commitToPick.GetAuthorIdent(); string authorScript = ToAuthorScript(author); CreateFile(rebaseDir, AUTHOR_SCRIPT, authorScript); CreateFile(rebaseDir, MESSAGE, commitToPick.GetFullMessage()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DiffFormatter df = new DiffFormatter(bos); df.SetRepository(repo); df.Format(commitToPick.GetParent(0), commitToPick); CreateFile(rebaseDir, PATCH, Sharpen.Runtime.GetStringForBytes(bos.ToByteArray(), Constants.CHARACTER_ENCODING)); CreateFile(rebaseDir, STOPPED_SHA, repo.NewObjectReader().Abbreviate(commitToPick ).Name); return(new RebaseResult(commitToPick)); }
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()); ReflogReader reader = db.GetReflogReader(Constants.HEAD); NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("revert: Revert \"" )); reader = db.GetReflogReader(db.GetBranch()); NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("revert: Revert \"" )); }
public virtual void RefLogIncludesCommitMessage() { PersonIdent who = new PersonIdent("user", "*****@*****.**"); DeleteTrashFile("file.txt"); RevCommit stashed = git.StashCreate().SetPerson(who).Call(); NUnit.Framework.Assert.IsNotNull(stashed); NUnit.Framework.Assert.AreEqual("content", Read(committedFile)); ValidateStashedCommit(stashed); ReflogReader reader = new ReflogReader(git.GetRepository(), Constants.R_STASH); ReflogEntry entry = reader.GetLastEntry(); NUnit.Framework.Assert.IsNotNull(entry); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entry.GetOldId()); NUnit.Framework.Assert.AreEqual(stashed, entry.GetNewId()); NUnit.Framework.Assert.AreEqual(who, entry.GetWho()); NUnit.Framework.Assert.AreEqual(stashed.GetFullMessage(), entry.GetComment()); }
public virtual void Test009_CreateCommitOldFormat() { ObjectId treeId = InsertTree(new TreeFormatter()); NGit.CommitBuilder c = new NGit.CommitBuilder(); c.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c.Message = "A Commit\n"; c.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c.TreeId); ObjectId actid = InsertCommit(c); ObjectId cmtid = ObjectId.FromString("9208b2459ea6609a5af68627cc031796d0d9329b"); NUnit.Framework.Assert.AreEqual(cmtid, actid); // Verify the commit we just wrote is in the correct format. ObjectDatabase odb = ((ObjectDirectory)db.ObjectDatabase); NUnit.Framework.Assert.IsTrue(odb is ObjectDirectory, "is ObjectDirectory"); XInputStream xis = new XInputStream(new FileInputStream(((ObjectDirectory)odb).FileFor (cmtid))); try { NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x78)), xis.ReadUInt8()); NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x9c)), xis.ReadUInt8()); NUnit.Framework.Assert.IsTrue(unchecked ((int)(0x789c)) % 31 == 0); } finally { xis.Close(); } // Verify we can read it. RevCommit c2 = ParseCommit(actid); NUnit.Framework.Assert.IsNotNull(c2); NUnit.Framework.Assert.AreEqual(c.Message, c2.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c.TreeId, c2.Tree); NUnit.Framework.Assert.AreEqual(c.Author, c2.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(c.Committer, c2.GetCommitterIdent()); }
public static MergeCommandResult MergeTrees(ProgressMonitor monitor, NGit.Repository repo, RevCommit srcBase, RevCommit srcCommit, string sourceDisplayName, bool commitResult) { RevCommit newHead; RevWalk revWalk = new RevWalk(repo); try { // get the head commit Ref headRef = repo.GetRef(Constants.HEAD); if (headRef == null) { throw new NoHeadException(JGitText.Get().commitOnRepoWithoutHEADCurrentlyNotSupported ); } RevCommit headCommit = revWalk.ParseCommit(headRef.GetObjectId()); ResolveMerger merger = (ResolveMerger)((ThreeWayMerger)MergeStrategy.RESOLVE.NewMerger (repo)); merger.SetWorkingTreeIterator(new FileTreeIterator(repo)); merger.SetBase(srcBase); bool noProblems; IDictionary <string, MergeResult <Sequence> > lowLevelResults = null; IDictionary <string, ResolveMerger.MergeFailureReason> failingPaths = null; IList <string> modifiedFiles = null; ResolveMerger resolveMerger = merger; resolveMerger.SetCommitNames(new string[] { "BASE", "HEAD", sourceDisplayName }); noProblems = merger.Merge(headCommit, srcCommit); lowLevelResults = resolveMerger.GetMergeResults(); modifiedFiles = resolveMerger.GetModifiedFiles(); failingPaths = resolveMerger.GetFailingPaths(); if (monitor != null) { monitor.Update(50); } if (noProblems) { if (modifiedFiles != null && modifiedFiles.Count == 0) { return(new MergeCommandResult(headCommit, null, new ObjectId[] { headCommit.Id, srcCommit .Id }, MergeStatus.ALREADY_UP_TO_DATE, MergeStrategy.RESOLVE, null, null)); } DirCacheCheckout dco = new DirCacheCheckout(repo, headCommit.Tree, repo.LockDirCache (), merger.GetResultTreeId()); dco.SetFailOnConflict(true); dco.Checkout(); if (commitResult) { newHead = new NGit.Api.Git(repo).Commit().SetMessage(srcCommit.GetFullMessage() ).SetAuthor(srcCommit.GetAuthorIdent()).Call(); return(new MergeCommandResult(newHead.Id, null, new ObjectId[] { headCommit.Id, srcCommit .Id }, MergeStatus.MERGED, MergeStrategy.RESOLVE, null, null)); } else { return(new MergeCommandResult(headCommit, null, new ObjectId[] { headCommit.Id, srcCommit .Id }, MergeStatus.MERGED, MergeStrategy.RESOLVE, null, null)); } } else { if (failingPaths != null) { return(new MergeCommandResult(null, merger.GetBaseCommit(0, 1), new ObjectId[] { headCommit.Id, srcCommit.Id }, MergeStatus.FAILED, MergeStrategy.RESOLVE, lowLevelResults , failingPaths, null)); } else { return(new MergeCommandResult(null, merger.GetBaseCommit(0, 1), new ObjectId[] { headCommit.Id, srcCommit.Id }, MergeStatus.CONFLICTING, MergeStrategy.RESOLVE, lowLevelResults , null)); } } } finally { revWalk.Release(); } }
public virtual void Test026_CreateCommitMultipleparents() { ObjectId treeId; ObjectInserter oi = db.NewObjectInserter(); try { ObjectId blobId = oi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString ("and this is the data in me\n", Constants.CHARSET.Name())); TreeFormatter fmt = new TreeFormatter(); fmt.Append("i-am-a-file", FileMode.REGULAR_FILE, blobId); treeId = oi.Insert(fmt); oi.Flush(); } finally { oi.Release(); } NUnit.Framework.Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936" ), treeId); NGit.CommitBuilder c1 = new NGit.CommitBuilder(); c1.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c1.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c1.Message = "A Commit\n"; c1.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c1.TreeId); ObjectId actid1 = InsertCommit(c1); ObjectId cmtid1 = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099"); NUnit.Framework.Assert.AreEqual(cmtid1, actid1); NGit.CommitBuilder c2 = new NGit.CommitBuilder(); c2.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c2.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c2.Message = "A Commit 2\n"; c2.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c2.TreeId); c2.SetParentIds(actid1); ObjectId actid2 = InsertCommit(c2); ObjectId cmtid2 = ObjectId.FromString("95d068687c91c5c044fb8c77c5154d5247901553"); NUnit.Framework.Assert.AreEqual(cmtid2, actid2); RevCommit rm2 = ParseCommit(cmtid2); NUnit.Framework.Assert.AreNotSame(c2, rm2); // assert the parsed objects is not from the // cache NUnit.Framework.Assert.AreEqual(c2.Author, rm2.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(actid2, rm2.Id); NUnit.Framework.Assert.AreEqual(c2.Message, rm2.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c2.TreeId, rm2.Tree.Id); NUnit.Framework.Assert.AreEqual(1, rm2.ParentCount); NUnit.Framework.Assert.AreEqual(actid1, rm2.GetParent(0)); NGit.CommitBuilder c3 = new NGit.CommitBuilder(); c3.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c3.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c3.Message = "A Commit 3\n"; c3.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c3.TreeId); c3.SetParentIds(actid1, actid2); ObjectId actid3 = InsertCommit(c3); ObjectId cmtid3 = ObjectId.FromString("ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4"); NUnit.Framework.Assert.AreEqual(cmtid3, actid3); RevCommit rm3 = ParseCommit(cmtid3); NUnit.Framework.Assert.AreNotSame(c3, rm3); // assert the parsed objects is not from the // cache NUnit.Framework.Assert.AreEqual(c3.Author, rm3.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(actid3, rm3.Id); NUnit.Framework.Assert.AreEqual(c3.Message, rm3.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c3.TreeId, rm3.Tree.Id); NUnit.Framework.Assert.AreEqual(2, rm3.ParentCount); NUnit.Framework.Assert.AreEqual(actid1, rm3.GetParent(0)); NUnit.Framework.Assert.AreEqual(actid2, rm3.GetParent(1)); NGit.CommitBuilder c4 = new NGit.CommitBuilder(); c4.Author = new PersonIdent(author, 1154236443000L, -4 * 60); c4.Committer = new PersonIdent(committer, 1154236443000L, -4 * 60); c4.Message = "A Commit 4\n"; c4.TreeId = treeId; NUnit.Framework.Assert.AreEqual(treeId, c3.TreeId); c4.SetParentIds(actid1, actid2, actid3); ObjectId actid4 = InsertCommit(c4); ObjectId cmtid4 = ObjectId.FromString("d1fca9fe3fef54e5212eb67902c8ed3e79736e27"); NUnit.Framework.Assert.AreEqual(cmtid4, actid4); RevCommit rm4 = ParseCommit(cmtid4); NUnit.Framework.Assert.AreNotSame(c4, rm3); // assert the parsed objects is not from the // cache NUnit.Framework.Assert.AreEqual(c4.Author, rm4.GetAuthorIdent()); NUnit.Framework.Assert.AreEqual(actid4, rm4.Id); NUnit.Framework.Assert.AreEqual(c4.Message, rm4.GetFullMessage()); NUnit.Framework.Assert.AreEqual(c4.TreeId, rm4.Tree.Id); NUnit.Framework.Assert.AreEqual(3, rm4.ParentCount); NUnit.Framework.Assert.AreEqual(actid1, rm4.GetParent(0)); NUnit.Framework.Assert.AreEqual(actid2, rm4.GetParent(1)); NUnit.Framework.Assert.AreEqual(actid3, rm4.GetParent(2)); }
/// <summary> /// Executes the /// <code>Cherry-Pick</code> /// command with all the options and /// parameters collected by the setter methods (e.g. /// <see cref="Include(NGit.Ref)">Include(NGit.Ref)</see> /// of /// this class. Each instance of this class should only be used for one /// invocation of the command. Don't call this method twice on an instance. /// </summary> /// <returns>the result of the cherry-pick</returns> /// <exception cref="NGit.Api.Errors.GitAPIException"></exception> public override CherryPickResult Call() { RevCommit newHead = null; IList <Ref> cherryPickedRefs = new List <Ref>(); CheckCallable(); RevWalk revWalk = new RevWalk(repo); try { // get the head commit Ref headRef = repo.GetRef(Constants.HEAD); if (headRef == null) { throw new NoHeadException(JGitText.Get().commitOnRepoWithoutHEADCurrentlyNotSupported ); } RevCommit headCommit = revWalk.ParseCommit(headRef.GetObjectId()); newHead = headCommit; // loop through all refs to be cherry-picked foreach (Ref src in commits) { // get the commit to be cherry-picked // handle annotated tags ObjectId srcObjectId = src.GetPeeledObjectId(); if (srcObjectId == null) { srcObjectId = src.GetObjectId(); } RevCommit srcCommit = revWalk.ParseCommit(srcObjectId); // get the parent of the commit to cherry-pick if (srcCommit.ParentCount != 1) { throw new MultipleParentsNotAllowedException(JGitText.Get().canOnlyCherryPickCommitsWithOneParent ); } RevCommit srcParent = srcCommit.GetParent(0); revWalk.ParseHeaders(srcParent); ResolveMerger merger = (ResolveMerger)((ThreeWayMerger)MergeStrategy.RESOLVE.NewMerger (repo)); merger.SetWorkingTreeIterator(new FileTreeIterator(repo)); merger.SetBase(srcParent.Tree); if (merger.Merge(headCommit, srcCommit)) { if (AnyObjectId.Equals(headCommit.Tree.Id, merger.GetResultTreeId())) { continue; } DirCacheCheckout dco = new DirCacheCheckout(repo, headCommit.Tree, repo.LockDirCache (), merger.GetResultTreeId()); dco.SetFailOnConflict(true); dco.Checkout(); newHead = new Git(GetRepository()).Commit().SetMessage(srcCommit.GetFullMessage() ).SetAuthor(srcCommit.GetAuthorIdent()).Call(); cherryPickedRefs.AddItem(src); } else { if (merger.Failed()) { return(new CherryPickResult(merger.GetFailingPaths())); } // there are merge conflicts string message = new MergeMessageFormatter().FormatWithConflicts(srcCommit.GetFullMessage (), merger.GetUnmergedPaths()); repo.WriteCherryPickHead(srcCommit.Id); repo.WriteMergeCommitMsg(message); return(CherryPickResult.CONFLICT); } } } catch (IOException e) { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().exceptionCaughtDuringExecutionOfCherryPickCommand , e), e); } finally { revWalk.Release(); } return(new CherryPickResult(newHead, cherryPickedRefs)); }
static void Main(string[] args) { Iterable <RevCommit> gitLogs = GetRevCommitList(); int count = 0; DateTime startTime = System.DateTime.Now; Dictionary <string, string> gitLogDictionary = new Dictionary <string, string>(); Dictionary <string, Dictionary <string, string> > groupedChangeSets = new Dictionary <string, Dictionary <string, string> >(); HashSet <string> commitIDs = new HashSet <string>(); for (Iterator <RevCommit> iterator = gitLogs.Iterator(); iterator.HasNext();) { RevCommit rev = iterator.Next(); //System.Console.WriteLine(rev.Id.FirstByte); //System.Console.WriteLine(rev.GetFullMessage()); // TermFrequency.Add(rev.Id.Name, rev.GetFullMessage()); gitLogDictionary.Add(rev.Id.Name, TermFrequency.CleanInput(rev.GetFullMessage())); //System.Console.ReadLine(); count++; } int loopCount = 0; Iterable <RevCommit> gitLogs1 = GetRevCommitList(); //for (Iterator<RevCommit> iterator2 = gitLogs1.Iterator(); iterator2.HasNext(); ) foreach (var itemParent in gitLogDictionary) { //RevCommit rev = iterator2.Next(); bool first = true; if (!itemParent.Value.ToLower().Contains("merge branch") && !commitIDs.Contains(itemParent.Key)) { foreach (var item in gitLogDictionary) { if (!item.Value.ToLower().Contains("merge branch")) { if (item.Key != itemParent.Key && TermFrequency.GetSimilarityValue(itemParent.Value, item.Value) > 0.8) { if (first) { groupedChangeSets.Add(itemParent.Key, new Dictionary <string, string>() { { itemParent.Key, itemParent.Value } }); commitIDs.Add(itemParent.Key); first = false; } groupedChangeSets[itemParent.Key].Add(item.Key, item.Value); commitIDs.Add(item.Key); string Test1 = "1"; } } } } loopCount++; System.Console.Clear(); System.Console.WriteLine(loopCount); } TimeSpan TotalTime = (System.DateTime.Now - startTime); foreach (var item in groupedChangeSets) { foreach (var item1 in item.Value) { //System.Console.WriteLine(item.Key + ";" + item1.Key + ";" + item1.Value); WriteData(item.Key, item1.Key, item1.Value); } } System.Console.WriteLine(TotalTime); // System.Console.ReadLine(); //TermFrequency.Print(); }
public static string GetComment(this RevCommit commit) { return(commit.GetFullMessage().TrimEnd('\n')); }