Skip to content

Commit 80ed2c4

Browse files
committed
code_review: PR #1969
- Merge `ViewModels.Histories.FixupHeadAsync` and `ViewModels.Histories.SquashHeadAsync` into `ViewModels.Histories.SquashOrFixupHeadAsync` - Rename `ViewModels|Views.Squash` to `ViewModels|Views.SquashOrFixupHead` - Use different title, log key and auto-squash-name for `Fixup into Parent` context menu - Do not start `Squash into Parent` or `Fixup into Parent` operation directly Signed-off-by: leo <[email protected]>
1 parent e130d35 commit 80ed2c4

File tree

9 files changed

+50
-46
lines changed

9 files changed

+50
-46
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,9 @@
793793
<x:String x:Key="Text.SetUpstream.Upstream" xml:space="preserve">Upstream:</x:String>
794794
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">Copy SHA</x:String>
795795
<x:String x:Key="Text.SHALinkCM.NavigateTo" xml:space="preserve">Go to</x:String>
796-
<x:String x:Key="Text.Squash" xml:space="preserve">Squash Commits</x:String>
797-
<x:String x:Key="Text.Squash.Into" xml:space="preserve">Into:</x:String>
796+
<x:String x:Key="Text.SquashOrFixup.Squash" xml:space="preserve">Squash HEAD into Parent</x:String>
797+
<x:String x:Key="Text.SquashOrFixup.Fixup" xml:space="preserve">Fixup HEAD into Parent</x:String>
798+
<x:String x:Key="Text.SquashOrFixup.Into" xml:space="preserve">Into:</x:String>
798799
<x:String x:Key="Text.SSHKey" xml:space="preserve">SSH Private Key:</x:String>
799800
<x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">Private SSH key store path</x:String>
800801
<x:String x:Key="Text.Start" xml:space="preserve">START</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,9 @@
797797
<x:String x:Key="Text.SetUpstream.Upstream" xml:space="preserve">上游分支 :</x:String>
798798
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">复制提交指纹</x:String>
799799
<x:String x:Key="Text.SHALinkCM.NavigateTo" xml:space="preserve">跳转到提交</x:String>
800-
<x:String x:Key="Text.Squash" xml:space="preserve">压缩为单个提交</x:String>
801-
<x:String x:Key="Text.Squash.Into" xml:space="preserve">合并入:</x:String>
800+
<x:String x:Key="Text.SquashOrFixup.Squash" xml:space="preserve">合并修改至父提交</x:String>
801+
<x:String x:Key="Text.SquashOrFixup.Fixup" xml:space="preserve">修复至父提交</x:String>
802+
<x:String x:Key="Text.SquashOrFixup.Into" xml:space="preserve">父提交:</x:String>
802803
<x:String x:Key="Text.SSHKey" xml:space="preserve">SSH密钥 :</x:String>
803804
<x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">SSH密钥文件</x:String>
804805
<x:String x:Key="Text.Start" xml:space="preserve">开 始</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,9 @@
797797
<x:String x:Key="Text.SetUpstream.Upstream" xml:space="preserve">上游分支:</x:String>
798798
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">複製提交編號</x:String>
799799
<x:String x:Key="Text.SHALinkCM.NavigateTo" xml:space="preserve">前往此提交</x:String>
800-
<x:String x:Key="Text.Squash" xml:space="preserve">壓縮為單個提交</x:String>
801-
<x:String x:Key="Text.Squash.Into" xml:space="preserve">合併入:</x:String>
800+
<x:String x:Key="Text.SquashOrFixup.Squash" xml:space="preserve">合併變更入父提交</x:String>
801+
<x:String x:Key="Text.SquashOrFixup.Fixup" xml:space="preserve">修正至父提交</x:String>
802+
<x:String x:Key="Text.SquashOrFixup.Into" xml:space="preserve">父提交:</x:String>
802803
<x:String x:Key="Text.SSHKey" xml:space="preserve">SSH 金鑰:</x:String>
803804
<x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">SSH 金鑰檔案</x:String>
804805
<x:String x:Key="Text.Start" xml:space="preserve">開 始</x:String>

src/ViewModels/Histories.cs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
5-
using System.Text;
65
using System.Threading.Tasks;
76

87
using Avalonia.Controls;
@@ -322,37 +321,23 @@ public async Task RewordHeadAsync(Models.Commit head)
322321
}
323322
}
324323

325-
public async Task SquashHeadAsync(Models.Commit head)
324+
public async Task SquashOrFixupHeadAsync(Models.Commit head, bool fixup)
326325
{
327326
if (head.Parents.Count == 1)
328327
{
329328
var parent = await new Commands.QuerySingleCommit(_repo.FullPath, head.Parents[0]).GetResultAsync();
330329
if (parent == null)
331330
return;
332331

333-
var headMessage = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).GetResultAsync();
334-
var parentMessage = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.Parents[0]).GetResultAsync();
335-
336-
var builder = new StringBuilder();
337-
builder.Append(parentMessage).Append("\n\n").Append(headMessage);
338-
339-
if (_repo.CanCreatePopup())
340-
_repo.ShowPopup(new Squash(_repo, parent, builder.ToString()));
341-
}
342-
}
343-
344-
public async Task FixupHeadAsync(Models.Commit head)
345-
{
346-
if (head.Parents.Count == 1)
347-
{
348-
var parent = await new Commands.QuerySingleCommit(_repo.FullPath, head.Parents[0]).GetResultAsync();
349-
if (parent == null)
350-
return;
351-
352-
var parentMessage = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.Parents[0]).GetResultAsync();
332+
string message = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.Parents[0]).GetResultAsync();
333+
if (!fixup)
334+
{
335+
var headMessage = await new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).GetResultAsync();
336+
message = $"{message}\n\n{headMessage}";
337+
}
353338

