mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-01 01:14:59 +00:00
feature: support to use relative path as submodule's url when adding new submodule (#1339)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
ece51fbd32
commit
438aa76695
3 changed files with 28 additions and 14 deletions
|
@ -13,7 +13,7 @@ namespace SourceGit.Commands
|
|||
|
||||
public bool Add(string url, string relativePath, bool recursive)
|
||||
{
|
||||
Args = $"submodule add {url} \"{relativePath}\"";
|
||||
Args = $"-c protocol.file.allow=always submodule add \"{url}\" \"{relativePath}\"";
|
||||
if (!Exec())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -50,7 +50,11 @@ namespace SourceGit.Models
|
|||
return true;
|
||||
}
|
||||
|
||||
return url.EndsWith(".git", StringComparison.Ordinal) && Directory.Exists(url);
|
||||
var localPath = url;
|
||||
if (url.StartsWith("file://", StringComparison.Ordinal))
|
||||
localPath = url.Substring(7);
|
||||
|
||||
return Directory.Exists(localPath);
|
||||
}
|
||||
|
||||
public bool TryGetVisitURL(out string url)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -35,24 +36,33 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public static ValidationResult ValidateURL(string url, ValidationContext ctx)
|
||||
{
|
||||
if (!Models.Remote.IsValidURL(url))
|
||||
return new ValidationResult("Invalid repository URL format");
|
||||
return ValidationResult.Success;
|
||||
if (ctx.ObjectInstance is AddSubmodule)
|
||||
{
|
||||
if (!Models.Remote.IsValidURL(url) &&
|
||||
!url.StartsWith("./", StringComparison.Ordinal) &&
|
||||
!url.StartsWith("../", StringComparison.Ordinal))
|
||||
return new ValidationResult("Invalid repository URL format");
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
return new ValidationResult("Missing validation context");
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateRelativePath(string path, ValidationContext ctx)
|
||||
{
|
||||
if (Path.Exists(path))
|
||||
if (ctx.ObjectInstance is AddSubmodule asm)
|
||||
{
|
||||
return new ValidationResult("Give path is exists already!");
|
||||
}
|
||||
if (!path.StartsWith("./", StringComparison.Ordinal))
|
||||
return new ValidationResult("Path must be relative to this repository!");
|
||||
|
||||
if (Path.Exists(Path.GetFullPath(path, asm._repo.FullPath)))
|
||||
return new ValidationResult("Give path is exists already!");
|
||||
|
||||
if (Path.IsPathRooted(path))
|
||||
{
|
||||
return new ValidationResult("Path must be relative to this repository!");
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
|
||||
return new ValidationResult("Missing validation context");
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue