Ejemplo n.º 1
0
        public virtual void TestLogWithFilter()
        {
            Git git = new Git(db);
            // create first file
            FilePath file = new FilePath(db.WorkTree, "a.txt");

            FileUtils.CreateNewFile(file);
            PrintWriter writer = new PrintWriter(file);

            writer.Write("content1");
            writer.Close();
            // First commit - a.txt file
            git.Add().AddFilepattern("a.txt").Call();
            git.Commit().SetMessage("commit1").SetCommitter(committer).Call();
            // create second file
            file = new FilePath(db.WorkTree, "b.txt");
            FileUtils.CreateNewFile(file);
            writer = new PrintWriter(file);
            writer.Write("content2");
            writer.Close();
            // Second commit - b.txt file
            git.Add().AddFilepattern("b.txt").Call();
            git.Commit().SetMessage("commit2").SetCommitter(committer).Call();
            // First log - a.txt filter
            int count = 0;

            foreach (RevCommit c in git.Log().AddPath("a.txt").Call())
            {
                NUnit.Framework.Assert.AreEqual("commit1", c.GetFullMessage());
                count++;
            }
            NUnit.Framework.Assert.AreEqual(1, count);
            // Second log - b.txt filter
            count = 0;
            foreach (RevCommit c_1 in git.Log().AddPath("b.txt").Call())
            {
                NUnit.Framework.Assert.AreEqual("commit2", c_1.GetFullMessage());
                count++;
            }
            NUnit.Framework.Assert.AreEqual(1, count);
            // Third log - without filter
            count = 0;
            foreach (RevCommit c_2 in git.Log().Call())
            {
                NUnit.Framework.Assert.AreEqual(committer, c_2.GetCommitterIdent());
                count++;
            }
            NUnit.Framework.Assert.AreEqual(2, count);
        }
Ejemplo n.º 2
0
        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();

            NUnit.Framework.Assert.AreEqual("Revert \"fixed a\"", history.Next().GetShortMessage
                                                ());
            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());
        }
Ejemplo n.º 3
0
        public Models.Repository GetIncomingChanges(Models.Repository repository)
        {
            try
            {
                NGit.Api.Git git  = NGit.Api.Git.Open(repository.Path);
                Repository   repo = git.GetRepository();
                repo.GetIndexFile();

                //Repository repo = new FileRepository(new Sharpen.FilePath(path));
                //NGit.Api.Git git = new NGit.Api.Git(repo);

                //TODO: Find out how git works really, and fix this.
                FetchCommand         fc = git.Fetch();
                FetchResult          fr = fc.Call();
                LogCommand           lc = git.Log();
                Iterable <RevCommit> lr = lc.Call();


                if (git != null && repo != null && fr != null && lr != null)
                {
                    List <Watchtower.Models.Changeset> commits = new List <Watchtower.Models.Changeset>();
                    foreach (RevCommit rc in lr)
                    {
                        //TODO: Find out if these values are right.
                        Watchtower.Models.Changeset c = new Watchtower.Models.Changeset(rc.GetParent(0).GetHashCode().ToString(), rc.GetHashCode().ToString(), rc.GetCommitterIdent().GetEmailAddress(), rc.GetCommitterIdent().GetWhen(), rc.GetCommitterIdent().GetName(), rc.GetFullMessage());
                        commits.Add(c);
                    }
                    repository.IncomingChangesets = commits;
                }
            }
            catch
            {
            }
            return(repository);
        }
Ejemplo n.º 4
0
        public virtual void TestCommitRange()
        {
            // do 4 commits and set the range to the second and fourth one
            Git git = new Git(db);

            git.Commit().SetMessage("first commit").Call();
            RevCommit second = git.Commit().SetMessage("second commit").SetCommitter(committer
                                                                                     ).Call();

            git.Commit().SetMessage("third commit").SetAuthor(author).Call();
            RevCommit last = git.Commit().SetMessage("fourth commit").SetAuthor(author).SetCommitter
                                 (committer).Call();
            Iterable <RevCommit> commits = git.Log().AddRange(second.Id, last.Id).Call();
            // check that we have the third and fourth commit
            PersonIdent defaultCommitter = new PersonIdent(db);

            PersonIdent[] expectedAuthors    = new PersonIdent[] { author, author };
            PersonIdent[] expectedCommitters = new PersonIdent[] { defaultCommitter, committer };
            string[]      expectedMessages   = new string[] { "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);
        }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 6
0
		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());
		}
