mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
enhance: better implementation to diff submodule changes while repository is not opened
This commit is contained in:
parent
7f389b2e6f
commit
f08acebb5e
1 changed files with 18 additions and 11 deletions
|
@ -111,27 +111,34 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
if (latest.TextDiff != null)
|
if (latest.TextDiff != null)
|
||||||
{
|
{
|
||||||
var repo = App.FindOpenedRepository(_repo);
|
var count = latest.TextDiff.Lines.Count;
|
||||||
if (repo != null && repo.Submodules.Contains(_option.Path))
|
var isSubmodule = false;
|
||||||
|
if (count <= 3)
|
||||||
{
|
{
|
||||||
var submoduleDiff = new Models.SubmoduleDiff();
|
var submoduleDiff = new Models.SubmoduleDiff();
|
||||||
var submoduleRoot = $"{_repo}/{_option.Path}".Replace("\\", "/");
|
var submoduleRoot = $"{_repo}/{_option.Path}".Replace("\\", "/");
|
||||||
foreach (var line in latest.TextDiff.Lines)
|
isSubmodule = true;
|
||||||
|
for (int i = 1; i < count; i++)
|
||||||
{
|
{
|
||||||
|
var line = latest.TextDiff.Lines[i];
|
||||||
|
if (!line.Content.StartsWith("Subproject commit ", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
isSubmodule = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sha = line.Content.Substring(18);
|
||||||
if (line.Type == Models.TextDiffLineType.Added)
|
if (line.Type == Models.TextDiffLineType.Added)
|
||||||
{
|
|
||||||
var sha = line.Content.Substring("Subproject commit ".Length);
|
|
||||||
submoduleDiff.New = QuerySubmoduleRevision(submoduleRoot, sha);
|
submoduleDiff.New = QuerySubmoduleRevision(submoduleRoot, sha);
|
||||||
}
|
|
||||||
else if (line.Type == Models.TextDiffLineType.Deleted)
|
else if (line.Type == Models.TextDiffLineType.Deleted)
|
||||||
{
|
|
||||||
var sha = line.Content.Substring("Subproject commit ".Length);
|
|
||||||
submoduleDiff.Old = QuerySubmoduleRevision(submoduleRoot, sha);
|
submoduleDiff.Old = QuerySubmoduleRevision(submoduleRoot, sha);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rs = submoduleDiff;
|
|
||||||
|
if (isSubmodule)
|
||||||
|
rs = submoduleDiff;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!isSubmodule)
|
||||||
{
|
{
|
||||||
latest.TextDiff.File = _option.Path;
|
latest.TextDiff.File = _option.Path;
|
||||||
rs = latest.TextDiff;
|
rs = latest.TextDiff;
|
||||||
|
|
Loading…
Reference in a new issue