Improve Checking out older commits

This commit is contained in:
Canon
2026-02-10 18:11:14 +08:00
parent 4af07f329f
commit 2d7e0c66c5
3 changed files with 63 additions and 15 deletions
+10
View File
@@ -174,6 +174,16 @@ public partial class GitService : IGitService
return true;
}
public async Task<bool> ResetToCommitAsync(string path, string commitHash, CancellationToken ct = default)
{
var (exitCode, _, _) = await RunGitCommandAsync(path, $"reset --hard \"{commitHash}\"", ct);
if (exitCode != 0)
return false;
await RunGitCommandAsync(path, "submodule update --init --recursive", ct);
return true;
}
public async Task<bool> HasLocalChangesAsync(string path, CancellationToken ct = default)
{
var (exitCode, output, _) = await RunGitCommandAsync(path, "status --porcelain", ct);
+1
View File
@@ -15,6 +15,7 @@ public interface IGitService
Task<bool> CloneAsync(string url, string targetPath, IProgress<string>? progress = null, IProgress<double>? percentProgress = null, CancellationToken ct = default);
Task<IReadOnlyList<string>> GetRemoteBranchesAsync(string path, CancellationToken ct = default);
Task<bool> CheckoutAsync(string path, string branchOrCommit, CancellationToken ct = default);
Task<bool> ResetToCommitAsync(string path, string commitHash, CancellationToken ct = default);
Task<bool> HasLocalChangesAsync(string path, CancellationToken ct = default);
Task<IReadOnlyList<GitCommitInfo>> GetCommitHistoryAsync(string path, int limit = 20, CancellationToken ct = default);
}