1
0

fix: 无法正确唤起Merge的问题

This commit is contained in:
Ca2didi 2025-05-21 01:36:38 +08:00
parent 3afafd4e91
commit ef1395945f
6 changed files with 94 additions and 98 deletions

View File

@ -8,7 +8,7 @@ public enum RepositoryResetMethod
Keep,
/// <summary>
/// Tracked files will being reset, changes will being reset.
/// Tracked files will being reset, changes will being merged.
/// </summary>
Soft,
@ -16,14 +16,4 @@ public enum RepositoryResetMethod
/// All files will being reset, changes will being reset, changes list will being cleaned.
/// </summary>
Hard,
/// <summary>
/// Tracked files will being reset, changes will being merged.
/// </summary>
Merge,
/// <summary>
/// All files will being reset, changes will being merged.
/// </summary>
HardMerge
}

View File

@ -837,9 +837,9 @@ public class RepositoryService : BaseService<RepositoryService>
try
{
var mergeChanges = method is RepositoryResetMethod.Merge or RepositoryResetMethod.HardMerge;
var mergeChanges = method is RepositoryResetMethod.Soft;
var resetChanges = method is RepositoryResetMethod.Soft or RepositoryResetMethod.Hard;
var hardMode = method is RepositoryResetMethod.Hard or RepositoryResetMethod.HardMerge;
var hardMode = method is RepositoryResetMethod.Hard;
List<WorkspaceFile> unmerged = new();
// Apply files excepts local changed.
@ -892,7 +892,6 @@ public class RepositoryService : BaseService<RepositoryService>
}
catch (Exception exception) { Console.WriteLine(exception); }
UIHelper.NotifyError(e);
Console.WriteLine(e);
await DeleteFromDiskAsync(repo);
@ -938,47 +937,45 @@ public class RepositoryService : BaseService<RepositoryService>
}
}
public async ValueTask MergeFilesAsync(RepositoryModel repo, RepositoryFileTreeAccessor repoAccessor, IEnumerable<WorkspaceFile> unmerged)
public async ValueTask<bool> MergeFilesAsync(RepositoryModel repo, RepositoryFileTreeAccessor repoAccessor, IEnumerable<WorkspaceFile> unmerged)
{
var root = PathUtility.GetWorkspaceManagerPath(Api.C.Username.Value, repo.OwnerName, repo.Name);
var srcTem = Path.Combine(root, "MergeInTemp");
using (Disposable.Create(srcTem, r => Directory.Delete(r, true)))
var tempFolder = Path.Combine(root, "MergeInTemp");
var wsRoot = PathUtility.GetWorkspacePath(Api.C.Username.Value, repo.OwnerName, repo.Name);
var left = Path.Combine(tempFolder, "left");
var right = Path.Combine(tempFolder, "right");
using (Disposable.Create(tempFolder, r => Directory.Delete(r, true)))
{
Directory.CreateDirectory(root);
// Prepare server files
var wsRoot = PathUtility.GetWorkspacePath(Api.C.Username.Value, repo.OwnerName, repo.Name);
var vm = new MergeDialogViewModel(repo, unmerged, srcTem, wsRoot);
foreach (var f in vm.MergeFiles)
foreach (var p in unmerged)
{
var pf = WorkPath.ToPlatformPath(f.WorkPath, vm.SrcFolder);
Directory.CreateDirectory(Path.GetDirectoryName(pf)!);
await using var fs = File.Create(pf);
repoAccessor.TryWriteDataIntoDisk(f.WorkPath, fs, out _);
}
try
{
// Prepare for left and right file
var wfs = WorkPath.ToPlatformPath(wsRoot, p.WorkPath);
File.Copy(wfs, left, true);
await using var rightFs = File.Create(right);
repoAccessor.TryWriteDataIntoDisk(p.WorkPath, rightFs, out _);
// Raise merge window
var opt = UIHelper.DefaultOverlayDialogOptionsYesNo();
opt.Buttons = DialogButton.OK;
opt.Title = "Merge files";
opt.FullScreen = true;
opt.IsCloseButtonVisible = false;
// Raise dialog window
var opt = UIHelper.DefaultOverlayDialogOptionsYesNo();
opt.Buttons = DialogButton.None;
opt.Title = "Merge files";
opt.IsCloseButtonVisible = true;
await OverlayDialog.ShowModal<MergeDialogView, MergeDialogViewModel>(vm, AppDefaultValues.HostId, opt);
// Rollback files
foreach (var f in vm.MergeFiles)
{
var copyFrom = WorkPath.ToPlatformPath(f.WorkPath, vm.TmpFolder);
if (!File.Exists(copyFrom)) continue; // If file existed, override it.
var copyTo = WorkPath.ToPlatformPath(f.WorkPath, vm.DstFolder);
Directory.CreateDirectory(Path.GetDirectoryName(copyTo)!);
File.Copy(copyFrom, copyTo, true);
var vm = new MergeDialogViewModel(p.WorkPath, wfs, p.WorkPath, left, right);
await OverlayDialog.ShowModal<MergeDialogView, MergeDialogViewModel>(vm, AppDefaultValues.HostId, opt);
}
catch (Exception e)
{
Console.Error.WriteLine(e);
}
}
}
return true;
}
public async ValueTask<bool> UpdateCommitsHistoryFromServerAsync(RepositoryModel repo)

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Flawless.Abstraction;
@ -11,34 +12,42 @@ namespace Flawless.Client.ViewModels.ModalBox;
public partial class MergeDialogViewModel : ViewModelBase
{
public ObservableCollection<WorkspaceFile> MergeFiles { get; }
[Reactive] private string _ws;
public RepositoryModel Repository { get; }
[Reactive] private string _final;
[Reactive] private string _leftFile; // Local file
[Reactive] private string _rightFile; // Remote file
public string SrcFolder { get; }
public string DstFolder { get; }
public string TmpFolder { get; }
public MergeDialogViewModel(RepositoryModel repository, IEnumerable<WorkspaceFile> files,
string srcFolder, string dstFolder)
public MergeDialogViewModel(string ws, string final, string fileWorkPath, string leftFile, string rightFile)
{
Repository = repository;
MergeFiles = new ObservableCollection<WorkspaceFile>(files);
SrcFolder = srcFolder;
DstFolder = dstFolder;
TmpFolder = Directory.CreateTempSubdirectory("Flawless_Merge").Name;
_ws = ws;
_final = final;
_leftFile = leftFile;
_rightFile = rightFile;
}
[ReactiveCommand]
private async Task RaiseMergeToolsAsync(string fileWorkPath)
{
var srcFile = WorkPath.ToPlatformPath(fileWorkPath, SrcFolder);
var dstFile = Path.Combine(fileWorkPath, DstFolder);
var tmpFile = Path.Combine(fileWorkPath, TmpFolder);
var result = Process.Start($"meld \"{LeftFile}\" \"{RightFile}\"");
}
[ReactiveCommand]
private Task UseLeftFileAsync()
{
return UseFileAsync(LeftFile);
}
[ReactiveCommand]
private Task UseRightFileAsync()
{
return UseFileAsync(RightFile);
}
private async Task UseFileAsync(string path)
{
File.Copy(path, _final, true);
}
}

