コード例 #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);
     }
 }