enhance: show source branch/tag/commit in banner while merging request in progress

This commit is contained in:
leo 2024-12-10 15:17:54 +08:00
parent e1df5c52f1
commit ef40e4b738
No known key found for this signature in database
7 changed files with 66 additions and 7 deletions

View file

@ -2,6 +2,15 @@
{ {
public static class Branch public static class Branch
{ {
public static string ShowCurrent(string repo)
{
var cmd = new Command();
cmd.WorkingDirectory = repo;
cmd.Context = repo;
cmd.Args = $"branch --show-current";
return cmd.ReadToEnd().StdOut.Trim();
}
public static bool Create(string repo, string name, string basedOn) public static bool Create(string repo, string name, string basedOn)
{ {
var cmd = new Command(); var cmd = new Command();

View file

@ -394,6 +394,7 @@
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">Cherry-Pick in progress.</x:String> <x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">Cherry-Pick in progress.</x:String>
<x:String x:Key="Text.InProgress.CherryPick.Head" xml:space="preserve">Processing commit</x:String> <x:String x:Key="Text.InProgress.CherryPick.Head" xml:space="preserve">Processing commit</x:String>
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">Merge request in progress.</x:String> <x:String x:Key="Text.InProgress.Merge" xml:space="preserve">Merge request in progress.</x:String>
<x:String x:Key="Text.InProgress.Merge.Operating" xml:space="preserve">Operating</x:String>
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">Rebase in progress.</x:String> <x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">Rebase in progress.</x:String>
<x:String x:Key="Text.InProgress.Rebase.StoppedAt" xml:space="preserve">Stopped at</x:String> <x:String x:Key="Text.InProgress.Rebase.StoppedAt" xml:space="preserve">Stopped at</x:String>
<x:String x:Key="Text.InProgress.Revert" xml:space="preserve">Revert in progress.</x:String> <x:String x:Key="Text.InProgress.Revert" xml:space="preserve">Revert in progress.</x:String>

View file

@ -397,6 +397,7 @@
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">挑选Cherry-Pick操作进行中。</x:String> <x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">挑选Cherry-Pick操作进行中。</x:String>
<x:String x:Key="Text.InProgress.CherryPick.Head" xml:space="preserve">正在处理提交</x:String> <x:String x:Key="Text.InProgress.CherryPick.Head" xml:space="preserve">正在处理提交</x:String>
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">合并操作进行中。</x:String> <x:String x:Key="Text.InProgress.Merge" xml:space="preserve">合并操作进行中。</x:String>
<x:String x:Key="Text.InProgress.Merge.Operating" xml:space="preserve">正在处理</x:String>
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">变基Rebase操作进行中。</x:String> <x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">变基Rebase操作进行中。</x:String>
<x:String x:Key="Text.InProgress.Rebase.StoppedAt" xml:space="preserve">当前停止于</x:String> <x:String x:Key="Text.InProgress.Rebase.StoppedAt" xml:space="preserve">当前停止于</x:String>
<x:String x:Key="Text.InProgress.Revert" xml:space="preserve">回滚提交操作进行中。</x:String> <x:String x:Key="Text.InProgress.Revert" xml:space="preserve">回滚提交操作进行中。</x:String>

View file

@ -397,6 +397,7 @@
<x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">揀選 (cherry-pick) 操作進行中。</x:String> <x:String x:Key="Text.InProgress.CherryPick" xml:space="preserve">揀選 (cherry-pick) 操作進行中。</x:String>
<x:String x:Key="Text.InProgress.CherryPick.Head" xml:space="preserve">正在處理提交</x:String> <x:String x:Key="Text.InProgress.CherryPick.Head" xml:space="preserve">正在處理提交</x:String>
<x:String x:Key="Text.InProgress.Merge" xml:space="preserve">合併操作進行中。</x:String> <x:String x:Key="Text.InProgress.Merge" xml:space="preserve">合併操作進行中。</x:String>
<x:String x:Key="Text.InProgress.Merge.Operating" xml:space="preserve">正在處理</x:String>
<x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">重定基底 (rebase) 操作進行中。</x:String> <x:String x:Key="Text.InProgress.Rebase" xml:space="preserve">重定基底 (rebase) 操作進行中。</x:String>
<x:String x:Key="Text.InProgress.Rebase.StoppedAt" xml:space="preserve">当前停止于</x:String> <x:String x:Key="Text.InProgress.Rebase.StoppedAt" xml:space="preserve">当前停止于</x:String>
<x:String x:Key="Text.InProgress.Revert" xml:space="preserve">復原提交操作進行中。</x:String> <x:String x:Key="Text.InProgress.Revert" xml:space="preserve">復原提交操作進行中。</x:String>

View file

@ -129,11 +129,52 @@ namespace SourceGit.ViewModels
public class RevertInProgress : InProgressContext public class RevertInProgress : InProgressContext
{ {
public RevertInProgress(string repo) : base(repo, "revert", false) { } public RevertInProgress(Repository repo) : base(repo.FullPath, "revert", false) { }
} }
public class MergeInProgress : InProgressContext public class MergeInProgress : InProgressContext
{ {
public MergeInProgress(string repo) : base(repo, "merge", false) { } public string Current
{
get;
private set;
}
public string SourceName
{
get;
private set;
}
public Models.Commit Source
{
get;
private set;
}
public MergeInProgress(Repository repo) : base(repo.FullPath, "merge", false)
{
Current = Commands.Branch.ShowCurrent(repo.FullPath);
var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim();
Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result();
if (Source == null)
return;
var branchDecorator = Source.Decorators.Find(x => x.Type == Models.DecoratorType.LocalBranchHead || x.Type == Models.DecoratorType.RemoteBranchHead);
if (branchDecorator != null)
{
SourceName = branchDecorator.Name;
return;
}
var tagDecorator = Source.Decorators.Find(x => x.Type == Models.DecoratorType.Tag);
if (tagDecorator != null)
{
SourceName = tagDecorator.Name;
}
SourceName = Source.SHA.Substring(0, 10);
}
} }
} }

View file

@ -241,9 +241,9 @@ namespace SourceGit.ViewModels
else if (File.Exists(Path.Combine(_repo.GitDir, "REBASE_HEAD")) && Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge"))) else if (File.Exists(Path.Combine(_repo.GitDir, "REBASE_HEAD")) && Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge")))
inProgress = new RebaseInProgress(_repo); inProgress = new RebaseInProgress(_repo);
else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD"))) else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD")))
inProgress = new RevertInProgress(_repo.FullPath); inProgress = new RevertInProgress(_repo);
else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD"))) else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD")))
inProgress = new MergeInProgress(_repo.FullPath); inProgress = new MergeInProgress(_repo);
HasUnsolvedConflicts = _cached.Find(x => x.IsConflit) != null; HasUnsolvedConflicts = _cached.Find(x => x.IsConflit) != null;
InProgressContext = inProgress; InProgressContext = inProgress;
@ -314,9 +314,9 @@ namespace SourceGit.ViewModels
else if (File.Exists(Path.Combine(_repo.GitDir, "REBASE_HEAD")) && Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge"))) else if (File.Exists(Path.Combine(_repo.GitDir, "REBASE_HEAD")) && Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge")))
inProgress = new RebaseInProgress(_repo); inProgress = new RebaseInProgress(_repo);
else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD"))) else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD")))
inProgress = new RevertInProgress(_repo.FullPath); inProgress = new RevertInProgress(_repo);
else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD"))) else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD")))
inProgress = new MergeInProgress(_repo.FullPath); inProgress = new MergeInProgress(_repo);
InProgressContext = inProgress; InProgressContext = inProgress;

View file

@ -583,7 +583,13 @@
</DataTemplate> </DataTemplate>
<DataTemplate DataType="vm:MergeInProgress"> <DataTemplate DataType="vm:MergeInProgress">
<StackPanel Orientation="Horizontal">
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Merge}"/> <TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Merge}"/>
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Merge.Operating}"/>
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.Accent}" Text="{Binding SourceName}" ToolTip.Tip="{Binding Source}"/>
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="→"/>
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.Accent}" Text="{Binding Current}"/>
</StackPanel>
</DataTemplate> </DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>
</ContentControl> </ContentControl>