public virtual void TestParse_OnlyLFMessage()
        {
            RevCommit c = Create("\n");

            NUnit.Framework.Assert.AreEqual("\n", c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetShortMessage());
        }
        public virtual void TestParse_explicit_bad_encoded2()
        {
            ByteArrayOutputStream b = new ByteArrayOutputStream();

            b.Write(Sharpen.Runtime.GetBytesForString("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
                                                      , "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n"
                                                      , "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("committer C O. Miter <*****@*****.**> 1218123390 -0500\n"
                                                      , "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("encoding ISO-8859-1\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("\u304d\u308c\u3044\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("Hi\n", "UTF-8"));
            RevCommit c;

            c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            // bogus id
            c.ParseCanonical(new RevWalk(db), b.ToByteArray());
            NUnit.Framework.Assert.AreEqual("ISO-8859-1", c.Encoding.Name());
            NUnit.Framework.Assert.AreEqual("F\u00f6r fattare", c.GetAuthorIdent().GetName());
            NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044", c.GetShortMessage());
            NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.GetFullMessage());
        }
        public virtual void TestParse_ShortLineOnlyNoLF()
        {
            string    shortMsg = "This is a short message.";
            RevCommit c        = Create(shortMsg);

            NUnit.Framework.Assert.AreEqual(shortMsg, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(shortMsg, c.GetShortMessage());
        }
        public virtual void TestParse_NoMessage()
        {
            string    msg = string.Empty;
            RevCommit c   = Create(msg);

            NUnit.Framework.Assert.AreEqual(msg, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(msg, c.GetShortMessage());
        }
        public virtual void TestParse_ShortLineOnlyEmbeddedAndEndingLF()
        {
            string    fullMsg  = "This is a\nshort message.\n";
            string    shortMsg = "This is a short message.";
            RevCommit c        = Create(fullMsg);

            NUnit.Framework.Assert.AreEqual(fullMsg, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(shortMsg, c.GetShortMessage());
        }
        public virtual void TestParse_GitStyleMessage()
        {
            string    shortMsg = "This fixes a bug.";
            string    body     = "We do it with magic and pixie dust and stuff.\n" + "\n" + "Signed-off-by: A U. Thor <*****@*****.**>\n";
            string    fullMsg  = shortMsg + "\n" + "\n" + body;
            RevCommit c        = Create(fullMsg);

            NUnit.Framework.Assert.AreEqual(fullMsg, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(shortMsg, c.GetShortMessage());
        }
        public virtual void TestParse_WeirdHeaderOnlyCommit()
        {
            StringBuilder b = new StringBuilder();

            b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
            b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n");
            b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n");
            RevCommit c;

            c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(),
                                                                                "UTF-8"));
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetShortMessage());
        }
        public virtual void TestParse_PublicParseMethod()
        {
            ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
            NGit.CommitBuilder       src = new NGit.CommitBuilder();
            src.TreeId    = fmt.IdFor(Constants.OBJ_TREE, new byte[] {  });
            src.Author    = author;
            src.Committer = committer;
            src.Message   = "Test commit\n\nThis is a test.\n";
            RevCommit p = RevCommit.Parse(src.Build());

            NUnit.Framework.Assert.AreEqual(src.TreeId, p.Tree);
            NUnit.Framework.Assert.AreEqual(0, p.ParentCount);
            NUnit.Framework.Assert.AreEqual(author, p.GetAuthorIdent());
            NUnit.Framework.Assert.AreEqual(committer, p.GetCommitterIdent());
            NUnit.Framework.Assert.AreEqual("Test commit", p.GetShortMessage());
            NUnit.Framework.Assert.AreEqual(src.Message, p.GetFullMessage());
        }
示例#9
0
文件: Git.cs 项目: ststeiger/NancyHub
        // http://stackoverflow.com/questions/3407575/retrieving-oldest-commit-with-jgit
        public virtual void GetOldestCommit(string path)
        {
            NGit.Revwalk.RevCommit c          = null;
            NGit.Api.Git           repository = NGit.Api.Git.Open(path);


            try
            {
                NGit.Revwalk.RevWalk rw = new NGit.Revwalk.RevWalk(repository.GetRepository());

                NGit.AnyObjectId       headid = repository.GetRepository().Resolve(NGit.Constants.HEAD);
                NGit.Revwalk.RevCommit root   = rw.ParseCommit(headid);

                string msg1 = root.GetFullMessage();


                rw.Sort(NGit.Revwalk.RevSort.REVERSE);

                rw.MarkStart(root);
                c = rw.Next();
                // repository.GetRepository().
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            string msg2 = c.GetFullMessage();

            // Get author
            NGit.PersonIdent    authorIdent    = c.GetAuthorIdent();
            System.DateTime     authorDate     = authorIdent.GetWhen();
            System.TimeZoneInfo authorTimeZone = authorIdent.GetTimeZone();

            NGit.PersonIdent committerIdent = c.GetCommitterIdent();
            // http://stackoverflow.com/questions/12608610/how-do-you-get-the-author-date-and-commit-date-from-a-jgit-revcommit

            System.Console.WriteLine(authorIdent);
            System.Console.WriteLine(authorDate);
            System.Console.WriteLine(authorTimeZone);
            System.Console.WriteLine(committerIdent);

            CloseRepository(repository);
        }
示例#10
0
文件: Git.cs 项目: ststeiger/NancyHub
        public virtual System.DateTime GetOldestCommitDate(string path)
        {
            System.DateTime retVal = default(System.DateTime);

            NGit.Revwalk.RevCommit c          = null;
            NGit.Api.Git           repository = NGit.Api.Git.Open(path);


            try
            {
                NGit.Revwalk.RevWalk rw = new NGit.Revwalk.RevWalk(repository.GetRepository());

                NGit.AnyObjectId       headid = repository.GetRepository().Resolve(NGit.Constants.HEAD);
                NGit.Revwalk.RevCommit root   = rw.ParseCommit(headid);

                string msg1 = root.GetFullMessage();


                rw.Sort(NGit.Revwalk.RevSort.REVERSE);

                rw.MarkStart(root);
                c = rw.Next();
                // repository.GetRepository().
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            string msg2 = c.GetFullMessage();

            // Get author
            NGit.PersonIdent authorIdent = c.GetAuthorIdent();
            System.DateTime  authorDate  = authorIdent.GetWhen();

            retVal = authorDate.ToUniversalTime();

            CloseRepository(repository);

            return(retVal);
        }
示例#11
0
		public static MergeCommandResult MergeTrees (NGit.Repository repo, RevCommit srcBase, RevCommit srcCommit, string sourceDisplayName, bool commitResult)
		{
			RevCommit newHead = null;
			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));
				
				// CherryPick command sets the working tree, but this should not be necessary, and when setting it
				// untracked files are deleted during the merge
				// merger.SetWorkingTreeIterator(new FileTreeIterator(repo));
				
				merger.SetBase(srcBase);
				
				bool noProblems;
				IDictionary<string, MergeResult<NGit.Diff.Sequence>> lowLevelResults = null;
				IDictionary<string, ResolveMerger.MergeFailureReason> failingPaths = null;
				IList<string> modifiedFiles = null;
				
				ResolveMerger 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 (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
							, 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();
			}
		}
示例#12
0
 public virtual void TestParse_explicit_bad_encoded()
 {
     ByteArrayOutputStream b = new ByteArrayOutputStream();
     b.Write(Sharpen.Runtime.GetBytesForString("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
         , "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n"
         , "ISO-8859-1"));
     b.Write(Sharpen.Runtime.GetBytesForString("committer C O. Miter <*****@*****.**> 1218123390 -0500\n"
         , "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("encoding EUC-JP\n", "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("\u304d\u308c\u3044\n", "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("Hi\n", "UTF-8"));
     RevCommit c;
     c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
     // bogus id
     c.ParseCanonical(new RevWalk(db), b.ToByteArray());
     NUnit.Framework.Assert.AreEqual("Japanese (EUC)", c.Encoding.EncodingName);
     NUnit.Framework.Assert.AreEqual("F\u00f6r fattare", c.GetAuthorIdent().GetName());
     NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044", c.GetShortMessage());
     NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.GetFullMessage());
 }
示例#13
0
 public virtual void TestParse_WeirdHeaderOnlyCommit()
 {
     StringBuilder b = new StringBuilder();
     b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
     b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n");
     b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n");
     RevCommit c;
     c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
     c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(),
         "UTF-8"));
     NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
     NUnit.Framework.Assert.AreEqual(string.Empty, c.GetShortMessage());
 }
示例#14
0
 public virtual void TestParse_NoParents()
 {
     ObjectId treeId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
     string authorName = "A U. Thor";
     string authorEmail = "*****@*****.**";
     int authorTime = 1218123387;
     string authorTimeZone = "+0700";
     string committerName = "C O. Miter";
     string committerEmail = "*****@*****.**";
     int committerTime = 1218123390;
     string committerTimeZone = "-0500";
     StringBuilder body = new StringBuilder();
     body.Append("tree ");
     body.Append(treeId.Name);
     body.Append("\n");
     body.Append("author ");
     body.Append(authorName);
     body.Append(" <");
     body.Append(authorEmail);
     body.Append("> ");
     body.Append(authorTime);
     body.Append(" ");
     body.Append(authorTimeZone);
     body.Append(" \n");
     body.Append("committer ");
     body.Append(committerName);
     body.Append(" <");
     body.Append(committerEmail);
     body.Append("> ");
     body.Append(committerTime);
     body.Append(" ");
     body.Append(committerTimeZone);
     body.Append("\n");
     body.Append("\n");
     RevWalk rw = new RevWalk(db);
     RevCommit c;
     c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
     NUnit.Framework.Assert.IsNull(c.Tree);
     NUnit.Framework.Assert.IsNull(c.parents);
     c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8"));
     NUnit.Framework.Assert.IsNotNull(c.Tree);
     NUnit.Framework.Assert.AreEqual(treeId, c.Tree.Id);
     NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.Tree);
     NUnit.Framework.Assert.IsNotNull(c.parents);
     NUnit.Framework.Assert.AreEqual(0, c.parents.Length);
     NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
     PersonIdent cAuthor = c.GetAuthorIdent();
     NUnit.Framework.Assert.IsNotNull(cAuthor);
     NUnit.Framework.Assert.AreEqual(authorName, cAuthor.GetName());
     NUnit.Framework.Assert.AreEqual(authorEmail, cAuthor.GetEmailAddress());
     NUnit.Framework.Assert.AreEqual((long)authorTime * 1000, cAuthor.GetWhen().GetTime
         ());
     NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + authorTimeZone
         ), cAuthor.GetTimeZone());
     PersonIdent cCommitter = c.GetCommitterIdent();
     NUnit.Framework.Assert.IsNotNull(cCommitter);
     NUnit.Framework.Assert.AreEqual(committerName, cCommitter.GetName());
     NUnit.Framework.Assert.AreEqual(committerEmail, cCommitter.GetEmailAddress());
     NUnit.Framework.Assert.AreEqual((long)committerTime * 1000, cCommitter.GetWhen().
         GetTime());
     NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + committerTimeZone
         ), cCommitter.GetTimeZone());
 }
        public virtual void TestParse_NoParents()
        {
            ObjectId      treeId            = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            string        authorName        = "A U. Thor";
            string        authorEmail       = "*****@*****.**";
            int           authorTime        = 1218123387;
            string        authorTimeZone    = "+0700";
            string        committerName     = "C O. Miter";
            string        committerEmail    = "*****@*****.**";
            int           committerTime     = 1218123390;
            string        committerTimeZone = "-0500";
            StringBuilder body = new StringBuilder();

            body.Append("tree ");
            body.Append(treeId.Name);
            body.Append("\n");
            body.Append("author ");
            body.Append(authorName);
            body.Append(" <");
            body.Append(authorEmail);
            body.Append("> ");
            body.Append(authorTime);
            body.Append(" ");
            body.Append(authorTimeZone);
            body.Append(" \n");
            body.Append("committer ");
            body.Append(committerName);
            body.Append(" <");
            body.Append(committerEmail);
            body.Append("> ");
            body.Append(committerTime);
            body.Append(" ");
            body.Append(committerTimeZone);
            body.Append("\n");
            body.Append("\n");
            RevWalk   rw = new RevWalk(db);
            RevCommit c;

            c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            NUnit.Framework.Assert.IsNull(c.Tree);
            NUnit.Framework.Assert.IsNull(c.parents);
            c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8"));
            NUnit.Framework.Assert.IsNotNull(c.Tree);
            NUnit.Framework.Assert.AreEqual(treeId, c.Tree.Id);
            NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.Tree);
            NUnit.Framework.Assert.IsNotNull(c.parents);
            NUnit.Framework.Assert.AreEqual(0, c.parents.Length);
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
            PersonIdent cAuthor = c.GetAuthorIdent();

            NUnit.Framework.Assert.IsNotNull(cAuthor);
            NUnit.Framework.Assert.AreEqual(authorName, cAuthor.GetName());
            NUnit.Framework.Assert.AreEqual(authorEmail, cAuthor.GetEmailAddress());
            NUnit.Framework.Assert.AreEqual((long)authorTime * 1000, cAuthor.GetWhen().GetTime
                                                ());
            NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + authorTimeZone
                                                                           ).BaseUtcOffset, cAuthor.GetTimeZone().BaseUtcOffset);
            PersonIdent cCommitter = c.GetCommitterIdent();

            NUnit.Framework.Assert.IsNotNull(cCommitter);
            NUnit.Framework.Assert.AreEqual(committerName, cCommitter.GetName());
            NUnit.Framework.Assert.AreEqual(committerEmail, cCommitter.GetEmailAddress());
            NUnit.Framework.Assert.AreEqual((long)committerTime * 1000, cCommitter.GetWhen().
                                            GetTime());
            NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + committerTimeZone
                                                                           ).BaseUtcOffset, cCommitter.GetTimeZone().BaseUtcOffset);
        }
示例#16
0
 /// <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()));
 }