mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-25 20:34:59 +00:00
Add support to configure different remote push url
This commit is contained in:
parent
af888e17de
commit
5e37d997c8
6 changed files with 89 additions and 4 deletions
|
@ -30,10 +30,16 @@ namespace SourceGit.Commands
|
||||||
var remote = new Models.Remote()
|
var remote = new Models.Remote()
|
||||||
{
|
{
|
||||||
Name = match.Groups[1].Value,
|
Name = match.Groups[1].Value,
|
||||||
URL = match.Groups[2].Value,
|
URL = match.Groups[0].Value.Contains("fetch") ? match.Groups[2].Value : "",
|
||||||
|
PushURL = match.Groups[0].Value.Contains("push") ? match.Groups[2].Value : "",
|
||||||
};
|
};
|
||||||
|
var alreadyFound = _loaded.Find(x => x.Name == remote.Name);
|
||||||
|
if (alreadyFound != null && !string.IsNullOrEmpty(remote.PushURL))
|
||||||
|
{
|
||||||
|
alreadyFound.PushURL = alreadyFound.URL != remote.PushURL ? remote.PushURL : "";
|
||||||
|
}
|
||||||
|
|
||||||
if (_loaded.Find(x => x.Name == remote.Name) != null)
|
if (alreadyFound != null)
|
||||||
return;
|
return;
|
||||||
_loaded.Add(remote);
|
_loaded.Add(remote);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,24 @@
|
||||||
public bool SetURL(string name, string url)
|
public bool SetURL(string name, string url)
|
||||||
{
|
{
|
||||||
Args = $"remote set-url {name} {url}";
|
Args = $"remote set-url {name} {url}";
|
||||||
|
var first = Exec();
|
||||||
|
Args = $"remote set-url {name} {url} --push";
|
||||||
|
return Exec() && first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SetPushURL(string name, string oldUrl, string newUrl)
|
||||||
|
{
|
||||||
|
if (oldUrl == newUrl)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(newUrl) && !string.IsNullOrEmpty(oldUrl))
|
||||||
|
{
|
||||||
|
Args = $"remote set-url --push --delete {name} {oldUrl}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Args = $"remote set-url --push {name} {newUrl}";
|
||||||
|
}
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string URL { get; set; }
|
public string URL { get; set; }
|
||||||
|
public string PushURL { get; set; }
|
||||||
|
|
||||||
public static bool IsSSH(string url)
|
public static bool IsSSH(string url)
|
||||||
{
|
{
|
||||||
|
|
|
@ -477,7 +477,9 @@
|
||||||
<x:String x:Key="Text.Remote.Name" xml:space="preserve">Name:</x:String>
|
<x:String x:Key="Text.Remote.Name" xml:space="preserve">Name:</x:String>
|
||||||
<x:String x:Key="Text.Remote.Name.Placeholder" xml:space="preserve">Remote name</x:String>
|
<x:String x:Key="Text.Remote.Name.Placeholder" xml:space="preserve">Remote name</x:String>
|
||||||
<x:String x:Key="Text.Remote.URL" xml:space="preserve">Repository URL:</x:String>
|
<x:String x:Key="Text.Remote.URL" xml:space="preserve">Repository URL:</x:String>
|
||||||
|
<x:String x:Key="Text.Remote.PushURL" xml:space="preserve">Push URL:</x:String>
|
||||||
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">Remote git repository URL</x:String>
|
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">Remote git repository URL</x:String>
|
||||||
|
<x:String x:Key="Text.Remote.PushURL.Placeholder" xml:space="preserve">Leave empty if same as URL</x:String>
|
||||||
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">Copy URL</x:String>
|
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">Copy URL</x:String>
|
||||||
<x:String x:Key="Text.RemoteCM.Delete" xml:space="preserve">Delete...</x:String>
|
<x:String x:Key="Text.RemoteCM.Delete" xml:space="preserve">Delete...</x:String>
|
||||||
<x:String x:Key="Text.RemoteCM.Edit" xml:space="preserve">Edit...</x:String>
|
<x:String x:Key="Text.RemoteCM.Edit" xml:space="preserve">Edit...</x:String>
|
||||||
|
|
|
@ -27,6 +27,17 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[CustomValidation(typeof(EditRemote), nameof(ValidatePushUrl))]
|
||||||
|
public string PushUrl
|
||||||
|
{
|
||||||
|
get => _pushUrl;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (SetProperty(ref _pushUrl, value, true))
|
||||||
|
UseSSH = Models.Remote.IsSSH(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool UseSSH
|
public bool UseSSH
|
||||||
{
|
{
|
||||||
get => _useSSH;
|
get => _useSSH;
|
||||||
|
@ -50,6 +61,7 @@ namespace SourceGit.ViewModels
|
||||||
_remote = remote;
|
_remote = remote;
|
||||||
_name = remote.Name;
|
_name = remote.Name;
|
||||||
_url = remote.URL;
|
_url = remote.URL;
|
||||||
|
_pushUrl = remote.PushURL;
|
||||||
_useSSH = Models.Remote.IsSSH(remote.URL);
|
_useSSH = Models.Remote.IsSSH(remote.URL);
|
||||||
|
|
||||||
if (_useSSH)
|
if (_useSSH)
|
||||||
|
@ -91,6 +103,28 @@ namespace SourceGit.ViewModels
|
||||||
return ValidationResult.Success;
|
return ValidationResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ValidationResult ValidatePushUrl(string pushUrl, ValidationContext ctx)
|
||||||
|
{
|
||||||
|
if (ctx.ObjectInstance is EditRemote edit)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(pushUrl))
|
||||||
|
{
|
||||||
|
return ValidationResult.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Models.Remote.IsValidURL(pushUrl))
|
||||||
|
return new ValidationResult("Bad remote URL format!!!");
|
||||||
|
|
||||||
|
foreach (var remote in edit._repo.Remotes)
|
||||||
|
{
|
||||||
|
if (remote != edit._remote && pushUrl == remote.PushURL)
|
||||||
|
return new ValidationResult("A remote with the same url already exists!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ValidationResult.Success;
|
||||||
|
}
|
||||||
|
|
||||||
public static ValidationResult ValidateSSHKey(string sshkey, ValidationContext ctx)
|
public static ValidationResult ValidateSSHKey(string sshkey, ValidationContext ctx)
|
||||||
{
|
{
|
||||||
if (ctx.ObjectInstance is EditRemote { _useSSH: true } && !string.IsNullOrEmpty(sshkey))
|
if (ctx.ObjectInstance is EditRemote { _useSSH: true } && !string.IsNullOrEmpty(sshkey))
|
||||||
|
@ -123,6 +157,18 @@ namespace SourceGit.ViewModels
|
||||||
_remote.URL = _url;
|
_remote.URL = _url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_pushUrl == _url)
|
||||||
|
{
|
||||||
|
_pushUrl = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_remote.PushURL != _pushUrl)
|
||||||
|
{
|
||||||
|
var succ = new Commands.Remote(_repo.FullPath).SetPushURL(_name, _remote.PushURL, _pushUrl);
|
||||||
|
if (succ)
|
||||||
|
_remote.PushURL = _pushUrl;
|
||||||
|
}
|
||||||
|
|
||||||
SetProgressDescription("Post processing ...");
|
SetProgressDescription("Post processing ...");
|
||||||
new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
|
new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
|
||||||
|
|
||||||
|
@ -135,6 +181,7 @@ namespace SourceGit.ViewModels
|
||||||
private readonly Models.Remote _remote = null;
|
private readonly Models.Remote _remote = null;
|
||||||
private string _name = null;
|
private string _name = null;
|
||||||
private string _url = null;
|
private string _url = null;
|
||||||
|
private string _pushUrl = null;
|
||||||
private bool _useSSH = false;
|
private bool _useSSH = false;
|
||||||
private string _sshkey = string.Empty;
|
private string _sshkey = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,22 @@
|
||||||
Text="{Binding Url, Mode=TwoWay}"/>
|
Text="{Binding Url, Mode=TwoWay}"/>
|
||||||
|
|
||||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||||
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
|
Margin="0,0,8,0"
|
||||||
|
Text="{DynamicResource Text.Remote.PushURL}"/>
|
||||||
|
<TextBox Grid.Row="2" Grid.Column="1"
|
||||||
|
Height="26"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
CornerRadius="2"
|
||||||
|
Watermark="{DynamicResource Text.Remote.PushURL.Placeholder}"
|
||||||
|
Text="{Binding PushUrl, Mode=TwoWay}"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="3" Grid.Column="0"
|
||||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
Margin="0,0,8,0"
|
Margin="0,0,8,0"
|
||||||
Text="{DynamicResource Text.SSHKey}"
|
Text="{DynamicResource Text.SSHKey}"
|
||||||
IsVisible="{Binding UseSSH}"/>
|
IsVisible="{Binding UseSSH}"/>
|
||||||
<TextBox Grid.Row="2" Grid.Column="1"
|
<TextBox Grid.Row="3" Grid.Column="1"
|
||||||
x:Name="TxtSshKey"
|
x:Name="TxtSshKey"
|
||||||
Height="26"
|
Height="26"
|
||||||
CornerRadius="3"
|
CornerRadius="3"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue