//public async Task<R<string>> GetCommitDiffAsync(string sha, CancellationToken ct) //{ // R<CmdResult2> result = await gitCmdService.RunAsync( // $"show --patch --root {sha}", ct); // if (result.IsFaulted) // { // return Error.From($"Failed to get commit diff for {sha}", result); // } // Log.Info($"Got path for {sha}"); // return R.From(result.Value.Output); //} public async Task <R <string> > GetCommitDiffAsync(string sha, CancellationToken ct) { CmdResult2 result = await gitCmdService.RunCmdAsync( $"diff --patch --find-renames --unified=6 --root {sha}^..{sha}", ct); if (result.IsFaulted) { if (result.Error.StartsWith("fatal: ambiguous argument")) { // Failed to get diff for sha, might be root commit, so try again CmdResult2 showRootResult = await gitCmdService.RunCmdAsync( $"show --patch --root {sha}", ct); if (showRootResult.IsOk) { Log.Info($"Got diff patch for root {sha}"); return(R.From(showRootResult.Output)); } } return(R.Error($"Failed to get commit diff for {sha}", result.AsException())); } Log.Info($"Got diff patch for {sha}"); return(R.From(result.Output)); }
public async Task <R> UndoUncommittedFileAsync(string path, CancellationToken ct) { CmdResult2 result = await gitCmdService.RunCmdAsync( $"checkout --force -- \"{path}\"", CancellationToken.None); if (result.IsFaulted) { if (IsFileUnkwon(result, path)) { R deleteResult = DeleteFile(path, result); if (deleteResult.IsFaulted) { return(R.Error($"Failed to delete {path}", deleteResult.Exception)); } Log.Info($"Undid file {path}"); return(R.Ok); } return(R.Error($"Failed to undo file {path}", result.AsException())); } Log.Info($"Undid file {path}"); return(R.Ok); }
public async Task <R <IReadOnlyList <GitTag> > > GetAllTagsAsync(CancellationToken ct) { CmdResult2 result = await gitCmdService.RunCmdAsync("show-ref -d --tags", ct); if (result.IsFaulted) { if (!(result.ExitCode == 1 && string.IsNullOrEmpty(result.Output))) { return(R.Error("Failed to list tags", result.AsException())); } } IReadOnlyList <GitTag> tags = ParseTags(result); Log.Info($"Got {tags.Count} tags"); return(R.From(tags)); }
public async Task <R> MergeAsync(string name, CancellationToken ct) { CmdResult2 result = await gitCmdService.RunCmdAsync( $"merge --no-ff --no-commit --stat --progress {name}", ct); if (result.IsFaulted) { if (result.ExitCode == 1 && IsConflicts(result)) { Log.Info($"Merge of {name} resulted in conflict(s)"); return(R.Ok); } return(R.Error($"Failed to merge branch {name}", result.AsException())); } Log.Info($"Merge of {name} was OK"); return(R.Ok); }
public async Task <R <string> > GetNoteAsync(string sha, string notesRef, CancellationToken ct) { CmdResult2 result = await gitCmdService.RunCmdAsync( $"-c core.notesRef={notesRef} notes show {sha}", ct); if (result.IsFaulted) { if (result.ExitCode == 1 && result.Error.StartsWith($"error: no note found for object {sha}")) { return(R.NoValue); } return(R.Error("Failed to get note", result.AsException())); } string notes = result.Output; Log.Info($"Got note {notes.Length} length"); return(notes); }
public async Task <R <bool> > TryCheckoutAsync(string name, CancellationToken ct) { CmdResult2 result = await gitCmdService.RunCmdAsync($"checkout --progress {name}", ct); if (result.IsFaulted) { if (IsUnknownName(result, name)) { Log.Info($"Unknown name: {name}"); return(false); } return(R.Error($"Failed to checkout {name}", result.AsException())); } Log.Info($"Checked out {name}"); return(true); }
public async Task <R> PushAsync(CancellationToken ct) { CmdResult2 result = await gitCmdService.RunCmdAsync(PushArgs, ct); if (result.IsFaulted) { if (IsNoRemoteBranch(result)) { return(R.Ok); } return(R.Error("Failed to push", result.AsException())); } return(R.Ok); }
public async Task <R> GetLogAsync(Action <GitCommit> commits, CancellationToken ct) { int count = 0; void OutputLines(string line) { if (!ct.IsCancellationRequested) { count++; commits(Parse(line)); } } CmdResult2 result = await gitCmdService.RunCmdAsync($"log --all --pretty=\"{LogFormat}\"", OutputLines, ct); if (result.IsFaulted && !ct.IsCancellationRequested) { return(R.Error("Failed to get log", result.AsException())); } Log.Info($"Got log for {count} commits"); return(R.Ok); }