Skip to content

Commit 4516b00

Browse files
committed
enhance: handle binary file in built-in merge tool
Signed-off-by: leo <longshuang@msn.cn>
1 parent 52da016 commit 4516b00

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@
938938
<x:String x:Key="Text.WorkingCopy.ConfirmCommitWithFilter">You have staged {0} file(s) but only {1} file(s) displayed ({2} files are filtered out). Do you want to continue?</x:String>
939939
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">CONFLICTS DETECTED</x:String>
940940
<x:String x:Key="Text.WorkingCopy.Conflicts.Merge" xml:space="preserve">MERGE</x:String>
941-
<x:String x:Key="Text.WorkingCopy.Conflicts.MergeExternal" xml:space="preserve">OPEN EXTERNAL MERGETOOL</x:String>
941+
<x:String x:Key="Text.WorkingCopy.Conflicts.MergeExternal" xml:space="preserve">Merge with External Tool</x:String>
942942
<x:String x:Key="Text.WorkingCopy.Conflicts.OpenExternalMergeToolAllConflicts" xml:space="preserve">OPEN ALL CONFLICTS IN EXTERNAL MERGETOOL</x:String>
943943
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">FILE CONFLICTS ARE RESOLVED</x:String>
944944
<x:String x:Key="Text.WorkingCopy.Conflicts.UseMine" xml:space="preserve">USE MINE</x:String>

src/ViewModels/MergeConflictEditor.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public bool IsLoading
7373
private set => SetProperty(ref _isLoading, value);
7474
}
7575

76+
public string Error
77+
{
78+
get => _error;
79+
private set => SetProperty(ref _error, value);
80+
}
81+
7682
public List<Models.TextDiffLine> OursDiffLines
7783
{
7884
get => _oursDiffLines;
@@ -156,15 +162,13 @@ public async Task LoadAsync()
156162

157163
try
158164
{
159-
var repoPath = _repo.FullPath;
160-
161-
// Read working copy with conflict markers
162-
var workingCopyPath = Path.Combine(repoPath, _filePath);
165+
var workingCopyPath = Path.Combine(_repo.FullPath, _filePath);
163166
var workingCopyContent = string.Empty;
164167
if (File.Exists(workingCopyPath))
165-
{
166168
workingCopyContent = await File.ReadAllTextAsync(workingCopyPath).ConfigureAwait(false);
167-
}
169+
170+
if (workingCopyContent.IndexOf('\0', StringComparison.Ordinal) >= 0)
171+
throw new Exception("Binary file is not supported!!!");
168172

169173
Dispatcher.UIThread.Post(() =>
170174
{
@@ -183,8 +187,8 @@ public async Task LoadAsync()
183187
{
184188
Dispatcher.UIThread.Post(() =>
185189
{
186-
App.RaiseException(_repo.FullPath, $"Failed to load conflict data: {ex.Message}");
187190
IsLoading = false;
191+
Error = ex.Message;
188192
});
189193
}
190194
}
@@ -969,5 +973,6 @@ private void RebuildResultContent()
969973
private List<MergeConflictLineType> _lineTypes = [];
970974
private Vector _scrollOffset = Vector.Zero;
971975
private MergeConflictSelectedChunk _selectedChunk;
976+
private string _error = string.Empty;
972977
}
973978
}

src/Views/MergeConflictEditor.axaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@
198198
Click="OnUseTheirs"/>
199199
<Button Classes="flat primary">
200200
<StackPanel Orientation="Horizontal" Spacing="4">
201-
<TextBlock Text="{DynamicResource Text.MergeConflictEditor.UseBoth}"/>
202-
<Path Width="12" Height="12" Margin="4,4,0,0" Data="{StaticResource Icons.Down}"/>
201+
<TextBlock Text="{DynamicResource Text.MergeConflictEditor.UseBoth}" Foreground="White"/>
202+
<Path Width="12" Height="12" Margin="4,4,0,0" Data="{StaticResource Icons.Down}" Fill="White"/>
203203
</StackPanel>
204204
<Button.Flyout>
205205
<MenuFlyout Placement="BottomEdgeAlignedLeft">
@@ -242,5 +242,23 @@
242242
</Grid>
243243
</Border>
244244
</Grid>
245+
246+
<!-- Error -->
247+
<Border Grid.Row="2"
248+
Background="{DynamicResource Brush.Popup}"
249+
Padding="16"
250+
CornerRadius="6"
251+
HorizontalAlignment="Center" VerticalAlignment="Center"
252+
Effect="drop-shadow(0 0 12 #60000000)"
253+
IsVisible="{Binding Error, Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
254+
<StackPanel Orientation="Vertical">
255+
<Path Width="28" Height="28" Data="{StaticResource Icons.Error}"/>
256+
<TextBlock Text="{Binding Error, Mode=OneWay}"
257+
MaxWidth="500"
258+
Margin="0,12,0,0"
259+
FontSize="16"
260+
TextWrapping="Wrap"/>
261+
</StackPanel>
262+
</Border>
245263
</Grid>
246264
</v:ChromelessWindow>

0 commit comments

Comments
 (0)