public void GetSubmoduleNamesFromDiffTest() { GitModule testModule = new GitModule("D:\\Test\\SuperProject"); // Submodule name without spaces in the name string text = "diff --git a/Externals/conemu-inside b/Externals/conemu-inside\nindex a17ea0c..b5a3d51 160000\n--- a/Externals/conemu-inside\n+++ b/Externals/conemu-inside\n@@ -1 +1 @@\n-Subproject commit a17ea0c8ebe9d8cd7e634ba44559adffe633c11d\n+Subproject commit b5a3d51777c85a9aeee534c382b5ccbb86b485d3\n"; string fileName = "Externals/conemu-inside"; GitSubmoduleStatus status = GitCommandHelpers.GetSubmoduleStatus(text, testModule, fileName); Assert.AreEqual(status.Commit, "b5a3d51777c85a9aeee534c382b5ccbb86b485d3"); Assert.AreEqual(status.Name, fileName); Assert.AreEqual(status.OldCommit, "a17ea0c8ebe9d8cd7e634ba44559adffe633c11d"); Assert.AreEqual(status.OldName, fileName); // Submodule name with spaces in the name text = "diff --git a/Assets/Core/Vehicle Physics core assets b/Assets/Core/Vehicle Physics core assets\nindex 2fb8851..0cc457d 160000\n--- a/Assets/Core/Vehicle Physics core assets\t\n+++ b/Assets/Core/Vehicle Physics core assets\t\n@@ -1 +1 @@\n-Subproject commit 2fb88514cfdc37a2708c24f71eca71c424b8d402\n+Subproject commit 0cc457d030e92f804569407c7cd39893320f9740\n"; fileName = "Assets/Core/Vehicle Physics core assets"; status = GitCommandHelpers.GetSubmoduleStatus(text, testModule, fileName); Assert.AreEqual(status.Commit, "0cc457d030e92f804569407c7cd39893320f9740"); Assert.AreEqual(status.Name, fileName); Assert.AreEqual(status.OldCommit, "2fb88514cfdc37a2708c24f71eca71c424b8d402"); Assert.AreEqual(status.OldName, fileName); }
public static string ProcessSubmoduleStatus([NotNull] GitModule module, [NotNull] GitSubmoduleStatus status) { if (module == null) { throw new ArgumentNullException("module"); } if (status == null) { throw new ArgumentNullException("status"); } GitModule gitmodule = module.GetSubmodule(status.Name); StringBuilder sb = new StringBuilder(); sb.AppendLine("Submodule " + status.Name + " Change"); sb.AppendLine(); sb.AppendLine("From:\t" + (status.OldCommit ?? "null")); CommitData oldCommitData = null; if (gitmodule.IsValidGitWorkingDir()) { string error = ""; if (status.OldCommit != null) { oldCommitData = CommitData.GetCommitData(gitmodule, status.OldCommit, ref error); } if (oldCommitData != null) { sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, oldCommitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(oldCommitData.CommitDate) + ")"); var delim = new char[] { '\n', '\r' }; var lines = oldCommitData.Body.Trim(delim).Split(new string[] { "\r\n" }, 0); foreach (var curline in lines) { sb.AppendLine("\t\t" + curline); } } } else { sb.AppendLine(); } sb.AppendLine(); string dirty = !status.IsDirty ? "" : " (dirty)"; sb.AppendLine("To:\t\t" + (status.Commit ?? "null") + dirty); CommitData commitData = null; if (gitmodule.IsValidGitWorkingDir()) { string error = ""; if (status.Commit != null) { commitData = CommitData.GetCommitData(gitmodule, status.Commit, ref error); } if (commitData != null) { sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" + GetFullDateString(commitData.CommitDate) + ")"); var delim = new char[] { '\n', '\r' }; var lines = commitData.Body.Trim(delim).Split(new string[] { "\r\n" }, 0); foreach (var curline in lines) { sb.AppendLine("\t\t" + curline); } } } 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(false); if (!String.IsNullOrEmpty(statusText)) { sb.AppendLine("\nStatus:"); sb.Append(statusText); } } string diffs = gitmodule.GetDiffFilesText(status.OldCommit, status.Commit); if (!String.IsNullOrEmpty(diffs)) { sb.AppendLine("\nDifferences:"); sb.Append(diffs); } } return(sb.ToString()); }
public static string ProcessSubmoduleStatus(GitModule module, GitSubmoduleStatus status, bool moduleIsParent = true, bool limitOutput = false) { if (module is null) { throw new ArgumentNullException(nameof(module)); } if (status is null) { throw new ArgumentNullException(nameof(status)); } GitModule gitModule = moduleIsParent ? module.GetSubmodule(status.Name) : module; var sb = new StringBuilder(); sb.AppendLine("Submodule " + status.Name + " Change"); // TEMP, will be moved in the follow up refactor ICommitDataManager commitDataManager = new CommitDataManager(() => gitModule); CommitData?oldCommitData = null; if (status.OldCommit != status.Commit) { sb.AppendLine(); sb.AppendLine("From:\t" + (status.OldCommit?.ToString() ?? "null")); // Submodule directory must exist to run commands, unknown otherwise if (gitModule.IsValidGitWorkingDir()) { if (status.OldCommit is not null) { oldCommitData = commitDataManager.GetCommitData(status.OldCommit.ToString(), out _, cache: true); } if (oldCommitData is not 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.Append(status.OldCommit != status.Commit ? "To:\t" : "Commit:\t"); sb.AppendLine((status.Commit?.ToString() ?? "null") + dirty); CommitData?commitData = null; // Submodule directory must exist to run commands, unknown otherwise if (gitModule.IsValidGitWorkingDir()) { if (status.Commit is not null) { commitData = commitDataManager.GetCommitData(status.Commit.ToString(), out _, cache: true); } if (commitData is not 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); } } if (status.OldCommit == status.Commit) { oldCommitData = commitData; } } 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(status.IsDirty ? "Dirty" : "Unknown"); break; } if (status.AddedCommits is not null && status.RemovedCommits is not 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 is not null && status.OldCommit is not null) { const int maxLimitedLines = 5; if (status.IsDirty) { string statusText = gitModule.GetStatusText(untracked: false); if (!string.IsNullOrEmpty(statusText)) { sb.AppendLine("\nStatus:"); if (limitOutput) { var txt = statusText.SplitLines(); if (txt.Length > maxLimitedLines) { statusText = new List <string>(txt).Take(maxLimitedLines).Join(Environment.NewLine) + $"{Environment.NewLine} {txt.Length - maxLimitedLines} more changes"; } } sb.Append(statusText); } } string diffs = gitModule.GetDiffFiles(status.OldCommit.ToString(), status.Commit.ToString(), nullSeparated: false); if (!string.IsNullOrEmpty(diffs)) { sb.AppendLine("\nDifferences:"); if (limitOutput) { var txt = diffs.SplitLines(); if (txt.Length > maxLimitedLines) { diffs = new List <string>(txt).Take(maxLimitedLines).Join(Environment.NewLine) + $"{Environment.NewLine} {txt.Length - maxLimitedLines} more differences"; } } sb.Append(diffs); } } return(sb.ToString()); }
public static string ProcessSubmoduleStatus([NotNull] GitModule module, [NotNull] GitSubmoduleStatus status) { if (module == null) { throw new ArgumentNullException(nameof(module)); } if (status == null) { throw new ArgumentNullException(nameof(status)); } GitModule 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.IsValidGitWorkingDir()) { 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.IsValidGitWorkingDir()) { 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()); }