Ejemplo n.º 1
0
 public virtual void TestCloneRepositoryWithBranch()
 {
     try
     {
         FilePath     directory = CreateTempDirectory("testCloneRepositoryWithBranch");
         CloneCommand command   = Git.CloneRepository();
         command.SetBranch("refs/heads/master");
         command.SetDirectory(directory);
         command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
         Git git2 = command.Call();
         AddRepoToClose(git2.GetRepository());
         NUnit.Framework.Assert.IsNotNull(git2);
         NUnit.Framework.Assert.AreEqual(git2.GetRepository().GetFullBranch(), "refs/heads/master"
                                         );
         NUnit.Framework.Assert.AreEqual("refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test"
                                         , AllRefNames(git2.BranchList().SetListMode(ListBranchCommand.ListMode.ALL).Call
                                                           ()));
         // Same thing, but now without checkout
         directory = CreateTempDirectory("testCloneRepositoryWithBranch_bare");
         command   = Git.CloneRepository();
         command.SetBranch("refs/heads/master");
         command.SetDirectory(directory);
         command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
         command.SetNoCheckout(true);
         git2 = command.Call();
         AddRepoToClose(git2.GetRepository());
         NUnit.Framework.Assert.IsNotNull(git2);
         NUnit.Framework.Assert.AreEqual(git2.GetRepository().GetFullBranch(), "refs/heads/master"
                                         );
         NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master, refs/remotes/origin/test"
                                         , AllRefNames(git2.BranchList().SetListMode(ListBranchCommand.ListMode.ALL).Call
                                                           ()));
         // Same thing, but now test with bare repo
         directory = CreateTempDirectory("testCloneRepositoryWithBranch_bare");
         command   = Git.CloneRepository();
         command.SetBranch("refs/heads/master");
         command.SetDirectory(directory);
         command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
         command.SetBare(true);
         git2 = command.Call();
         AddRepoToClose(git2.GetRepository());
         NUnit.Framework.Assert.IsNotNull(git2);
         NUnit.Framework.Assert.AreEqual(git2.GetRepository().GetFullBranch(), "refs/heads/master"
                                         );
         NUnit.Framework.Assert.AreEqual("refs/heads/master, refs/heads/test", AllRefNames
                                             (git2.BranchList().SetListMode(ListBranchCommand.ListMode.ALL).Call()));
     }
     catch (Exception e)
     {
         NUnit.Framework.Assert.Fail(e.Message);
     }
 }
Ejemplo n.º 2
0
        public virtual void TestCloneRepository()
        {
            FilePath     directory = CreateTempDirectory("testCloneRepository");
            CloneCommand command   = Git.CloneRepository();

            command.SetDirectory(directory);
            command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            Git git2 = command.Call();

            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsNotNull(git2);
            ObjectId id = git2.GetRepository().Resolve("tag-for-blob");

            NUnit.Framework.Assert.IsNotNull(id);
            NUnit.Framework.Assert.AreEqual(git2.GetRepository().GetFullBranch(), "refs/heads/test"
                                            );
            NUnit.Framework.Assert.AreEqual("origin", git2.GetRepository().GetConfig().GetString
                                                (ConfigConstants.CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_KEY_REMOTE
                                                ));
            NUnit.Framework.Assert.AreEqual("refs/heads/test", git2.GetRepository().GetConfig
                                                ().GetString(ConfigConstants.CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_KEY_MERGE
                                                             ));
            NUnit.Framework.Assert.AreEqual(2, git2.BranchList().SetListMode(ListBranchCommand.ListMode
                                                                             .REMOTE).Call().Count);
        }
