コード例 #1
0
ファイル: BranchCommandTest.cs プロジェクト: shoff/ngit
        /// <exception cref="System.Exception"></exception>
        private Git SetUpRepoWithRemote()
        {
            Repository remoteRepository = CreateWorkRepository();
            Git        remoteGit        = new Git(remoteRepository);

            // commit something
            WriteTrashFile("Test.txt", "Hello world");
            remoteGit.Add().AddFilepattern("Test.txt").Call();
            initialCommit = remoteGit.Commit().SetMessage("Initial commit").Call();
            WriteTrashFile("Test.txt", "Some change");
            remoteGit.Add().AddFilepattern("Test.txt").Call();
            secondCommit = remoteGit.Commit().SetMessage("Second commit").Call();
            // create a master branch
            RefUpdate rup = remoteRepository.UpdateRef("refs/heads/master");

            rup.SetNewObjectId(initialCommit.Id);
            rup.ForceUpdate();
            Repository   localRepository = CreateWorkRepository();
            Git          localGit        = new Git(localRepository);
            StoredConfig config          = localRepository.GetConfig();
            RemoteConfig rc = new RemoteConfig(config, "origin");

            rc.AddURI(new URIish(remoteRepository.Directory.GetPath()));
            rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
            rc.Update(config);
            config.Save();
            FetchResult res = localGit.Fetch().SetRemote("origin").Call();

            NUnit.Framework.Assert.IsFalse(res.GetTrackingRefUpdates().IsEmpty());
            rup = localRepository.UpdateRef("refs/heads/master");
            rup.SetNewObjectId(initialCommit.Id);
            rup.ForceUpdate();
            rup = localRepository.UpdateRef(Constants.HEAD);
            rup.Link("refs/heads/master");
            rup.SetNewObjectId(initialCommit.Id);
            rup.Update();
            return(localGit);
        }