コード例 #1
0
ファイル: GitUtil.cs プロジェクト: zendbit/monodevelop
        public static LocalGitRepository Init(string targetLocalPath, string url)
        {
            InitCommand ci = new InitCommand();

            ci.SetDirectory(targetLocalPath);
            ci.Call();
            LocalGitRepository repo = new LocalGitRepository(Path.Combine(targetLocalPath, Constants.DOT_GIT));

            string branch = Constants.R_HEADS + "master";

            RefUpdate head = repo.UpdateRef(Constants.HEAD);

            head.DisableRefLog();
            head.Link(branch);

            if (url != null)
            {
                RemoteConfig remoteConfig = new RemoteConfig(repo.GetConfig(), "origin");
                remoteConfig.AddURI(new URIish(url));

                string  dst  = Constants.R_REMOTES + remoteConfig.Name;
                RefSpec wcrs = new RefSpec();
                wcrs = wcrs.SetForceUpdate(true);
                wcrs = wcrs.SetSourceDestination(Constants.R_HEADS + "*", dst + "/*");

                remoteConfig.AddFetchRefSpec(wcrs);
                remoteConfig.Update(repo.GetConfig());
            }

            // we're setting up for a clone with a checkout
            repo.GetConfig().SetBoolean("core", null, "bare", false);

            repo.GetConfig().Save();
            return(repo);
        }
コード例 #2
0
ファイル: Releaser.cs プロジェクト: KatoStoelen/GitHubRelease
        /// <summary>
        /// Initializes the release creator.
        /// <para>
        /// The target GitHub repository is determined by the remotes of the local
        /// repository found in <paramref name="repositoryRootDirectory"/>.
        /// </para>
        /// </summary>
        /// <param name="repositoryRootDirectory">The root directory of the local git repository.</param>
        /// <param name="githubToken">A token used for GitHub API authentication.</param>
        public Releaser(DirectoryInfo repositoryRootDirectory, string githubToken)
        {
            using var localRepository = new LocalGitRepository(repositoryRootDirectory.FullName);

            _gitHubApi = new GitHubApi(
                GitHubRepository.FindByRemotes(localRepository.Remotes),
                githubToken);
        }
コード例 #3
0
        /// <summary>
        /// Initializes the release notest creator.
        /// </summary>
        /// <param name="repositoryRootDirectory">The root directory of the local git repository.</param>
        /// <param name="githubToken">A token used for GitHub API authentication.</param>
        /// <param name="configuration">The configuration to use.</param>
        public ReleaseNotesCreator(
            DirectoryInfo repositoryRootDirectory,
            string githubToken,
            ReleaseNotesConfiguration configuration)
        {
            _localRepository  = new LocalGitRepository(repositoryRootDirectory.FullName);
            _gitHubRepository = GitHubRepository.FindByRemotes(_localRepository.Remotes);
            _gitHubApi        = new GitHubApi(_gitHubRepository, githubToken);
            _configuration    = configuration;

            _configuration.EnsureValid();
        }
コード例 #4
0
        public void CurrentBranch_throws_InvalidOperationException_if_repository_is_in_detached_HEAD_state()
        {
            var commit1 = GitCommit(allowEmtpy: true);

            _ = GitCommit(allowEmtpy: true);
            Git($"checkout {commit1}");

            using var sut = new LocalGitRepository(m_WorkingDirectory);

            Action act = () => _ = sut.CurrentBranch;

            act.Should().Throw <InvalidOperationException>().WithMessage("*'detached HEAD'*");
        }