Ejemplo n.º 3
0
        public virtual void TestCloneRepositoryOnlyOneBranch()
        {
            FilePath     directory = CreateTempDirectory("testCloneRepositoryWithBranch");
            CloneCommand command   = Git.CloneRepository();

            command.SetBranch("refs/heads/master");
            command.SetBranchesToClone(Collections.SingletonList("refs/heads/master"));
            command.SetDirectory(directory);
            command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            Git git2 = command.Call();

            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsNotNull(git2);
            NUnit.Framework.Assert.AreEqual(git2.GetRepository().GetFullBranch(), "refs/heads/master"
                                            );
            NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", AllRefNames(git2.BranchList
                                                                                          ().SetListMode(ListBranchCommand.ListMode.REMOTE).Call()));
            // Same thing, but now test with bare repo
            directory = CreateTempDirectory("testCloneRepositoryWithBranch_bare");
            command   = Git.CloneRepository();
            command.SetBranch("refs/heads/master");
            command.SetBranchesToClone(Collections.SingletonList("refs/heads/master"));
            command.SetDirectory(directory);
            command.SetURI("file://" + git.GetRepository().WorkTree.GetPath());
            command.SetBare(true);
            git2 = command.Call();
            AddRepoToClose(git2.GetRepository());
            NUnit.Framework.Assert.IsNotNull(git2);
            NUnit.Framework.Assert.AreEqual(git2.GetRepository().GetFullBranch(), "refs/heads/master"
                                            );
            NUnit.Framework.Assert.AreEqual("refs/heads/master", AllRefNames(git2.BranchList(
                                                                                 ).SetListMode(ListBranchCommand.ListMode.ALL).Call()));
        }
Ejemplo n.º 4
0
        public virtual void TestPullConfigRemoteBranch()
        {
            Git localGit = SetUpRepoWithRemote();
            Ref remote   = localGit.BranchList().SetListMode(ListBranchCommand.ListMode.REMOTE)
                           .Call()[0];

            NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", remote.GetName());
            // by default, we should create pull configuration
            CreateBranch(localGit, "newFromRemote", false, remote.GetName(), null);
            NUnit.Framework.Assert.AreEqual("origin", localGit.GetRepository().GetConfig().GetString
                                                ("branch", "newFromRemote", "remote"));
            localGit.BranchDelete().SetBranchNames("newFromRemote").Call();
            // the pull configuration should be gone after deletion
            NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch"
                                                                                         , "newFromRemote", "remote"));
            CreateBranch(localGit, "newFromRemote", false, remote.GetName(), null);
            NUnit.Framework.Assert.AreEqual("origin", localGit.GetRepository().GetConfig().GetString
                                                ("branch", "newFromRemote", "remote"));
            localGit.BranchDelete().SetBranchNames("refs/heads/newFromRemote").Call();
            // the pull configuration should be gone after deletion
            NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch"
                                                                                         , "newFromRemote", "remote"));
            // use --no-track
            CreateBranch(localGit, "newFromRemote", false, remote.GetName(), CreateBranchCommand.SetupUpstreamMode
                         .NOTRACK);
            NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch"
                                                                                         , "newFromRemote", "remote"));
            localGit.BranchDelete().SetBranchNames("newFromRemote").Call();
        }
Ejemplo n.º 5
0
        public virtual void TestWrap()
        {
            Git git = Git.Wrap(db);

            NUnit.Framework.Assert.AreEqual(1, git.BranchList().Call().Count);
            git = Git.Wrap(bareRepo);
            NUnit.Framework.Assert.AreEqual(1, git.BranchList().SetListMode(ListBranchCommand.ListMode
                                                                            .ALL).Call().Count);
            try
            {
                Git.Wrap(null);
                NUnit.Framework.Assert.Fail("Expected exception has not been thrown");
            }
            catch (ArgumentNullException)
            {
            }
        }
