private string GetGitRepositoryOrigin(GitRepositoryInfo gitRepositoryInfo)
        {
            var configFileText = gitRepositoryInfo.ReadConfigFile();

            // IDEA: Parse .INI and use '[remote "origin"]'
            return(Regex.Matches(configFileText, @"\bhttps?://.+\b").Cast <Match>().Select(x => x.Value).FirstOrDefault());
        }
Ejemplo n.º 2
0
        public BlockchainNode(ClientNodeConfig nodeConfig)
        {
            NodeState         = new BlockchainNodeState(nodeConfig.NodeEndpoint);
            GitRepositoryInfo = new GitRepositoryInfo(nodeConfig.CodeDirectory);
            NodeConfig        = nodeConfig;

            NodeEndpoint = nodeConfig.NodeEndpoint;
        }
Ejemplo n.º 3
0
        public void StripUsernameAndPasswordDoesNothingIfNoUserInfo()
        {
            Uri before = new Uri("https://github.com/organization/repo.git");

            Uri after = GitRepositoryInfo.StripUsernameAndPassword(before);

            after.ShouldBeSameAs(before);
        }
Ejemplo n.º 4
0
        public void StripUsernameAndPassword(string userInfo)
        {
            Uri before = new Uri($"https://{userInfo}github.com/organization/repo.git");

            Uri after = GitRepositoryInfo.StripUsernameAndPassword(before);

            after.UserInfo.ShouldBeEmpty();
        }
Ejemplo n.º 5
0
        public async override Task <object> ExecuteAsync(CancellationToken cancellationToken)
        {
            GitRepositoryInfo repo;

            if (!string.IsNullOrEmpty(this.Context.LocalRepositoryPath))
            {
                repo = new GitRepositoryInfo(
                    new WorkspacePath(this.Context.LocalRepositoryPath),
                    this.Context.RemoteRepositoryUrl,
                    this.Context.UserName,
                    AH.CreateSecureString(this.Context.Password)
                    );
            }
            else
            {
                repo = new GitRepositoryInfo(
                    this.Context.RemoteRepositoryUrl,
                    this.Context.UserName,
                    AH.CreateSecureString(this.Context.Password)
                    );
            }

            var client = new LibGitSharpClient(repo, this);

            switch (this.Command)
            {
            case ClientCommand.Archive:
                await client.ArchiveAsync(this.Context.TargetDirectory, this.Context.KeepInternals).ConfigureAwait(false);

                return(null);

            case ClientCommand.Clone:
                await client.CloneAsync(this.Context.CloneOptions).ConfigureAwait(false);

                return(null);

            case ClientCommand.EnumerateRemoteBranches:
                return((await client.EnumerateRemoteBranchesAsync().ConfigureAwait(false)).ToArray());

            case ClientCommand.IsRepositoryValid:
                return(await client.IsRepositoryValidAsync().ConfigureAwait(false));

            case ClientCommand.Tag:
                await client.TagAsync(this.Context.Tag, this.Context.Commit, this.Context.TagMessage, this.Context.Force).ConfigureAwait(false);

                return(null);

            case ClientCommand.Update:
                return(await client.UpdateAsync(this.Context.UpdateOptions).ConfigureAwait(false));

            default:
                throw new InvalidOperationException("Invalid remote LibGitSharp job type: " + this.Command);
            }
        }
Ejemplo n.º 6
0
        private GitClient CreateClient(ClientType type, string workingDirectory)
        {
            var repo = new GitRepositoryInfo(new WorkspacePath(workingDirectory), repoUrl, this.userName, this.password);

            if (type == ClientType.CommandLine)
            {
                return(new GitCommandLineClient(gitExePath, this.processExecuter, this.fileOps, repo, TestLogger.Instance, CancellationToken.None));
            }
            else if (type == ClientType.LibGitSharp)
            {
                return(new LibGitSharpClient(repo, TestLogger.Instance));
            }
            else
            {
                return(new RemoteLibGitSharpClient(this.jobExecuter, workingDirectory, false, CancellationToken.None, repo, TestLogger.Instance));
            }
        }
