Skip to content

Commit 90c3220

Browse files
committed
refactor: rename CheckoutCommit to CheckoutDetached (#2442)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 8d8da03 commit 90c3220

9 files changed

Lines changed: 63 additions & 33 deletions

File tree

‎src/Resources/Locales/en_US.axaml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@
113113
<x:String x:Key="Text.ChangeSubmoduleUrl.Submodule" xml:space="preserve">Submodule:</x:String>
114114
<x:String x:Key="Text.ChangeSubmoduleUrl.URL" xml:space="preserve">URL:</x:String>
115115
<x:String x:Key="Text.Checkout" xml:space="preserve">Checkout Branch</x:String>
116-
<x:String x:Key="Text.Checkout.Commit" xml:space="preserve">Checkout Commit</x:String>
117-
<x:String x:Key="Text.Checkout.Commit.Target" xml:space="preserve">Commit:</x:String>
118-
<x:String x:Key="Text.Checkout.Commit.Warning" xml:space="preserve">Warning: By doing a commit checkout, HEAD will be detached</x:String>
119116
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">Local Changes:</x:String>
120117
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch:</x:String>
121118
<x:String x:Key="Text.Checkout.WarnLostCommits" xml:space="preserve">Your current HEAD contains commit(s) not connected to any branches/tags! Do you want to continue?</x:String>
@@ -125,6 +122,9 @@
125122
<x:String x:Key="Text.CheckoutBranchFromStash" xml:space="preserve">Checkout Branch From Stash</x:String>
126123
<x:String x:Key="Text.CheckoutBranchFromStash.Branch" xml:space="preserve">New Branch:</x:String>
127124
<x:String x:Key="Text.CheckoutBranchFromStash.Stash" xml:space="preserve">Stash:</x:String>
125+
<x:String x:Key="Text.CheckoutDetached" xml:space="preserve">Checkout Commit or Tag</x:String>
126+
<x:String x:Key="Text.CheckoutDetached.Target" xml:space="preserve">Target:</x:String>
127+
<x:String x:Key="Text.CheckoutDetached.Warning" xml:space="preserve">Warning: After doing this, HEAD will be detached</x:String>
128128
<x:String x:Key="Text.CherryPick" xml:space="preserve">Cherry Pick</x:String>
129129
<x:String x:Key="Text.CherryPick.AppendSourceToMessage" xml:space="preserve">Append source to commit message</x:String>
130130
<x:String x:Key="Text.CherryPick.Commit" xml:space="preserve">Commit(s):</x:String>
@@ -936,7 +936,7 @@
936936
<x:String x:Key="Text.Sure" xml:space="preserve">OK</x:String>
937937
<x:String x:Key="Text.Tag.Tagger" xml:space="preserve">TAGGER</x:String>
938938
<x:String x:Key="Text.Tag.Time" xml:space="preserve">TIME</x:String>
939-
<x:String x:Key="Text.TagCM.Checkout" xml:space="preserve">Checkout</x:String>
939+
<x:String x:Key="Text.TagCM.Checkout" xml:space="preserve">Checkout Tag</x:String>
940940
<x:String x:Key="Text.TagCM.CompareTwo" xml:space="preserve">Compare 2 tags</x:String>
941941
<x:String x:Key="Text.TagCM.CompareWith" xml:space="preserve">Compare with...</x:String>
942942
<x:String x:Key="Text.TagCM.CompareWithHead" xml:space="preserve">Compare with HEAD</x:String>

‎src/Resources/Locales/zh_CN.axaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<x:String x:Key="Text.CheckoutBranchFromStash" xml:space="preserve">从所选贮藏检出分支</x:String>
130130
<x:String x:Key="Text.CheckoutBranchFromStash.Branch" xml:space="preserve">新分支 :</x:String>
131131
<x:String x:Key="Text.CheckoutBranchFromStash.Stash" xml:space="preserve">所选贮藏 :</x:String>
132+
<x:String x:Key="Text.CheckoutDetached" xml:space="preserve">检出提交或标签</x:String>
133+
<x:String x:Key="Text.CheckoutDetached.Target" xml:space="preserve">目标 :</x:String>
134+
<x:String x:Key="Text.CheckoutDetached.Warning" xml:space="preserve">注意:执行该操作后,当前HEAD会变为游离(detached)状态!</x:String>
132135
<x:String x:Key="Text.CherryPick" xml:space="preserve">挑选提交</x:String>
133136
<x:String x:Key="Text.CherryPick.AppendSourceToMessage" xml:space="preserve">提交信息中追加来源信息</x:String>
134137
<x:String x:Key="Text.CherryPick.Commit" xml:space="preserve">提交列表 :</x:String>

‎src/Resources/Locales/zh_TW.axaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<x:String x:Key="Text.CheckoutBranchFromStash" xml:space="preserve">從所選擱置簽出分支</x:String>
130130
<x:String x:Key="Text.CheckoutBranchFromStash.Branch" xml:space="preserve">新分支:</x:String>
131131
<x:String x:Key="Text.CheckoutBranchFromStash.Stash" xml:space="preserve">所選擱置:</x:String>
132+
<x:String x:Key="Text.CheckoutDetached" xml:space="preserve">簽出提交或標籤</x:String>
133+
<x:String x:Key="Text.CheckoutDetached.Target" xml:space="preserve">目標:</x:String>
134+
<x:String x:Key="Text.CheckoutDetached.Warning" xml:space="preserve">注意:執行該操作後,目前 HEAD 會變為分離 (detached) 狀態!</x:String>
132135
<x:String x:Key="Text.CherryPick" xml:space="preserve">揀選提交</x:String>
133136
<x:String x:Key="Text.CherryPick.AppendSourceToMessage" xml:space="preserve">提交資訊中追加來源資訊</x:String>
134137
<x:String x:Key="Text.CherryPick.Commit" xml:space="preserve">提交列表:</x:String>
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace SourceGit.ViewModels
44
{
5-
public class CheckoutCommit : Popup
5+
public class CheckoutDetached : Popup
66
{
7-
public Models.Commit Commit
7+
public object Target
88
{
99
get;
1010
}
@@ -20,11 +20,23 @@ public Models.DealWithLocalChanges DealWithLocalChanges
2020
set;
2121
}
2222

23-
public CheckoutCommit(Repository repo, Models.Commit commit)
23+
public CheckoutDetached(Repository repo, Models.Commit commit)
2424
{
2525
_repo = repo;
26-
Commit = commit;
26+
_revision = commit.SHA;
2727

28+
Target = commit;
29+
DealWithLocalChanges = Preferences.Instance.UseStashAndReapplyByDefault ?
30+
Models.DealWithLocalChanges.StashAndReapply :
31+
Models.DealWithLocalChanges.DoNothing;
32+
}
33+
34+
public CheckoutDetached(Repository repo, Models.Tag tag)
35+
{
36+
_repo = repo;
37+
_revision = tag.SHA;
38+
39+
Target = tag;
2840
DealWithLocalChanges = Preferences.Instance.UseStashAndReapplyByDefault ?
2941
Models.DealWithLocalChanges.StashAndReapply :
3042
Models.DealWithLocalChanges.DoNothing;
@@ -33,7 +45,7 @@ public CheckoutCommit(Repository repo, Models.Commit commit)
3345
public override async Task<bool> Sure()
3446
{
3547
using var lockWatcher = _repo.LockWatcher();
36-
ProgressDescription = $"Checkout Commit '{Commit.SHA}' ...";
48+
ProgressDescription = $"Checkout Commit '{_revision}' ...";
3749

3850
var log = _repo.CreateLog("Checkout Commit");
3951
Use(log);
@@ -57,7 +69,7 @@ public override async Task<bool> Sure()
5769
{
5870
succ = await new Commands.Checkout(_repo.FullPath)
5971
.Use(log)
60-
.CommitAsync(Commit.SHA, false);
72+
.CommitAsync(_revision, false);
6173
}
6274
else if (DealWithLocalChanges == Models.DealWithLocalChanges.StashAndReapply)
6375
{
@@ -79,13 +91,13 @@ public override async Task<bool> Sure()
7991

8092
succ = await new Commands.Checkout(_repo.FullPath)
8193
.Use(log)
82-
.CommitAsync(Commit.SHA, false);
94+
.CommitAsync(_revision, false);
8395
}
8496
else
8597
{
8698
succ = await new Commands.Checkout(_repo.FullPath)
8799
.Use(log)
88-
.CommitAsync(Commit.SHA, true);
100+
.CommitAsync(_revision, true);
89101
}
90102

91103
if (succ)
@@ -103,5 +115,6 @@ public override async Task<bool> Sure()
103115
}
104116

105117
private readonly Repository _repo = null;
118+
private readonly string _revision = string.Empty;
106119
}
107120
}

‎src/ViewModels/Histories.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public void NavigateTo(string commitSHA)
291291
public void CheckoutCommitDetached(Models.Commit c)
292292
{
293293
if (!c.IsCurrentHead && _repo.CanCreatePopup())
294-
_repo.ShowPopup(new CheckoutCommit(_repo, c));
294+
_repo.ShowPopup(new CheckoutDetached(_repo, c));
295295
}
296296

297297
public async Task<bool> CheckoutBranchByDecoratorAsync(Models.Decorator decorator)
@@ -382,7 +382,7 @@ public async Task CheckoutBranchByCommitAsync(Models.Commit commit)
382382
if (firstRemoteBranch != null)
383383
_repo.ShowPopup(new CreateBranch(_repo, firstRemoteBranch));
384384
else if (!_repo.IsBare)
385-
_repo.ShowPopup(new CheckoutCommit(_repo, commit));
385+
_repo.ShowPopup(new CheckoutDetached(_repo, commit));
386386
}
387387
}
388388

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:m="using:SourceGit.Models"
56
xmlns:vm="using:SourceGit.ViewModels"
67
xmlns:v="using:SourceGit.Views"
78
xmlns:c="using:SourceGit.Converters"
89
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
9-
x:Class="SourceGit.Views.CheckoutCommit"
10-
x:DataType="vm:CheckoutCommit">
10+
x:Class="SourceGit.Views.CheckoutDetached"
11+
x:DataType="vm:CheckoutDetached">
1112
<StackPanel Orientation="Vertical" Margin="8,0">
1213
<StackPanel Orientation="Horizontal">
1314
<Path Width="16" Height="16"
@@ -16,7 +17,7 @@
1617
<TextBlock FontSize="18"
1718
Margin="8,0,0,0"
1819
Classes="bold"
19-
Text="{DynamicResource Text.Checkout.Commit}"/>
20+
Text="{DynamicResource Text.CheckoutDetached}"/>
2021
</StackPanel>
2122

