|
1 | | -using System.ComponentModel.DataAnnotations; |
| 1 | +using System; |
| 2 | +using System.ComponentModel.DataAnnotations; |
2 | 3 | using System.IO; |
3 | 4 | using System.Threading.Tasks; |
4 | 5 |
|
@@ -35,24 +36,33 @@ public AddSubmodule(Repository repo) |
35 | 36 |
|
36 | 37 | public static ValidationResult ValidateURL(string url, ValidationContext ctx) |
37 | 38 | { |
38 | | - if (!Models.Remote.IsValidURL(url)) |
39 | | - return new ValidationResult("Invalid repository URL format"); |
40 | | - return ValidationResult.Success; |
| 39 | + if (ctx.ObjectInstance is AddSubmodule) |
| 40 | + { |
| 41 | + if (!Models.Remote.IsValidURL(url) && |
| 42 | + !url.StartsWith("./", StringComparison.Ordinal) && |
| 43 | + !url.StartsWith("../", StringComparison.Ordinal)) |
| 44 | + return new ValidationResult("Invalid repository URL format"); |
| 45 | + |
| 46 | + return ValidationResult.Success; |
| 47 | + } |
| 48 | + |
| 49 | + return new ValidationResult("Missing validation context"); |
41 | 50 | } |
42 | 51 |
|
43 | 52 | public static ValidationResult ValidateRelativePath(string path, ValidationContext ctx) |
44 | 53 | { |
45 | | - if (Path.Exists(path)) |
| 54 | + if (ctx.ObjectInstance is AddSubmodule asm) |
46 | 55 | { |
47 | | - return new ValidationResult("Give path is exists already!"); |
48 | | - } |
| 56 | + if (!path.StartsWith("./", StringComparison.Ordinal)) |
| 57 | + return new ValidationResult("Path must be relative to this repository!"); |
| 58 | + |
| 59 | + if (Path.Exists(Path.GetFullPath(path, asm._repo.FullPath))) |
| 60 | + return new ValidationResult("Give path is exists already!"); |
49 | 61 |
|
50 | | - if (Path.IsPathRooted(path)) |
51 | | - { |
52 | | - return new ValidationResult("Path must be relative to this repository!"); |
| 62 | + return ValidationResult.Success; |
53 | 63 | } |
54 | | - |
55 | | - return ValidationResult.Success; |
| 64 | + |
| 65 | + return new ValidationResult("Missing validation context"); |
56 | 66 | } |
57 | 67 |
|
58 | 68 | public override Task<bool> Sure() |
|
0 commit comments