Ejemplo n.º 7
0
        public async override Task <object> ExecuteAsync(CancellationToken cancellationToken)
        {
            var repo = new GitRepositoryInfo(
                new WorkspacePath(this.Context.LocalRepositoryPath),
                this.Context.RemoteRepositoryUrl,
                this.Context.UserName,
                this.Context.Password != null ? this.Context.Password.ToSecureString() : null
                );

            var client = new LibGitSharpClient(repo, this);

            switch (this.Command)
            {
            case ClientCommand.Archive:
                await client.ArchiveAsync(this.Context.TargetDirectory).ConfigureAwait(false);

                return(null);

            case ClientCommand.Clone:
                await client.CloneAsync(this.Context.CloneOptions).ConfigureAwait(false);

                return(null);

            case ClientCommand.EnumerateRemoteBranches:
                return((await client.EnumerateRemoteBranchesAsync().ConfigureAwait(false)).ToArray());

            case ClientCommand.IsRepositoryValid:
                return(await client.IsRepositoryValidAsync().ConfigureAwait(false));

            case ClientCommand.Tag:
                await client.TagAsync(this.Context.Tag);

                return(null);

            case ClientCommand.Update:
                await client.UpdateAsync(this.Context.UpdateOptions);

                return(null);

            default:
                throw new InvalidOperationException("Invalid remote LibGitSharp job type: " + this.Command);
            }
        }
Ejemplo n.º 8
0
        public GitCommandLineClient(string gitExePath, IRemoteProcessExecuter processExecuter, IFileOperationsExecuter fileOps, GitRepositoryInfo repository, ILogSink log, CancellationToken cancellationToken)
            : base(repository, log)
        {
            if (gitExePath == null)
            {
                throw new ArgumentNullException(nameof(gitExePath));
            }
            if (processExecuter == null)
            {
                throw new ArgumentNullException(nameof(processExecuter));
            }
            if (fileOps == null)
            {
                throw new ArgumentNullException(nameof(fileOps));
            }

            this.gitExePath        = gitExePath;
            this.processExecuter   = processExecuter;
            this.fileOps           = fileOps;
            this.cancellationToken = cancellationToken;
        }
Ejemplo n.º 9
0
 public LibGitSharpClient(GitRepositoryInfo repository, ILogger log)
     : base(repository, log)
 {
 }
Ejemplo n.º 10
0
 public GitRepository(string codeDirectoryFullName) : this()
 {
     Info = new GitRepositoryInfo(codeDirectoryFullName);
     RefreshGitRepositoryInfo();
 }
Ejemplo n.º 11
0
        public RemoteLibGitSharpClient(IRemoteJobExecuter jobExecuter, string workingDirectory, bool simulation, CancellationToken cancellationToken, GitRepositoryInfo repository, ILogger log)
            : base(repository, log)
        {
            if (jobExecuter == null)
            {
                throw new NotSupportedException("A hosted agent must be used with the built-in LibGitSharp git client.");
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(WorkspacePath));
            }

            this.jobExecuter       = jobExecuter;
            this.workingDirectory  = workingDirectory;
            this.simulation        = simulation;
            this.cancellationToken = cancellationToken;
        }
Ejemplo n.º 12
0
 public RemoteLibGitSharpClient(IRemoteJobExecuter jobExecuter, string workingDirectory, bool simulation, CancellationToken cancellationToken, GitRepositoryInfo repository, ILogSink log)
     : base(repository, log)
 {
     this.jobExecuter       = jobExecuter ?? throw new NotSupportedException("A hosted agent must be used with the built-in LibGitSharp git client.");
     this.workingDirectory  = workingDirectory;
     this.simulation        = simulation;
     this.cancellationToken = cancellationToken;
 }