public void CheckSubmoduleStatus(VsrModule submodule) { if (submodule == null) { Status = SubmoduleStatus.NewSubmodule; return; } Status = submodule.CheckSubmoduleStatus(Commit, OldCommit); }
public static string ProcessSubmoduleStatus([NotNull] VsrModule module, [NotNull] GitSubmoduleStatus status) { if (module == null) { throw new ArgumentNullException(nameof(module)); } if (status == null) { throw new ArgumentNullException(nameof(status)); } VsrModule gitModule = module.GetSubmodule(status.Name); var sb = new StringBuilder(); sb.AppendLine("Submodule " + status.Name + " Change"); // TEMP, will be moved in the follow up refactor ICommitDataManager commitDataManager = new CommitDataManager(() => gitModule); sb.AppendLine(); sb.AppendLine("From:\t" + (status.OldCommit?.ToString() ?? "null")); CommitData oldCommitData = null; // TODO File access for Git revision access if (gitModule.IsValidVersionrWorkingDir()) { if (status.OldCommit != null) { oldCommitData = commitDataManager.GetCommitData(status.OldCommit.ToString(), out _); } if (oldCommitData != null) { sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, oldCommitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(oldCommitData.CommitDate) + ")"); var delimiter = new[] { '\n', '\r' }; var lines = oldCommitData.Body.Trim(delimiter).Split(new[] { "\r\n" }, 0); foreach (var line in lines) { sb.AppendLine("\t\t" + line); } } } else { sb.AppendLine(); } sb.AppendLine(); string dirty = !status.IsDirty ? "" : " (dirty)"; sb.AppendLine("To:\t\t" + (status.Commit?.ToString() ?? "null") + dirty); CommitData commitData = null; // TODO File access for Git revision access if (gitModule.IsValidVersionrWorkingDir()) { if (status.Commit != null) { commitData = commitDataManager.GetCommitData(status.Commit.ToString(), out _); } if (commitData != null) { sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(commitData.CommitDate) + ")"); var delimiter = new[] { '\n', '\r' }; var lines = commitData.Body.Trim(delimiter).Split(new[] { "\r\n" }, 0); foreach (var line in lines) { sb.AppendLine("\t\t" + line); } } } else { sb.AppendLine(); } sb.AppendLine(); var submoduleStatus = gitModule.CheckSubmoduleStatus(status.Commit, status.OldCommit, commitData, oldCommitData); sb.Append("Type: "); switch (submoduleStatus) { case SubmoduleStatus.NewSubmodule: sb.AppendLine("New submodule"); break; case SubmoduleStatus.FastForward: sb.AppendLine("Fast Forward"); break; case SubmoduleStatus.Rewind: sb.AppendLine("Rewind"); break; case SubmoduleStatus.NewerTime: sb.AppendLine("Newer commit time"); break; case SubmoduleStatus.OlderTime: sb.AppendLine("Older commit time"); break; case SubmoduleStatus.SameTime: sb.AppendLine("Same commit time"); break; default: sb.AppendLine("Unknown"); break; } if (status.AddedCommits != null && status.RemovedCommits != null && (status.AddedCommits != 0 || status.RemovedCommits != 0)) { sb.Append("\nCommits: "); if (status.RemovedCommits > 0) { sb.Append(status.RemovedCommits + " removed"); if (status.AddedCommits > 0) { sb.Append(", "); } } if (status.AddedCommits > 0) { sb.Append(status.AddedCommits + " added"); } sb.AppendLine(); } if (status.Commit != null && status.OldCommit != null) { if (status.IsDirty) { string statusText = gitModule.GetStatusText(untracked: false); if (!string.IsNullOrEmpty(statusText)) { sb.AppendLine("\nStatus:"); sb.Append(statusText); } } string diffs = gitModule.GetDiffFilesText(status.OldCommit.ToString(), status.Commit.ToString()); if (!string.IsNullOrEmpty(diffs)) { sb.AppendLine("\nDifferences:"); sb.Append(diffs); } } return(sb.ToString()); }