354339
if (_repo.CanCreatePopup())
355-
await _repo.ShowAndStartPopupAsync(new Squash(_repo, parent, parentMessage));
340+
_repo.ShowPopup(new SquashOrFixupHead(_repo, parent, message, fixup));
356341
}
357342
}
358343

src/ViewModels/InteractiveRebase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,8 @@ private void UpdateItems()
372372
item.IsMessageUserEdited = false;
373373

374374
if (item.Action == Models.InteractiveRebaseAction.Squash)
375-
{
376375
pendingMessages.Add(item.OriginalFullMessage);
377-
}
376+
378377
hasPending = true;
379378
continue;
380379
}
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
namespace SourceGit.ViewModels
55
{
6-
public class Squash : Popup
6+
public class SquashOrFixupHead : Popup
77
{
8+
public bool IsFixupMode
9+
{
10+
get;
11+
}
12+
813
public Models.Commit Target
914
{
1015
get;
@@ -17,19 +22,21 @@ public string Message
1722
set => SetProperty(ref _message, value, true);
1823
}
1924

20-
public Squash(Repository repo, Models.Commit target, string message)
25+
public SquashOrFixupHead(Repository repo, Models.Commit target, string message, bool fixup)
2126
{
27+
IsFixupMode = fixup;
28+
Target = target;
29+
2230
_repo = repo;
2331
_message = message;
24-
Target = target;
2532
}
2633

2734
public override async Task<bool> Sure()
2835
{
2936
using var lockWatcher = _repo.LockWatcher();
30-
ProgressDescription = "Squashing ...";
37+
ProgressDescription = IsFixupMode ? "Fixup ..." : "Squashing ...";
3138

32-
var log = _repo.CreateLog("Squash");
39+
var log = _repo.CreateLog(IsFixupMode ? "Fixup" : "Squash");
3340
Use(log);
3441

3542
var changes = await new Commands.QueryLocalChanges(_repo.FullPath, false).GetResultAsync();
@@ -51,7 +58,7 @@ public override async Task<bool> Sure()
5158
{
5259
succ = await new Commands.Stash(_repo.FullPath)
5360
.Use(log)
54-
.PushAsync("SQUASH_AUTO_STASH");
61+
.PushAsync(IsFixupMode ? "FIXUP_AUTO_STASH" : "SQUASH_AUTO_STASH");
5562
if (!succ)
5663
{
5764
log.Complete();

src/Views/Histories.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
559559
squash.IsEnabled = commit.Parents.Count == 1;
560560
squash.Click += async (_, e) =>
561561
{
562-
await vm.SquashHeadAsync(commit);
562+
await vm.SquashOrFixupHeadAsync(commit, false);
563563
e.Handled = true;
564564
};
565565
menu.Items.Add(squash);
@@ -570,7 +570,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
570570
fixup.IsEnabled = commit.Parents.Count == 1;
571571
fixup.Click += async (_, e) =>
572572
{
573-
await vm.FixupHeadAsync(commit);
573+
await vm.SquashOrFixupHeadAsync(commit, true);
574574
e.Handled = true;
575575
};
576576
menu.Items.Add(fixup);
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,32 @@
66
xmlns:v="using:SourceGit.Views"
77
xmlns:c="using:SourceGit.Converters"
88
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
9-
x:Class="SourceGit.Views.Squash"
10-
x:DataType="vm:Squash">
9+
x:Class="SourceGit.Views.SquashOrFixupHead"
10+
x:DataType="vm:SquashOrFixupHead">
1111
<StackPanel Orientation="Vertical" Margin="8,0">
12-
<StackPanel Orientation="Horizontal">
12+
<StackPanel Orientation="Horizontal" IsVisible="{Binding !IsFixupMode}">
1313
<Path Width="16" Height="16"
1414
Data="{StaticResource Icons.SquashIntoParent}"/>
1515

1616
<TextBlock FontSize="18"
1717
Margin="8,0,0,0"
1818
Classes="bold"
19-
Text="{DynamicResource Text.Squash}"/>
19+
Text="{DynamicResource Text.SquashOrFixup.Squash}"/>
20+
</StackPanel>
21+
22+
<StackPanel Orientation="Horizontal" IsVisible="{Binding IsFixupMode}">
23+
<Path Width="16" Height="16"
24+
Data="{StaticResource Icons.Fix}"/>
25+
26+
<TextBlock FontSize="18"
27+
Margin="8,0,0,0"
28+
Classes="bold"
29+
Text="{DynamicResource Text.SquashOrFixup.Fixup}"/>
2030
</StackPanel>
2131

2232
<Grid Margin="0,18,0,0" ColumnDefinitions="Auto,Auto,Auto,*">
2333
<TextBlock Grid.Column="0"
24-
Text="{DynamicResource Text.Squash.Into}"/>
34+
Text="{DynamicResource Text.SquashOrFixup.Into}"/>
2535
<Path Grid.Column="1"
2636
Margin="8,0"
2737
Width="14" Height="14"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace SourceGit.Views
44
{
5-
public partial class Squash : UserControl
5+
public partial class SquashOrFixupHead : UserControl
66
{
7-
public Squash()
7+
public SquashOrFixupHead()
88
{
99
InitializeComponent();
1010
}

0 commit comments

Comments
 (0)