fix: submodule diff missing commit message

This commit is contained in:
leo 2024-06-08 21:13:59 +08:00
parent 4ec93b9d75
commit c3cbb6d895
3 changed files with 30 additions and 8 deletions

View file

@ -587,10 +587,16 @@ namespace SourceGit.Models
public string New { get; set; } = string.Empty; public string New { get; set; } = string.Empty;
} }
public class SubmoduleRevision
{
public Commit Commit { get; set; } = null;
public string FullMessage { get; set; } = string.Empty;
}
public class SubmoduleDiff public class SubmoduleDiff
{ {
public Commit Old { get; set; } = null; public SubmoduleRevision Old { get; set; } = null;
public Commit New { get; set; } = null; public SubmoduleRevision New { get; set; } = null;
} }
public class DiffResult public class DiffResult

View file

@ -131,12 +131,12 @@ namespace SourceGit.ViewModels
if (line.Type == Models.TextDiffLineType.Added) if (line.Type == Models.TextDiffLineType.Added)
{ {
var sha = line.Content.Substring("Subproject commit ".Length); var sha = line.Content.Substring("Subproject commit ".Length);
submoduleDiff.New = new Commands.QuerySingleCommit(submoduleRoot, sha).Result() ?? new Models.Commit() { SHA = 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); var sha = line.Content.Substring("Subproject commit ".Length);
submoduleDiff.Old = new Commands.QuerySingleCommit(submoduleRoot, sha).Result() ?? new Models.Commit() { SHA = sha }; submoduleDiff.Old = QuerySubmoduleRevision(submoduleRoot, sha);
} }
} }
rs = submoduleDiff; rs = submoduleDiff;
@ -219,6 +219,22 @@ namespace SourceGit.ViewModels
return size > 0 ? (new Bitmap(stream), size) : (null, size); return size > 0 ? (new Bitmap(stream), size) : (null, size);
} }
private Models.SubmoduleRevision QuerySubmoduleRevision(string repo, string sha)
{
var commit = new Commands.QuerySingleCommit(repo, sha).Result();
if (commit != null)
{
var body = new Commands.QueryCommitFullMessage(repo, sha).Result();
return new Models.SubmoduleRevision() { Commit = commit, FullMessage = body };
}
return new Models.SubmoduleRevision()
{
Commit = new Models.Commit() { SHA = sha },
FullMessage = string.Empty,
};
}
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>() private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
{ {
".ico", ".bmp", ".jpg", ".png", ".jpeg" ".ico", ".bmp", ".jpg", ".png", ".jpeg"

View file

@ -151,9 +151,9 @@
<Border IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}"> <Border IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}">
<ContentControl Content="{Binding Old}"> <ContentControl Content="{Binding Old}">
<ContentControl.DataTemplates> <ContentControl.DataTemplates>
<DataTemplate DataType="m:Commit"> <DataTemplate DataType="m:SubmoduleRevision">
<Border Margin="0,0,0,8" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Background="{DynamicResource Brush.Window}"> <Border Margin="0,0,0,8" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Background="{DynamicResource Brush.Window}">
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" CanNavigate="False" Content="{Binding}"/> <v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" CanNavigate="False" Content="{Binding Commit}" Message="{Binding FullMessage}"/>
</Border> </Border>
</DataTemplate> </DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>
@ -167,7 +167,7 @@
<Path Width="16" Height="16" Data="{StaticResource Icons.DoubleDown}" HorizontalAlignment="Center" IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}"/> <Path Width="16" Height="16" Data="{StaticResource Icons.DoubleDown}" HorizontalAlignment="Center" IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}"/>
<Border Margin="0,8,0,0" BorderThickness="1" BorderBrush="Green" Background="{DynamicResource Brush.Window}"> <Border Margin="0,8,0,0" BorderThickness="1" BorderBrush="Green" Background="{DynamicResource Brush.Window}">
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" CanNavigate="False" Content="{Binding New}"/> <v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" CanNavigate="False" Content="{Binding New.Commit}" Message="{Binding New.FullMessage}"/>
</Border> </Border>
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
@ -239,7 +239,7 @@
UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"/> UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"/>
</DataTemplate> </DataTemplate>
<!-- No or only EOL changes --> <!-- Empty or only EOL changes -->
<DataTemplate DataType="m:NoOrEOLChange"> <DataTemplate DataType="m:NoOrEOLChange">
<StackPanel Orientation="Vertical" VerticalAlignment="Center"> <StackPanel Orientation="Vertical" VerticalAlignment="Center">
<Path Width="64" Height="64" Data="{StaticResource Icons.Check}" Fill="{DynamicResource Brush.FG2}"/> <Path Width="64" Height="64" Data="{StaticResource Icons.Check}" Fill="{DynamicResource Brush.FG2}"/>