Ejemplo n.º 7
0
		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());
		}
        public virtual void LogAllCommits()
        {
            IList <RevCommit> commits = new AList <RevCommit>();
            Git git = Git.Wrap(db);

            WriteTrashFile("Test.txt", "Hello world");
            git.Add().AddFilepattern("Test.txt").Call();
            commits.AddItem(git.Commit().SetMessage("initial commit").Call());
            git.BranchCreate().SetName("branch1").Call();
            Ref checkedOut = git.Checkout().SetName("branch1").Call();

            NUnit.Framework.Assert.AreEqual("refs/heads/branch1", checkedOut.GetName());
            WriteTrashFile("Test1.txt", "Hello world!");
            git.Add().AddFilepattern("Test1.txt").Call();
            commits.AddItem(git.Commit().SetMessage("branch1 commit").Call());
            checkedOut = git.Checkout().SetName("master").Call();
            NUnit.Framework.Assert.AreEqual("refs/heads/master", checkedOut.GetName());
            WriteTrashFile("Test2.txt", "Hello world!!");
            git.Add().AddFilepattern("Test2.txt").Call();
            commits.AddItem(git.Commit().SetMessage("branch1 commit").Call());
            Iterator <RevCommit> log = git.Log().All().Call().Iterator();

            NUnit.Framework.Assert.IsTrue(log.HasNext());
            NUnit.Framework.Assert.IsTrue(commits.Contains(log.Next()));
            NUnit.Framework.Assert.IsTrue(log.HasNext());
            NUnit.Framework.Assert.IsTrue(commits.Contains(log.Next()));
            NUnit.Framework.Assert.IsTrue(log.HasNext());
            NUnit.Framework.Assert.IsTrue(commits.Contains(log.Next()));
            NUnit.Framework.Assert.IsFalse(log.HasNext());
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public virtual void TestMultipleInvocations()
        {
            Git           git       = new Git(db);
            CommitCommand commitCmd = git.Commit();

            commitCmd.SetMessage("initial commit").Call();
            try
            {
                // check that setters can't be called after invocation
                commitCmd.SetAuthor(author);
                NUnit.Framework.Assert.Fail("didn't catch the expected exception");
            }
            catch (InvalidOperationException)
            {
            }
            // expected
            LogCommand logCmd = git.Log();

            logCmd.Call();
            try
            {
                // check that call can't be called twice
                logCmd.Call();
                NUnit.Framework.Assert.Fail("didn't catch the expected exception");
            }
            catch (InvalidOperationException)
            {
            }
        }
Ejemplo n.º 11
0
		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:"
				));
		}
Ejemplo n.º 12
0
        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 virtual void LogAllCommitsWithSkipAndMaxCount()
        {
            Git git = Git.Wrap(db);
            IList <RevCommit>    commits = CreateCommits(git);
            Iterator <RevCommit> log     = git.Log().All().SetSkip(1).SetMaxCount(1).Call().Iterator
                                               ();

            NUnit.Framework.Assert.IsTrue(log.HasNext());
            RevCommit commit = log.Next();

            NUnit.Framework.Assert.IsTrue(commits.Contains(commit));
            NUnit.Framework.Assert.AreEqual("commit#2", commit.GetShortMessage());
            NUnit.Framework.Assert.IsFalse(log.HasNext());
        }
Ejemplo n.º 14
0
        public virtual void TestCommitAmend()
        {
            Git git = new Git(db);

            git.Commit().SetMessage("first comit").Call();
            // typo
            git.Commit().SetAmend(true).SetMessage("first commit").Call();
            Iterable <RevCommit> commits = git.Log().Call();
            int c = 0;

            foreach (RevCommit commit in commits)
            {
                NUnit.Framework.Assert.AreEqual("first commit", commit.GetFullMessage());
                c++;
            }
            NUnit.Framework.Assert.AreEqual(1, c);
        }
Ejemplo n.º 15
0
        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 \""
                                                                                        ));
        }
Ejemplo n.º 16
0
        public virtual void TestCommitAmend()
        {
            Git git = new Git(db);

            git.Commit().SetMessage("first comit").Call();
            // typo
            git.Commit().SetAmend(true).SetMessage("first commit").Call();
            Iterable <RevCommit> commits = git.Log().Call();
            int c = 0;

            foreach (RevCommit commit in commits)
            {
                NUnit.Framework.Assert.AreEqual("first commit", commit.GetFullMessage());
                c++;
            }
            NUnit.Framework.Assert.AreEqual(1, c);
            ReflogReader reader = db.GetReflogReader(Constants.HEAD);

            NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("commit (amend):"
                                                                                        ));
        }
Ejemplo n.º 17
0
 public virtual void TestMultipleInvocations()
 {
     Git git = new Git(db);
     CommitCommand commitCmd = git.Commit();
     commitCmd.SetMessage("initial commit").Call();
     try
     {
         // check that setters can't be called after invocation
         commitCmd.SetAuthor(author);
         NUnit.Framework.Assert.Fail("didn't catch the expected exception");
     }
     catch (InvalidOperationException)
     {
     }
     // expected
     LogCommand logCmd = git.Log();
     logCmd.Call();
     try
     {
         // check that call can't be called twice
         logCmd.Call();
         NUnit.Framework.Assert.Fail("didn't catch the expected exception");
     }
     catch (InvalidOperationException)
     {
     }
 }