Ejemplo n.º 6
0
        public virtual void TestCreateAndList()
        {
            int localBefore;
            int remoteBefore;
            int allBefore;

            // invalid name not allowed
            try
            {
                git.BranchCreate().SetName("In va lid").Call();
                NUnit.Framework.Assert.Fail("Create branch with invalid ref name should fail");
            }
            catch (InvalidRefNameException)
            {
            }
            // expected
            // existing name not allowed w/o force
            try
            {
                git.BranchCreate().SetName("master").Call();
                NUnit.Framework.Assert.Fail("Create branch with existing ref name should fail");
            }
            catch (RefAlreadyExistsException)
            {
            }
            // expected
            localBefore  = git.BranchList().Call().Count;
            remoteBefore = git.BranchList().SetListMode(ListBranchCommand.ListMode.REMOTE).Call
                               ().Count;
            allBefore = git.BranchList().SetListMode(ListBranchCommand.ListMode.ALL).Call().Count;
            NUnit.Framework.Assert.AreEqual(localBefore + remoteBefore, allBefore);
            Ref newBranch = CreateBranch(git, "NewForTestList", false, "master", null);

            NUnit.Framework.Assert.AreEqual("refs/heads/NewForTestList", newBranch.GetName());
            NUnit.Framework.Assert.AreEqual(1, git.BranchList().Call().Count - localBefore);
            NUnit.Framework.Assert.AreEqual(0, git.BranchList().SetListMode(ListBranchCommand.ListMode
                                                                            .REMOTE).Call().Count - remoteBefore);
            NUnit.Framework.Assert.AreEqual(1, git.BranchList().SetListMode(ListBranchCommand.ListMode
                                                                            .ALL).Call().Count - allBefore);
            // we can only create local branches
            newBranch = CreateBranch(git, "refs/remotes/origin/NewRemoteForTestList", false,
                                     "master", null);
            NUnit.Framework.Assert.AreEqual("refs/heads/refs/remotes/origin/NewRemoteForTestList"
                                            , newBranch.GetName());
            NUnit.Framework.Assert.AreEqual(2, git.BranchList().Call().Count - localBefore);
            NUnit.Framework.Assert.AreEqual(0, git.BranchList().SetListMode(ListBranchCommand.ListMode
                                                                            .REMOTE).Call().Count - remoteBefore);
            NUnit.Framework.Assert.AreEqual(2, git.BranchList().SetListMode(ListBranchCommand.ListMode
                                                                            .ALL).Call().Count - allBefore);
        }
Ejemplo n.º 7
0
        public virtual void TestOpen()
        {
            Git git = Git.Open(db.Directory);

            NUnit.Framework.Assert.AreEqual(1, git.BranchList().Call().Count);
            git = Git.Open(bareRepo.Directory);
            NUnit.Framework.Assert.AreEqual(1, git.BranchList().SetListMode(ListBranchCommand.ListMode
                                                                            .ALL).Call().Count);
            git = Git.Open(db.WorkTree);
            NUnit.Framework.Assert.AreEqual(1, git.BranchList().SetListMode(ListBranchCommand.ListMode
                                                                            .ALL).Call().Count);
            try
            {
                Git.Open(db.ObjectsDirectory);
                NUnit.Framework.Assert.Fail("Expected exception has not been thrown");
            }
            catch (RepositoryNotFoundException)
            {
            }
        }
Ejemplo n.º 8
0
        public virtual void TestRenameRemoteTrackingBranch()
        {
            Git localGit     = SetUpRepoWithRemote();
            Ref remoteBranch = localGit.BranchList().SetListMode(ListBranchCommand.ListMode.REMOTE
                                                                 ).Call()[0];
            Ref renamed = localGit.BranchRename().SetOldName(remoteBranch.GetName()).SetNewName
                              ("newRemote").Call();

            NUnit.Framework.Assert.AreEqual(Constants.R_REMOTES + "newRemote", renamed.GetName
                                                ());
        }
Ejemplo n.º 9
0
        public virtual void TestListAllBranchesShouldNotDie()
        {
            Git git = SetUpRepoWithRemote();

            git.BranchList().SetListMode(ListBranchCommand.ListMode.ALL).Call();
        }