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()); }
public override async Task TagAsync(string tag) { var args = new GitArgumentsBuilder("tag -f"); args.Append(tag); await this.ExecuteCommandLineAsync(args, this.repository.LocalRepositoryPath).ConfigureAwait(false); var pushArgs = new GitArgumentsBuilder("push"); pushArgs.AppendSensitive(this.repository.GetRemoteUrlWithCredentials()); pushArgs.Append("--tags --quiet"); await this.ExecuteCommandLineAsync(pushArgs, this.repository.LocalRepositoryPath).ConfigureAwait(false); }
public override async Task <IEnumerable <string> > EnumerateRemoteBranchesAsync() { var args = new GitArgumentsBuilder("ls-remote --refs --heads"); args.AppendSensitive(this.repository.GetRemoteUrlWithCredentials()); var result = await this.ExecuteCommandLineAsync(args, this.repository.LocalRepositoryPath, false).ConfigureAwait(false); var branches = from o in result.Output let value = BranchParsingRegex.Match(o).Groups["branch"].Value where !string.IsNullOrEmpty(value) select value; return(branches); }
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); }
public override async Task <IEnumerable <RemoteBranchInfo> > EnumerateRemoteBranchesAsync() { var args = new GitArgumentsBuilder("ls-remote --refs --heads"); args.AppendSensitive(this.repository.GetRemoteUrlWithCredentials()); var result = await this.ExecuteCommandLineAsync(args, null, false).ConfigureAwait(false); var branches = new List <RemoteBranchInfo>(); foreach (var o in result.Output) { var match = BranchParsingRegex.Match(o); if (match.Success) { branches.Add(new RemoteBranchInfo(match.Groups[2].Value, match.Groups[1].Value)); } } return(branches); }