using MarketAlly.GitCommitEditor.Resources; namespace MarketAlly.GitCommitEditor.Models; /// /// Safety information for a batch rewrite operation. /// public sealed class RewriteSafetyInfo { /// /// Whether the repository has uncommitted changes. /// public bool HasUncommittedChanges { get; init; } /// /// Whether any commits to be rewritten have been pushed to remote. /// public bool HasPushedCommits { get; init; } /// /// Number of commits that have been pushed to remote. /// public int PushedCommitCount { get; init; } /// /// Number of commits that are local only. /// public int LocalOnlyCommitCount { get; init; } /// /// Total commits to be rewritten. /// public int TotalCommitCount { get; init; } /// /// Whether the current branch tracks a remote branch. /// public bool HasRemoteTracking { get; init; } /// /// The remote tracking branch name, if any. /// public string? RemoteTrackingBranch { get; init; } /// /// Number of commits ahead of remote. /// public int? AheadOfRemote { get; init; } /// /// Number of commits behind remote. /// public int? BehindRemote { get; init; } /// /// Whether a backup branch was created. /// public bool BackupBranchCreated { get; init; } /// /// Name of the backup branch, if created. /// public string? BackupBranchName { get; init; } /// /// Whether the operation can proceed safely. /// public bool CanProceedSafely => !HasUncommittedChanges && !HasPushedCommits; /// /// Whether the operation can proceed with warnings. /// public bool CanProceedWithWarnings => !HasUncommittedChanges; /// /// Gets warning messages based on the safety info. /// public IReadOnlyList GetWarnings() { var warnings = new List(); if (HasUncommittedChanges) { warnings.Add(Str.Safety_UncommittedChanges); } if (HasPushedCommits) { warnings.Add(Str.Safety_PushedCommits(PushedCommitCount)); } if (BehindRemote > 0) { warnings.Add(Str.Safety_BehindRemote(BehindRemote.Value)); } return warnings; } /// /// Gets a summary description of the operation. /// public string GetSummary() { var parts = new List(); if (LocalOnlyCommitCount > 0) { parts.Add($"{LocalOnlyCommitCount} local commit(s)"); } if (PushedCommitCount > 0) { parts.Add($"{PushedCommitCount} pushed commit(s)"); } return string.Join(" and ", parts) + " will be rewritten."; } } /// /// Result of a batch rewrite execute operation. /// public sealed class BatchRewriteResult { /// /// Whether the overall operation succeeded. /// public bool Success { get; init; } /// /// Number of commits successfully rewritten. /// public int SuccessCount { get; init; } /// /// Number of commits that failed to rewrite. /// public int FailedCount { get; init; } /// /// Number of commits skipped. /// public int SkippedCount { get; init; } /// /// Error message if the operation failed. /// public string? ErrorMessage { get; init; } /// /// Whether a force push is required. /// public bool RequiresForcePush { get; init; } /// /// The backup branch name if one was created. /// public string? BackupBranchName { get; init; } /// /// Individual operation results. /// public IReadOnlyList Operations { get; init; } = []; public static BatchRewriteResult Failure(string error) => new() { Success = false, ErrorMessage = error }; }