Ejemplo n.º 18
0
 public virtual void TestLogWithFilter()
 {
     Git git = new Git(db);
     // create first file
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content1");
     writer.Close();
     // First commit - a.txt file
     git.Add().AddFilepattern("a.txt").Call();
     git.Commit().SetMessage("commit1").SetCommitter(committer).Call();
     // create second file
     file = new FilePath(db.WorkTree, "b.txt");
     FileUtils.CreateNewFile(file);
     writer = new PrintWriter(file);
     writer.Write("content2");
     writer.Close();
     // Second commit - b.txt file
     git.Add().AddFilepattern("b.txt").Call();
     git.Commit().SetMessage("commit2").SetCommitter(committer).Call();
     // First log - a.txt filter
     int count = 0;
     foreach (RevCommit c in git.Log().AddPath("a.txt").Call())
     {
         NUnit.Framework.Assert.AreEqual("commit1", c.GetFullMessage());
         count++;
     }
     NUnit.Framework.Assert.AreEqual(1, count);
     // Second log - b.txt filter
     count = 0;
     foreach (RevCommit c_1 in git.Log().AddPath("b.txt").Call())
     {
         NUnit.Framework.Assert.AreEqual("commit2", c_1.GetFullMessage());
         count++;
     }
     NUnit.Framework.Assert.AreEqual(1, count);
     // Third log - without filter
     count = 0;
     foreach (RevCommit c_2 in git.Log().Call())
     {
         NUnit.Framework.Assert.AreEqual(committer, c_2.GetCommitterIdent());
         count++;
     }
     NUnit.Framework.Assert.AreEqual(2, count);
 }
Ejemplo n.º 19
0
 public virtual void TestCommitRange()
 {
     // do 4 commits and set the range to the second and fourth one
     Git git = new Git(db);
     git.Commit().SetMessage("first commit").Call();
     RevCommit second = git.Commit().SetMessage("second commit").SetCommitter(committer
         ).Call();
     git.Commit().SetMessage("third commit").SetAuthor(author).Call();
     RevCommit last = git.Commit().SetMessage("fourth commit").SetAuthor(author).SetCommitter
         (committer).Call();
     Iterable<RevCommit> commits = git.Log().AddRange(second.Id, last.Id).Call();
     // check that we have the third and fourth commit
     PersonIdent defaultCommitter = new PersonIdent(db);
     PersonIdent[] expectedAuthors = new PersonIdent[] { author, author };
     PersonIdent[] expectedCommitters = new PersonIdent[] { defaultCommitter, committer
          };
     string[] expectedMessages = new string[] { "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);
 }
Ejemplo n.º 20
0
 public virtual void TestCommitAmend()
 {
     Git git = new Git(db);
     git.Commit().SetMessage("first comit").Call();
     // typo
     git.Commit().SetAmend(true).SetMessage("first commit").Call();
     Iterable<RevCommit> commits = git.Log().Call();
     int c = 0;
     foreach (RevCommit commit in commits)
     {
         NUnit.Framework.Assert.AreEqual("first commit", commit.GetFullMessage());
         c++;
     }
     NUnit.Framework.Assert.AreEqual(1, c);
     ReflogReader reader = db.GetReflogReader(Constants.HEAD);
     NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("commit (amend):"
         ));
     reader = db.GetReflogReader(db.GetBranch());
     NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("commit (amend):"
         ));
 }
Ejemplo n.º 21
0
        Element ConvertFileInfoToElement(Git git, string project, FileInfo fileInfo)
        {
            var element =  new Element
            {
                Name = Path.GetFileNameWithoutExtension(fileInfo.Name),
                File = GetRelativePathForFile(project, fileInfo),
                Author = "Unknown",
                LastChanged = "Unknown"
            };

            var logCommand = git.Log ();
            logCommand.AddPath (element.File);
            var result = logCommand.Call ();
            var commit = result.FirstOrDefault();
            if( commit != null )
            {
                element.Author = commit.GetCommitterIdent().GetName();
            }
            return element;
        }
Ejemplo n.º 22
0
 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());
 }
Ejemplo n.º 23
0
 public virtual void TestCommitAmend()
 {
     Git git = new Git(db);
     git.Commit().SetMessage("first comit").Call();
     // typo
     git.Commit().SetAmend(true).SetMessage("first commit").Call();
     Iterable<RevCommit> commits = git.Log().Call();
     int c = 0;
     foreach (RevCommit commit in commits)
     {
         NUnit.Framework.Assert.AreEqual("first commit", commit.GetFullMessage());
         c++;
     }
     NUnit.Framework.Assert.AreEqual(1, c);
 }
Ejemplo n.º 24
0
		public virtual void TestSuccessfulContentMerge()
		{
			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(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();
			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(null, result.GetConflicts());
			NUnit.Framework.Assert.AreEqual(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 '3fa334456d236a92db020289fe0bf481d91777b4'"
				, newHead.GetFullMessage());
			// @TODO fix me
			NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
		}