Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 52491d6

Browse files
Populating repository name and clone uri from cache
1 parent f726c7f commit 52491d6

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

src/GitHub.Api/Git/Repository.cs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Repository : IEquatable<Repository>, IRepository
1313
{
1414
private IRepositoryManager repositoryManager;
1515
private ICacheContainer cacheContainer;
16+
private UriString cloneUrl;
17+
private string name;
1618

1719
public event Action<CacheUpdateEvent> GitStatusCacheUpdated;
1820
public event Action<CacheUpdateEvent> GitLogCacheUpdated;
@@ -23,22 +25,17 @@ class Repository : IEquatable<Repository>, IRepository
2325
/// <summary>
2426
/// Initializes a new instance of the <see cref="Repository"/> class.
2527
/// </summary>
26-
/// <param name="name">The repository name.</param>
2728
/// <param name="localPath"></param>
2829
/// <param name="container"></param>
29-
public Repository(string name, NPath localPath, ICacheContainer container)
30+
public Repository(NPath localPath, ICacheContainer container)
3031
{
31-
Guard.ArgumentNotNullOrWhiteSpace(name, nameof(name));
3232
Guard.ArgumentNotNull(localPath, nameof(localPath));
3333

34-
Name = name;
3534
LocalPath = localPath;
3635
User = new User();
3736

3837
cacheContainer = container;
39-
4038
cacheContainer.CacheInvalidated += CacheContainer_OnCacheInvalidated;
41-
4239
cacheContainer.CacheUpdated += CacheContainer_OnCacheUpdated;
4340
}
4441

@@ -533,9 +530,42 @@ public List<GitLock> CurrentLocks
533530
set { cacheContainer.GitLocksCache.GitLocks = value; }
534531
}
535532

536-
public UriString CloneUrl { get; private set; }
533+
public UriString CloneUrl
534+
{
535+
get
536+
{
537+
if (cloneUrl == null)
538+
{
539+
var currentRemote = CurrentRemote;
540+
if (currentRemote.HasValue && currentRemote.Value.Url != null)
541+
{
542+
cloneUrl = new UriString(currentRemote.Value.Url);
543+
}
544+
}
545+
return cloneUrl;
546+
}
547+
private set
548+
{
549+
cloneUrl = value;
550+
}
551+
}
537552

538-
public string Name { get; private set; }
553+
public string Name
554+
{
555+
get
556+
{
557+
if (name == null)
558+
{
559+
var url = CloneUrl;
560+
if (url != null)
561+
{
562+
name = url.RepositoryName;
563+
}
564+
}
565+
return name;
566+
}
567+
private set { name = value; }
568+
}
539569

540570
public NPath LocalPath { get; private set; }
541571

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void InitializeRepository(ICacheContainer cacheContainer, NPath expectedR
7979
{
8080
Logger.Trace("Determined expectedRepositoryPath:{0}", expectedRepositoryPath);
8181
RepositoryPath = expectedRepositoryPath;
82-
Repository = new Repository(RepositoryPath.FileName, RepositoryPath, cacheContainer);
82+
Repository = new Repository(RepositoryPath, cacheContainer);
8383
}
8484
}
8585

src/tests/IntegrationTests/BaseGitEnvironmentTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected async Task<IEnvironment> Initialize(NPath repoPath, NPath environmentP
3333

3434
//TODO: Mock CacheContainer
3535
ICacheContainer cacheContainer = null;
36-
Environment.Repository = new Repository("TestRepo", repoPath, cacheContainer);
36+
Environment.Repository = new Repository(repoPath, cacheContainer);
3737
Environment.Repository.Initialize(RepositoryManager);
3838

3939
RepositoryManager.Start();

src/tests/UnitTests/Git/RepositoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private static Repository LoadRepository()
2929

3030
//TODO: Mock CacheContainer
3131
ICacheContainer cacheContainer = null;
32-
return new Repository("TestRepo", @"C:\Repo".ToNPath(), cacheContainer);
32+
return new Repository(@"C:\Repo".ToNPath(), cacheContainer);
3333
}
3434

3535
private RepositoryEvents repositoryEvents;

0 commit comments

Comments
 (0)