Skip to content

Commit 71b90a8

Browse files
committed
refactor: remove validation for relative path while adding submodule (#1339)
Signed-off-by: leo <[email protected]>
1 parent d304c50 commit 71b90a8

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

src/ViewModels/AddSubmodule.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ public string Url
1515
set => SetProperty(ref _url, value, true);
1616
}
1717

18-
[Required(ErrorMessage = "Reletive path is required!!!")]
19-
[CustomValidation(typeof(AddSubmodule), nameof(ValidateRelativePath))]
2018
public string RelativePath
2119
{
2220
get => _relativePath;
23-
set => SetProperty(ref _relativePath, value, true);
21+
set => SetProperty(ref _relativePath, value);
2422
}
2523

2624
public bool Recursive
@@ -49,22 +47,6 @@ public static ValidationResult ValidateURL(string url, ValidationContext ctx)
4947
return new ValidationResult("Missing validation context");
5048
}
5149

52-
public static ValidationResult ValidateRelativePath(string path, ValidationContext ctx)
53-
{
54-
if (ctx.ObjectInstance is AddSubmodule asm)
55-
{
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!");
61-
62-
return ValidationResult.Success;
63-
}
64-
65-
return new ValidationResult("Missing validation context");
66-
}
67-
6850
public override Task<bool> Sure()
6951
{
7052
_repo.SetWatcherEnabled(false);
@@ -73,9 +55,20 @@ public override Task<bool> Sure()
7355
var log = _repo.CreateLog("Add Submodule");
7456
Use(log);
7557

58+
var relativePath = _relativePath;
59+
if (string.IsNullOrEmpty(relativePath))
60+
{
61+
if (_url.EndsWith("/.git", StringComparison.Ordinal))
62+
relativePath = Path.GetFileName(Path.GetDirectoryName(_url));
63+
else if (_url.EndsWith(".git", StringComparison.Ordinal))
64+
relativePath = Path.GetFileNameWithoutExtension(_url);
65+
else
66+
relativePath = Path.GetFileName(_url);
67+
}
68+
7669
return Task.Run(() =>
7770
{
78-
var succ = new Commands.Submodule(_repo.FullPath).Use(log).Add(_url, _relativePath, Recursive);
71+
var succ = new Commands.Submodule(_repo.FullPath).Use(log).Add(_url, relativePath, Recursive);
7972
log.Complete();
8073

8174
CallUIThread(() => _repo.SetWatcherEnabled(true));

0 commit comments

Comments
 (0)