2223
<Grid Margin="0,16,0,0" RowDefinitions="32,Auto,Auto">
@@ -28,12 +29,25 @@
2829
<TextBlock Grid.Row="0" Grid.Column="0"
2930
HorizontalAlignment="Right" VerticalAlignment="Center"
3031
Margin="0,0,8,0"
31-
Text="{DynamicResource Text.Checkout.Commit.Target}" />
32-
<Grid Grid.Row="0" Grid.Column="1" ColumnDefinitions="Auto,Auto,*">
33-
<Path Grid.Column="0" Width="14" Height="14" Data="{StaticResource Icons.Commit}" />
34-
<TextBlock Grid.Column="1" Foreground="DarkOrange" VerticalAlignment="Center" Margin="8,0" Text="{Binding Commit.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" />
35-
<TextBlock Grid.Column="2" Text="{Binding Commit.Subject}" TextTrimming="CharacterEllipsis"/>
36-
</Grid>
32+
Text="{DynamicResource Text.CheckoutDetached.Target}" />
33+
<ContentControl Grid.Row="0" Grid.Column="1" Content="{Binding Target, Mode=OneWay}">
34+
<ContentControl.DataTemplates>
35+
<DataTemplate DataType="m:Commit">
36+
<Grid ColumnDefinitions="Auto,Auto,*">
37+
<Path Grid.Column="0" Width="14" Height="14" Data="{StaticResource Icons.Commit}" />
38+
<TextBlock Grid.Column="1" Foreground="DarkOrange" VerticalAlignment="Center" Margin="8,0" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" />
39+
<TextBlock Grid.Column="2" Text="{Binding Subject, Mode=OneWay}" TextTrimming="CharacterEllipsis"/>
40+
</Grid>
41+
</DataTemplate>
42+
43+
<DataTemplate DataType="m:Tag">
44+
<Grid ColumnDefinitions="Auto,*">
45+
<Path Grid.Column="0" Width="14" Height="14" Data="{StaticResource Icons.Tag}" />
46+
<TextBlock Grid.Column="1" Margin="8,0" Text="{Binding Name, Mode=OneWay}" TextTrimming="CharacterEllipsis"/>
47+
</Grid>
48+
</DataTemplate>
49+
</ContentControl.DataTemplates>
50+
</ContentControl>
3751

