Exemple #1
0
        public override async Task <string> UpdateAsync(GitUpdateOptions options)
        {
            /*
             *  git remote set-url origin <url>         | Make sure we're talking to the correct remote repository
             *  git fetch origin                        | Update the local cache of the remote repository
             *  git reset --hard <ref>                  | Resets to the HEAD revision and removes commits that haven't been pushed
             *  git clean -dfq                          | Remove all non-Git versioned files and directories from the repository working directory
             *  git submodule update --init --recursive | Updates submodules to the version referenced by the HEAD revision
             */

            var remoteArgs = new GitArgumentsBuilder("remote set-url origin");

            remoteArgs.AppendSensitive(this.repository.GetRemoteUrlWithCredentials());
            await this.ExecuteCommandLineAsync(remoteArgs, this.repository.LocalRepositoryPath).ConfigureAwait(false);

            await this.ExecuteCommandLineAsync(new GitArgumentsBuilder("fetch origin"), this.repository.LocalRepositoryPath).ConfigureAwait(false);

            var resetArgs = new GitArgumentsBuilder("reset --hard");

            if (options.Ref != null)
            {
                resetArgs.AppendQuoted(options.Ref);
            }
            else if (options.Branch != null)
            {
                resetArgs.AppendQuoted("origin/" + options.Branch);
            }
            else
            {
                resetArgs.Append("FETCH_HEAD");
            }

            await this.ExecuteCommandLineAsync(
                resetArgs,
                this.repository.LocalRepositoryPath
                ).ConfigureAwait(false);

            await this.ExecuteCommandLineAsync(
                new GitArgumentsBuilder("clean -dfq"),
                this.repository.LocalRepositoryPath
                ).ConfigureAwait(false);

            if (options.RecurseSubmodules)
            {
                await this.ExecuteCommandLineAsync(
                    new GitArgumentsBuilder("submodule update --init --recursive"),
                    this.repository.LocalRepositoryPath
                    ).ConfigureAwait(false);
            }

            var results = await this.ExecuteCommandLineAsync(
                new GitArgumentsBuilder("log -n 1 --format=%H"),
                this.repository.LocalRepositoryPath
                ).ConfigureAwait(false);

            return(string.Join(" ", results.Output).Trim());
        }
Exemple #2
0
        public override async Task CloneAsync(GitCloneOptions options)
        {
            var args = new GitArgumentsBuilder("clone");

            if (options.Branch != null)
            {
                args.Append("-b");
                args.AppendQuoted(options.Branch);
            }
            if (options.RecurseSubmodules)
            {
                args.Append("--recursive");
            }

            args.AppendSensitive(this.repository.GetRemoteUrlWithCredentials());
            args.AppendQuoted(this.repository.LocalRepositoryPath);

            await this.ExecuteCommandLineAsync(args, this.repository.LocalRepositoryPath).ConfigureAwait(false);
        }
Exemple #3
0
        public override async Task TagAsync(string tag, string commit, string message, bool force = false)
        {
            var args = new GitArgumentsBuilder("tag");

            if (force)
            {
                args.Append("-f");
            }
            if (!string.IsNullOrEmpty(message))
            {
                args.Append("-a");
                args.AppendQuoted(tag);
                args.Append("-m");
                args.AppendQuoted(message);
            }
            else
            {
                args.AppendQuoted(tag);
            }

            if (!string.IsNullOrEmpty(commit))
            {
                args.AppendQuoted(commit);
            }

            await this.ExecuteCommandLineAsync(args, this.repository.LocalRepositoryPath).ConfigureAwait(false);

            var pushArgs = new GitArgumentsBuilder("push origin");

            pushArgs.AppendQuoted(tag);
            pushArgs.Append("--quiet");
            if (force)
            {
                pushArgs.Append("--force");
            }

            await this.ExecuteCommandLineAsync(pushArgs, this.repository.LocalRepositoryPath).ConfigureAwait(false);
        }