@@ -15,12 +15,10 @@ public string Url
15
15
set => SetProperty ( ref _url , value , true ) ;
16
16
}
17
17
18
- [ Required ( ErrorMessage = "Reletive path is required!!!" ) ]
19
- [ CustomValidation ( typeof ( AddSubmodule ) , nameof ( ValidateRelativePath ) ) ]
20
18
public string RelativePath
21
19
{
22
20
get => _relativePath ;
23
- set => SetProperty ( ref _relativePath , value , true ) ;
21
+ set => SetProperty ( ref _relativePath , value ) ;
24
22
}
25
23
26
24
public bool Recursive
@@ -49,22 +47,6 @@ public static ValidationResult ValidateURL(string url, ValidationContext ctx)
49
47
return new ValidationResult ( "Missing validation context" ) ;
50
48
}
51
49
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
-
68
50
public override Task < bool > Sure ( )
69
51
{
70
52
_repo . SetWatcherEnabled ( false ) ;
@@ -73,9 +55,20 @@ public override Task<bool> Sure()
73
55
var log = _repo . CreateLog ( "Add Submodule" ) ;
74
56
Use ( log ) ;
75
57
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
+
76
69
return Task . Run ( ( ) =>
77
70
{
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 ) ;
79
72
log . Complete ( ) ;
80
73
81
74
CallUIThread ( ( ) => _repo . SetWatcherEnabled ( true ) ) ;
0 commit comments