@@ -23,6 +23,7 @@ public class RepositoryCloneViewModel : ViewModelBase, IRepositoryCloneViewModel
2323 readonly IRepositoryCloneService service ;
2424 readonly IReadOnlyList < IRepositoryCloneTabViewModel > tabs ;
2525 string path ;
26+ string previousOwner ;
2627 ObservableAsPropertyHelper < string > pathError ;
2728 int selectedTabIndex ;
2829
@@ -50,7 +51,7 @@ public RepositoryCloneViewModel(
5051
5152 pathError = Observable . CombineLatest (
5253 repository ,
53- this . WhenAnyValue ( x => x . Path ) ,
54+ this . WhenAnyValue ( x => x . Path ) ,
5455 ValidatePath )
5556 . ToProperty ( this , x => x . PathError ) ;
5657
@@ -113,20 +114,38 @@ public async Task InitializeAsync(IConnection connection)
113114 this . WhenAnyValue ( x => x . SelectedTabIndex ) . Subscribe ( x => tabs [ x ] . Activate ( ) . Forget ( ) ) ;
114115 }
115116
116- void UpdatePath ( IRepositoryModel x )
117+ void UpdatePath ( IRepositoryModel repository )
117118 {
118- if ( x != null )
119+ if ( repository != null )
119120 {
120- if ( Path == service . DefaultClonePath )
121- {
122- Path = System . IO . Path . Combine ( Path , x . Name ) ;
123- }
124- else
121+ var basePath = GetBasePath ( Path , previousOwner ) ;
122+ previousOwner = repository . Owner ;
123+ Path = System . IO . Path . Combine ( basePath , repository . Owner , repository . Name ) ;
124+ }
125+ }
126+
127+ static string GetBasePath ( string path , string owner )
128+ {
129+ if ( owner != null )
130+ {
131+ var dir = path ;
132+ for ( var i = 0 ; i < 2 ; i ++ )
125133 {
126- var basePath = System . IO . Path . GetDirectoryName ( Path ) ;
127- Path = System . IO . Path . Combine ( basePath , x . Name ) ;
134+ if ( string . IsNullOrEmpty ( dir ) )
135+ {
136+ break ;
137+ }
138+
139+ var name = System . IO . Path . GetFileName ( dir ) ;
140+ dir = System . IO . Path . GetDirectoryName ( dir ) ;
141+ if ( name == owner )
142+ {
143+ return dir ;
144+ }
128145 }
129146 }
147+
148+ return path ;
130149 }
131150
132151 string ValidatePath ( IRepositoryModel repository , string path )
0 commit comments