mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
feature: test if conflicts have been resolved manually (#96)
This commit is contained in:
parent
df66bacbd2
commit
84568e573a
5 changed files with 74 additions and 27 deletions
20
src/Commands/IsConflictResolved.cs
Normal file
20
src/Commands/IsConflictResolved.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
namespace SourceGit.Commands
|
||||||
|
{
|
||||||
|
public class IsConflictResolved : Command
|
||||||
|
{
|
||||||
|
public IsConflictResolved(string repo, Models.Change change)
|
||||||
|
{
|
||||||
|
var opt = new Models.DiffOption(change, true);
|
||||||
|
|
||||||
|
WorkingDirectory = repo;
|
||||||
|
Context = repo;
|
||||||
|
Args = $"diff -a --ignore-cr-at-eol --check {opt}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Result()
|
||||||
|
{
|
||||||
|
var rs = ReadToEnd();
|
||||||
|
return rs.IsSuccess;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -427,11 +427,13 @@
|
||||||
<x:String x:Key="Text.Welcome.Sort" xml:space="preserve">Sort</x:String>
|
<x:String x:Key="Text.Welcome.Sort" xml:space="preserve">Sort</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy" xml:space="preserve">Changes</x:String>
|
<x:String x:Key="Text.WorkingCopy" xml:space="preserve">Changes</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Amend" xml:space="preserve">Amend</x:String>
|
<x:String x:Key="Text.WorkingCopy.Amend" xml:space="preserve">Amend</x:String>
|
||||||
|
<x:String x:Key="Text.WorkingCopy.CanStageTip" xml:space="preserve">You can stage this file now.</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Commit" xml:space="preserve">COMMIT</x:String>
|
<x:String x:Key="Text.WorkingCopy.Commit" xml:space="preserve">COMMIT</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitAndPush" xml:space="preserve">COMMIT & PUSH</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitAndPush" xml:space="preserve">COMMIT & PUSH</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitMessageTip" xml:space="preserve">Enter commit message</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitMessageTip" xml:space="preserve">Enter commit message</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">CTRL + Enter</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">CTRL + Enter</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">CONFLICTS DETECTED</x:String>
|
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">CONFLICTS DETECTED</x:String>
|
||||||
|
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">FILE CONFLICTS ARE RESOLVED</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.HasCommitHistories" xml:space="preserve">RECENT INPUT MESSAGES</x:String>
|
<x:String x:Key="Text.WorkingCopy.HasCommitHistories" xml:space="preserve">RECENT INPUT MESSAGES</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
|
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.MessageHistories" xml:space="preserve">MESSAGE HISTORIES</x:String>
|
<x:String x:Key="Text.WorkingCopy.MessageHistories" xml:space="preserve">MESSAGE HISTORIES</x:String>
|
||||||
|
|
|
@ -427,11 +427,13 @@
|
||||||
<x:String x:Key="Text.Welcome.Sort" xml:space="preserve">排序</x:String>
|
<x:String x:Key="Text.Welcome.Sort" xml:space="preserve">排序</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy" xml:space="preserve">本地更改</x:String>
|
<x:String x:Key="Text.WorkingCopy" xml:space="preserve">本地更改</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Amend" xml:space="preserve">修补(--amend)</x:String>
|
<x:String x:Key="Text.WorkingCopy.Amend" xml:space="preserve">修补(--amend)</x:String>
|
||||||
|
<x:String x:Key="Text.WorkingCopy.CanStageTip" xml:space="preserve">现在您已可将其加入暂存区中</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Commit" xml:space="preserve">提交</x:String>
|
<x:String x:Key="Text.WorkingCopy.Commit" xml:space="preserve">提交</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitAndPush" xml:space="preserve">提交并推送</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitAndPush" xml:space="preserve">提交并推送</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitMessageTip" xml:space="preserve">填写提交信息</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitMessageTip" xml:space="preserve">填写提交信息</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">CTRL + Enter</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">CTRL + Enter</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">检测到冲突</x:String>
|
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">检测到冲突</x:String>
|
||||||
|
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">文件冲突已解决</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.HasCommitHistories" xml:space="preserve">最近输入的提交信息</x:String>
|
<x:String x:Key="Text.WorkingCopy.HasCommitHistories" xml:space="preserve">最近输入的提交信息</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">显示未跟踪文件</x:String>
|
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">显示未跟踪文件</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.MessageHistories" xml:space="preserve">历史提交信息</x:String>
|
<x:String x:Key="Text.WorkingCopy.MessageHistories" xml:space="preserve">历史提交信息</x:String>
|
||||||
|
|
|
@ -12,9 +12,27 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class ConflictContext
|
public class ConflictContext : ObservableObject
|
||||||
{
|
{
|
||||||
public Models.Change Change { get; set; }
|
public bool IsResolved
|
||||||
|
{
|
||||||
|
get => _isResolved;
|
||||||
|
set => SetProperty(ref _isResolved, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConflictContext(string repo, Models.Change change)
|
||||||
|
{
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
var result = new Commands.IsConflictResolved(repo, change).Result();
|
||||||
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
|
IsResolved = result;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _isResolved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WorkingCopy : ObservableObject
|
public class WorkingCopy : ObservableObject
|
||||||
|
@ -296,9 +314,9 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
DetailContext = null;
|
DetailContext = null;
|
||||||
}
|
}
|
||||||
else if (change.IsConflit)
|
else if (change.IsConflit && isUnstaged)
|
||||||
{
|
{
|
||||||
DetailContext = new ConflictContext() { Change = change };
|
DetailContext = new ConflictContext(_repo.FullPath, change);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -432,26 +450,23 @@ namespace SourceGit.ViewModels
|
||||||
_repo.SetWatcherEnabled(true);
|
_repo.SetWatcherEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void UseExternalMergeTool()
|
public async void UseExternalMergeTool(Models.Change change)
|
||||||
{
|
{
|
||||||
if (_detailContext is ConflictContext ctx)
|
var type = Preference.Instance.ExternalMergeToolType;
|
||||||
|
var exec = Preference.Instance.ExternalMergeToolPath;
|
||||||
|
|
||||||
|
var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type);
|
||||||
|
if (tool == null)
|
||||||
{
|
{
|
||||||
var type = Preference.Instance.ExternalMergeToolType;
|
App.RaiseException(_repo.FullPath, "Invalid merge tool in preference setting!");
|
||||||
var exec = Preference.Instance.ExternalMergeToolPath;
|
return;
|
||||||
|
|
||||||
var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type);
|
|
||||||
if (tool == null)
|
|
||||||
{
|
|
||||||
App.RaiseException(_repo.FullPath, "Invalid merge tool in preference setting!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = tool.Type != 0 ? tool.Cmd : Preference.Instance.ExternalMergeToolCmd;
|
|
||||||
|
|
||||||
_repo.SetWatcherEnabled(false);
|
|
||||||
await Task.Run(() => Commands.MergeTool.OpenForMerge(_repo.FullPath, exec, args, ctx.Change.Path));
|
|
||||||
_repo.SetWatcherEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var args = tool.Type != 0 ? tool.Cmd : Preference.Instance.ExternalMergeToolCmd;
|
||||||
|
|
||||||
|
_repo.SetWatcherEnabled(false);
|
||||||
|
await Task.Run(() => Commands.MergeTool.OpenForMerge(_repo.FullPath, exec, args, change.Path));
|
||||||
|
_repo.SetWatcherEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void DoCommit(bool autoPush)
|
public async void DoCommit(bool autoPush)
|
||||||
|
@ -554,7 +569,7 @@ namespace SourceGit.ViewModels
|
||||||
openMerger.Header = App.Text("FileCM.OpenWithExternalMerger");
|
openMerger.Header = App.Text("FileCM.OpenWithExternalMerger");
|
||||||
openMerger.Click += (_, e) =>
|
openMerger.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
UseExternalMergeTool();
|
UseExternalMergeTool(change);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -319,11 +319,19 @@
|
||||||
<ContentControl.DataTemplates>
|
<ContentControl.DataTemplates>
|
||||||
<DataTemplate DataType="vm:ConflictContext">
|
<DataTemplate DataType="vm:ConflictContext">
|
||||||
<Border Background="{DynamicResource Brush.Window}" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
|
<Border Background="{DynamicResource Brush.Window}" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
<Path Width="64" Height="64" Data="{StaticResource Icons.Conflict}" Fill="{DynamicResource Brush.FG2}"/>
|
<StackPanel Orientation="Vertical" IsVisible="{Binding !IsResolved}">
|
||||||
<TextBlock Margin="0,16,0,8" FontSize="20" FontWeight="Bold" Text="{DynamicResource Text.WorkingCopy.Conflicts}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
|
<Path Width="64" Height="64" Data="{StaticResource Icons.Conflict}" Fill="{DynamicResource Brush.FG2}"/>
|
||||||
<TextBlock Text="{DynamicResource Text.WorkingCopy.ResolveTip}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
|
<TextBlock Margin="0,16,0,8" FontSize="20" FontWeight="Bold" Text="{DynamicResource Text.WorkingCopy.Conflicts}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
|
||||||
</StackPanel>
|
<TextBlock Text="{DynamicResource Text.WorkingCopy.ResolveTip}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Orientation="Vertical" IsVisible="{Binding IsResolved}">
|
||||||
|
<Path Width="64" Height="64" Data="{StaticResource Icons.Check}" Fill="Green"/>
|
||||||
|
<TextBlock Margin="0,16,0,8" FontSize="20" FontWeight="Bold" Text="{DynamicResource Text.WorkingCopy.Conflicts.Resolved}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
|
||||||
|
<TextBlock Text="{DynamicResource Text.WorkingCopy.CanStageTip}" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue