diff --git a/src/Commands/Submodule.cs b/src/Commands/Submodule.cs index c8b676ea..7d88ca5b 100644 --- a/src/Commands/Submodule.cs +++ b/src/Commands/Submodule.cs @@ -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; diff --git a/src/Models/Remote.cs b/src/Models/Remote.cs index ec9b8f20..d45aa20f 100644 --- a/src/Models/Remote.cs +++ b/src/Models/Remote.cs @@ -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) diff --git a/src/ViewModels/AddSubmodule.cs b/src/ViewModels/AddSubmodule.cs index cf1bd8a3..47259daf 100644 --- a/src/ViewModels/AddSubmodule.cs +++ b/src/ViewModels/AddSubmodule.cs @@ -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 Sure()