fix: commit stucks when using SSH formatted GPG signing with a key contains non-empty passphrase

This commit is contained in:
leo 2024-07-09 17:56:23 +08:00
parent 386c92fa28
commit 9db050e8c2
No known key found for this signature in database
5 changed files with 19 additions and 19 deletions

View file

@ -458,12 +458,8 @@ namespace SourceGit
var args = desktop.Args;
if (args.Length <= 1 || !args[0].Equals("--askpass", StringComparison.Ordinal))
return false;
var match = REG_ASKPASS().Match(args[1]);
if (!match.Success)
return false;
desktop.MainWindow = new Views.Askpass(Path.GetFileName(match.Groups[1].Value));
desktop.MainWindow = new Views.Askpass(args[1]);
return true;
}
@ -483,9 +479,6 @@ namespace SourceGit
}
}
[GeneratedRegex(@"Enter\s+passphrase\s*for\s*key\s*['""]([^'""]+)['""]\:\s*", RegexOptions.IgnoreCase)]
private static partial Regex REG_ASKPASS();
private ViewModels.Launcher _launcher = null;
private ResourceDictionary _activeLocale = null;
private ResourceDictionary _themeOverrides = null;

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using Avalonia.Threading;
namespace SourceGit.Commands
@ -38,11 +39,16 @@ namespace SourceGit.Commands
public Dictionary<string, string> Envs { get; set; } = new Dictionary<string, string>();
public void UseSSHKey(string key)
{
UseSSHAskpass();
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{key}'");
}
public void UseSSHAskpass()
{
Envs.Add("DISPLAY", "required");
Envs.Add("SSH_ASKPASS", $"\"{Process.GetCurrentProcess().MainModule.FileName}\" --askpass");
Envs.Add("SSH_ASKPASS_REQUIRE", "prefer");
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{key}'");
}
public bool Exec()

View file

@ -1,4 +1,5 @@
using System.IO;
using System.Diagnostics;
using System.IO;
namespace SourceGit.Commands
{
@ -11,6 +12,7 @@ namespace SourceGit.Commands
WorkingDirectory = repo;
Context = repo;
TraitErrorAsOutput = true;
Args = $"commit --file=\"{file}\"";
if (autoStage)
Args += " --all";
@ -18,6 +20,8 @@ namespace SourceGit.Commands
Args += " --amend --no-edit";
if (allowEmpty)
Args += " --allow-empty";
UseSSHAskpass();
}
}
}

View file

@ -50,12 +50,9 @@
</Grid>
<StackPanel Grid.Row="1" Margin="0,16" Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="16,0">
<TextBlock Text="Enter passphrase for key: "/>
<Border Background="{DynamicResource Brush.Accent}" CornerRadius="4">
<TextBlock Text="{Binding KeyName}" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
</Border>
</StackPanel>
<Border Margin="16,0">
<TextBlock Text="{Binding Description}" TextWrapping="Wrap"/>
</Border>
<TextBox Margin="16"
MinWidth="300"

View file

@ -17,7 +17,7 @@ namespace SourceGit.Views
set => SetValue(ShowPasswordProperty, value);
}
public string KeyName
public string Description
{
get;
private set;
@ -35,9 +35,9 @@ namespace SourceGit.Views
InitializeComponent();
}
public Askpass(string keyname)
public Askpass(string description)
{
KeyName = keyname;
Description = description;
DataContext = this;
InitializeComponent();
}