Skip to content

Commit ec12af3

Browse files
committed
code_review: PR #2764
- Remove `Trust this repository` checkbox and `CanSure` property, pressing `OK` means trust this repository - Stop processing drop item when there is an untrusted repository because `SourceGit` only supports to display one popup at a time - Remove `TryShowTrustRepositoryPopup` * Both `OpenRepositoryInTab` and `OpenSubRepository` are used for added repositories. * `GetRepositoryGitDir` uses `Directory.Exist` and `File.Exist` first to get the $GIT_DIR Signed-off-by: leo <longshuang@msn.cn>
1 parent 9752df3 commit ec12af3

11 files changed

Lines changed: 65 additions & 106 deletions

File tree

‎src/Resources/Locales/en_US.axaml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,9 @@
998998
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">Push ${0}$...</x:String>
999999
<x:String x:Key="Text.Terminate" xml:space="preserve">TERMINATE</x:String>
10001000
<x:String x:Key="Text.TrustRepository" xml:space="preserve">Untrusted Repository</x:String>
1001-
<x:String x:Key="Text.TrustRepository.CommandTip" xml:space="preserve">Will run: </x:String>
1001+
<x:String x:Key="Text.TrustRepository.CommandTip" xml:space="preserve">Do you want to run `git config --global --add safe.directory {0}` command to trust this path?</x:String>
10021002
<x:String x:Key="Text.TrustRepository.Description" xml:space="preserve">Git refused to access this repository: </x:String>
10031003
<x:String x:Key="Text.TrustRepository.Path" xml:space="preserve">Path:</x:String>
1004-
<x:String x:Key="Text.TrustRepository.Permanent" xml:space="preserve">Trust this repository</x:String>
10051004
<x:String x:Key="Text.TrustRepository.ScanSkipped" xml:space="preserve">{0} repositories were skipped because git does not trust them. Please open them manually and confirm whether to trust them.</x:String>
10061005
<x:String x:Key="Text.UpdateSubmodules" xml:space="preserve">Update Submodules</x:String>
10071006
<x:String x:Key="Text.UpdateSubmodules.All" xml:space="preserve">All submodules</x:String>

‎src/Resources/Locales/zh_CN.axaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@
10021002
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">推送 ${0}$...</x:String>
10031003
<x:String x:Key="Text.Terminate" xml:space="preserve">终止运行</x:String>
10041004
<x:String x:Key="Text.TrustRepository" xml:space="preserve">不受信任的仓库</x:String>
1005-
<x:String x:Key="Text.TrustRepository.CommandTip" xml:space="preserve">将执行:</x:String>
1005+
<x:String x:Key="Text.TrustRepository.CommandTip" xml:space="preserve">是否执行 `git config --global --add safe.directory {0}` 命令以信任该仓库?</x:String>
10061006
<x:String x:Key="Text.TrustRepository.Description" xml:space="preserve">Git 拒绝访问该仓库: </x:String>
10071007
<x:String x:Key="Text.TrustRepository.Path" xml:space="preserve">路径 :</x:String>
10081008
<x:String x:Key="Text.TrustRepository.Permanent" xml:space="preserve">信任此仓库</x:String>

‎src/Resources/Locales/zh_TW.axaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@
992992
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">推送 ${0}$...</x:String>
993993
<x:String x:Key="Text.Terminate" xml:space="preserve">終止執行</x:String>
994994
<x:String x:Key="Text.TrustRepository" xml:space="preserve">不受信任的存放庫</x:String>
995-
<x:String x:Key="Text.TrustRepository.CommandTip" xml:space="preserve">將執行:</x:String>
995+
<x:String x:Key="Text.TrustRepository.CommandTip" xml:space="preserve">您是否要在該路徑執行 `git config --global --add safe.directory {0}` 命令以信任該存放庫?</x:String>
996996
<x:String x:Key="Text.TrustRepository.Description" xml:space="preserve">Git 拒絕存取該存放庫: </x:String>
997997
<x:String x:Key="Text.TrustRepository.Path" xml:space="preserve">路徑 :</x:String>
998998
<x:String x:Key="Text.TrustRepository.Permanent" xml:space="preserve">信任此存放庫</x:String>