View File

@ -235,15 +235,19 @@ public partial class SettingViewModel : RoutableViewModelBase
Users.Clear();
foreach (var user in users)
{
Users.Add(new UserModel
var m = new UserModel
{
Username = user.Username,
Email = user.Email,
IsActive = user.IsActive,
IsAdmin = user.IsAdmin ?? false,
CanEdit = user.Username != Api.C.Username.Value!
});
};
if (m.CanEdit) Users.Insert(0, m);
else Users.Add(m);
}
}
catch (ApiException ex)
{

View File

@ -6,19 +6,15 @@
xmlns:u="https://irihi.tech/ursa"
x:DataType="vm:MergeDialogViewModel"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
MinWidth="400"
MinWidth="600"
x:Class="Flawless.Client.Views.ModalBox.MergeDialogView">
<ListBox HorizontalAlignment="Stretch" ItemsSource="{Binding MergeFiles}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>
<Grid ColumnDefinitions="Auto, *, Auto">
<Label Grid.Column="0" Content="{Binding WorkPath}"/>
<u:IconButton Command="{Binding $parent[ItemsControl].((vm:MergeDialogViewModel)DataContext).RaiseMergeToolsCommand}"
CommandParameter="{Binding WorkPath}"/>
</Grid>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Spacing="12">
<Label Content="{Binding Ws, StringFormat='Conflict on file:\n {0}'}"/>
<Label Content="{Binding Ws, StringFormat='Left is local and right is remote'}"/>
<StackPanel Orientation="Horizontal" Spacing="4" HorizontalAlignment="Center">
<Button Content="Use Left" Command="{Binding UseLeftFileCommand}"/>
<Button Content="Merge" Command="{Binding RaiseMergeToolsCommand}"/>
<Button Content="Use Right" Command="{Binding UseRightFileCommand}"/>
</StackPanel>
</StackPanel>
</UserControl>

View File

@ -36,22 +36,22 @@
</u:Form>
</ScrollViewer>
</TabItem>
<TabItem Header="Preference">
<ScrollViewer Width="600" HorizontalAlignment="Left" Margin="6">
<u:Form HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<!-- <u:FormItem Label="Default Storage Location"> -->
<!-- <u:PathPicker/> -->
<!-- </u:FormItem> -->
<u:FormGroup Header="Extern Tools">
<u:PathPicker u:FormItem.Label="Diff Tool"/>
</u:FormGroup>
<StackPanel Orientation="Horizontal" Spacing="4">
<u:IconButton Content="Save" Command="{Binding SaveClientPreferenceCommand}"/>
<u:IconButton Classes="Danger" Content="Reset" Command="{Binding ResetClientPreferenceCommand}"/>
</StackPanel>
</u:Form>
</ScrollViewer>
</TabItem>
<!-- <TabItem Header="Preference"> -->
<!-- <ScrollViewer Width="600" HorizontalAlignment="Left" Margin="6"> -->
<!-- <u:Form HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> -->
<!-- ~1~ <u:FormItem Label="Default Storage Location"> @1@ -->
<!-- ~1~ <u:PathPicker/> @1@ -->
<!-- ~1~ </u:FormItem> @1@ -->
<!-- <u:FormGroup Header="Extern Tools"> -->
<!-- <u:PathPicker u:FormItem.Label="Diff Tool"/> -->
<!-- </u:FormGroup> -->
<!-- <StackPanel Orientation="Horizontal" Spacing="4"> -->
<!-- <u:IconButton Content="Save" Command="{Binding SaveClientPreferenceCommand}"/> -->
<!-- <u:IconButton Classes="Danger" Content="Reset" Command="{Binding ResetClientPreferenceCommand}"/> -->
<!-- </StackPanel> -->
<!-- </u:Form> -->
<!-- </ScrollViewer> -->
<!-- </TabItem> -->
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Server">
<ScrollViewer Width="600" HorizontalAlignment="Left" Margin="6">
<u:Form HorizontalAlignment="Stretch" VerticalAlignment="Stretch">