3852
<Border Grid.Row="1" Grid.Column="0"
3953
Height="32"
@@ -53,7 +67,7 @@
5367
Data="{StaticResource Icons.Error}"
5468
Fill="DarkOrange"/>
5569
<TextBlock Grid.Column="1" Margin="8,0,0,0"
56-
Text="{DynamicResource Text.Checkout.Commit.Warning}"
70+
Text="{DynamicResource Text.CheckoutDetached.Warning}"
5771
TextWrapping="Wrap"
5872
Foreground="DarkOrange"/>
5973
</Grid>
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 CheckoutCommit : UserControl
5+
public partial class CheckoutDetached : UserControl
66
{
7-
public CheckoutCommit()
7+
public CheckoutDetached()
88
{
99
InitializeComponent();
1010
}

‎src/Views/Histories.axaml.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
10301030
checkoutCommit.Click += (_, e) =>
10311031
{
10321032
if (repo.CanCreatePopup())
1033-
repo.ShowPopup(new ViewModels.CheckoutCommit(repo, commit));
1033+
repo.ShowPopup(new ViewModels.CheckoutDetached(repo, commit));
10341034
e.Handled = true;
10351035
};
10361036
menu.Items.Add(checkoutCommit);

‎src/Views/TagsView.axaml.cs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,10 @@ private void OnTagsContextMenuRequested(object sender, ContextRequestedEventArgs
252252
var checkoutCommit = new MenuItem();
253253
checkoutCommit.Header = App.Text("TagCM.Checkout");
254254
checkoutCommit.Icon = this.CreateMenuIcon("Icons.Detached");
255-
checkoutCommit.Click += async (_, e) =>
255+
checkoutCommit.Click += (_, e) =>
256256
{
257-
var commit = await new Commands.QuerySingleCommit(repo.FullPath, tag.SHA)
258-
.GetResultAsync();
259-
260-
if (commit != null && repo.CanCreatePopup())
261-
repo.ShowPopup(new ViewModels.CheckoutCommit(repo, commit));
257+
if (repo.CanCreatePopup())
258+
repo.ShowPopup(new ViewModels.CheckoutDetached(repo, tag));
262259

263260
e.Handled = true;
264261
};

0 commit comments

Comments
 (0)