‎src/ViewModels/Launcher.cs‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,6 @@ public void OpenRepositoryInTab(RepositoryNode node, LauncherPage page)
330330
var gitDir = isBare ? node.Id : GetRepositoryGitDir(node.Id);
331331
if (string.IsNullOrEmpty(gitDir))
332332
{
333-
if (TryShowTrustRepositoryPopup(node.Id, ActivePage))
334-
return;
335-
336333
ActivePage.Notifications.Add(new Models.Notification
337334
{
338335
Group = node.Id,
@@ -412,9 +409,6 @@ public void OpenSubRepository(LauncherPage ownerPage, string fullpath)
412409
var gitDir = GetRepositoryGitDir(normalizedPath);
413410
if (string.IsNullOrEmpty(gitDir))
414411
{
415-
if (TryShowTrustRepositoryPopup(normalizedPath, ownerPage))
416-
return;
417-
418412
ownerPage.Notifications.Add(new Models.Notification
419413
{
420414
Group = ownerPage.Node.Id,
@@ -450,21 +444,6 @@ public void OpenSubRepository(LauncherPage ownerPage, string fullpath)
450444
ActivePage = page;
451445
}
452446

453-
private bool TryShowTrustRepositoryPopup(string path, LauncherPage page)
454-
{
455-
if (page == null || !page.CanCreatePopup())
456-
return false;
457-
458-
var test = new Commands.QueryRepositoryRootPath(path).GetResult();
459-
if (test.IsSuccess ||
460-
!Models.SafeDirectories.IsUntrustedRepository(test.StdErr) ||
461-
!Models.SafeDirectories.TryGetSafeDirectoryValue(path, test.StdErr, out var safeDirectory))
462-
return false;
463-
464-
page.Popup = new TrustRepository(page.Node.Id, path, test.StdErr, safeDirectory, null, false, true, 0);
465-
return true;
466-
}
467-
468447
private void DispatchNotification(Models.Notification notification)
469448
{
470449
if (!Dispatcher.UIThread.CheckAccess())

‎src/ViewModels/LauncherPage.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public bool CanCreatePopup()
8080

8181
public async Task ProcessPopupAsync()
8282
{
83-
if (_popup is { InProgress: false } dump && dump.CanSure)
83+
if (_popup is { InProgress: false } dump)
8484
{
8585
if (!dump.Check())
8686
return;

‎src/ViewModels/Popup.cs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ public virtual bool CanStartDirectly()
5555
return true;
5656
}
5757

58-
/// <summary>
59-
/// Whether the `Sure` action is currently allowed. Views should bind the confirm button's
60-
/// `IsEnabled` to this property.
61-
/// </summary>
62-
public virtual bool CanSure => true;
63-
6458
public virtual Task<bool> Sure()
6559
{
6660
return null;

‎src/ViewModels/TrustRepository.cs‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ public string Reason
2424
get;
2525
}
2626

27-
/// <summary>
28-
/// Whether the exception should be added into the user's global git config. Disabled by default,
29-
/// so the user has to opt in explicitly.
30-
/// </summary>
31-
public bool Permanent
32-
{
33-
get => _permanent;
34-
set
35-
{
36-
if (SetProperty(ref _permanent, value))
37-
OnPropertyChanged(nameof(CanSure));
38-
}
39-
}
40-
41-
public override bool CanSure => Permanent;
42-
4327
public TrustRepository(string pageId, string path, string reason, string safeDirectory, RepositoryNode parent, bool moveNode, bool open, int bookmark)
4428
{
4529
_pageId = pageId;
@@ -50,15 +34,12 @@ public TrustRepository(string pageId, string path, string reason, string safeDir
5034

5135
TargetPath = path;
5236
SafeDirectory = safeDirectory;
53-
Command = $"git config --global --add safe.directory {safeDirectory.Quoted()}";
37+
Command = App.Text("TrustRepository.CommandTip", safeDirectory);
5438
Reason = GetReason(reason);
5539
}
5640

5741
public override async Task<bool> Sure()
5842
{
59-
if (!Permanent)
60-
return false;
61-
6243
var log = new CommandLog("Trust Repository");
6344
Use(log);
6445

@@ -120,6 +101,5 @@ private static string GetReason(string stderr)
120101
private readonly bool _moveNode;
121102
private readonly bool _open;
122103
private readonly int _bookmark;
123-
private bool _permanent = false;
124104
}
125105
}

‎src/ViewModels/Welcome.cs‎

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Threading;
54
using System.Threading.Tasks;
65

@@ -100,40 +99,16 @@ public void ToggleNodeIsExpanded(RepositoryNode node)
10099
}
101100
}
102101

103-
public async Task<string> GetRepositoryRootAsync(string path, RepositoryNode parent = null)
102+
public async Task<Commands.Command.Result> GetRepositoryRootAsync(string path)
104103
{
105104
if (!Preferences.Instance.IsGitConfigured())
106-
{
107-
Models.Notification.Send(null, App.Text("NotConfigured"), true);
108-
return null;
109-
}
110-
111-
var root = path;
112-
if (!Directory.Exists(root))
113-
{
114-
if (File.Exists(root))
115-
root = Path.GetDirectoryName(root);
116-
else
117-
return null;
118-
}
105+
return Commands.Command.Result.Failed(App.Text("NotConfigured"));
119106

120-
var isBare = await new Commands.IsBareRepository(root).GetResultAsync();
107+
var isBare = await new Commands.IsBareRepository(path).GetResultAsync();
121108
if (isBare)
122-
return root;
123-
124-
var rs = await new Commands.QueryRepositoryRootPath(root).GetResultAsync();
125-
if (rs.IsSuccess && !string.IsNullOrWhiteSpace(rs.StdOut))
126-
return rs.StdOut.Trim();
127-
128-
if (Models.SafeDirectories.IsUntrustedRepository(rs.StdErr) &&
129-
Models.SafeDirectories.TryGetSafeDirectoryValue(root, rs.StdErr, out var safeDirectory))
130-
{
131-
var launcher = App.GetLauncher();
132-
if (launcher?.ActivePage is { } page && page.CanCreatePopup())
133-
page.Popup = new TrustRepository(page.Node.Id, root, rs.StdErr, safeDirectory, parent, true, false, 0);
134-
}
109+
return new Commands.Command.Result { IsSuccess = true, StdOut = path };
135110

136-
return null;
111+
return await new Commands.QueryRepositoryRootPath(path).GetResultAsync();
137112
}
138113

139114
public async Task AddRepositoryAsync(string path, RepositoryNode parent, bool moveNode, bool open)

‎src/Views/LauncherPage.axaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
Padding="0"
117117
HorizontalContentAlignment="Center"
118118
VerticalContentAlignment="Center"
119-
IsEnabled="{Binding CanSure}"
120119
Content="{DynamicResource Text.Sure}"
121120
Click="OnPopupSure"
122121
ToolTip.Tip="Enter"/>

‎src/Views/TrustRepository.axaml‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,16 @@
2828
Text="{Binding TargetPath}"/>
2929

3030
<TextBlock Grid.Row="1" Grid.Column="1"
31-
Margin="0,16,0,0"
31+
Margin="0,12"
3232
Foreground="{DynamicResource Brush.FG2}"
3333
TextWrapping="Wrap">
3434
<Run Text="{DynamicResource Text.TrustRepository.Description}"/>
3535
<Run Text="{Binding Reason, Mode=OneWay}"/>
3636
</TextBlock>
37-
38-
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Vertical" Margin="0,16,0,0">
39-
<CheckBox IsChecked="{Binding Permanent, Mode=TwoWay}">
40-
<TextBlock TextWrapping="Wrap"
41-
Text="{DynamicResource Text.TrustRepository.Permanent}"/>
42-
</CheckBox>
43-
44-
<TextBlock Margin="0,2,0,0"
45-
Foreground="{DynamicResource Brush.FG2}"
46-
TextWrapping="Wrap"
47-
IsVisible="{Binding Permanent}">
48-
<Run Text="{DynamicResource Text.TrustRepository.CommandTip}"/>
49-
<Run Text="{Binding Command, Mode=OneWay}"/>
50-
</TextBlock>
51-
</StackPanel>
37+
38+
<TextBlock Grid.Row="2" Grid.Column="1"
39+
Text="{Binding Command, Mode=OneWay}"
40+
TextWrapping="Wrap"/>
5241
</Grid>
5342
</StackPanel>
5443
</UserControl>

0 commit comments

Comments
 (0)