Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 785c5f6

Browse files
committed
Handle when just owner has been deleted
Don't include old the repository name when next repository is selected.
1 parent fca3a96 commit 785c5f6

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

src/GitHub.App/ViewModels/Dialog/Clone/RepositoryCloneViewModel.cs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class RepositoryCloneViewModel : ViewModelBase, IRepositoryCloneViewModel
2525
readonly IRepositoryCloneService service;
2626
readonly IReadOnlyList<IRepositoryCloneTabViewModel> tabs;
2727
string path;
28-
string previousOwner;
28+
IRepositoryModel previousRepository;
2929
ObservableAsPropertyHelper<string> pathError;
3030
int selectedTabIndex;
3131

@@ -143,41 +143,55 @@ void UpdatePath(IRepositoryModel repository)
143143
{
144144
if (repository != null)
145145
{
146-
var basePath = GetBasePath(Path, previousOwner);
147-
previousOwner = repository.Owner;
146+
var basePath = GetUpdatedBasePath(Path);
147+
previousRepository = repository;
148148
Path = System.IO.Path.Combine(basePath, repository.Owner, repository.Name);
149149
}
150150
}
151151

152-
string GetBasePath(string path, string owner)
152+
string GetUpdatedBasePath(string path)
153153
{
154154
if (string.IsNullOrEmpty(path))
155155
{
156156
return service.DefaultClonePath;
157157
}
158158

159-
if (string.IsNullOrEmpty(owner))
159+
if (previousRepository == null)
160160
{
161161
return path;
162162
}
163163

164-
var dir = path;
165-
for (var i = 0; i < 2; i++)
164+
if (FindDirWithout(path, previousRepository?.Owner, 2) is string dirWithoutOwner)
166165
{
167-
if (string.IsNullOrEmpty(dir))
168-
{
169-
break;
170-
}
166+
return dirWithoutOwner;
167+
}
171168

172-
var name = System.IO.Path.GetFileName(dir);
173-
dir = System.IO.Path.GetDirectoryName(dir);
174-
if (name == owner)
175-
{
176-
return dir;
177-
}
169+
if (FindDirWithout(path, previousRepository?.Name, 1) is string dirWithoutRepo)
170+
{
171+
return dirWithoutRepo;
178172
}
179173

180174
return path;
175+
176+
string FindDirWithout(string dir, string match, int levels)
177+
{
178+
for (var i = 0; i < 2; i++)
179+
{
180+
if (string.IsNullOrEmpty(dir))
181+
{
182+
break;
183+
}
184+
185+
var name = System.IO.Path.GetFileName(dir);
186+
dir = System.IO.Path.GetDirectoryName(dir);
187+
if (name == match)
188+
{
189+
return dir;
190+
}
191+
}
192+
193+
return null;
194+
}
181195
}
182196

183197
string ValidatePath(IRepositoryModel repository, string path)

0 commit comments

Comments
 (0)