feat: Add GitRepoRegistration cmdlets #5
2 changed files with 28 additions and 2 deletions
tests(git-provider): Add duplicated repo registration test
commit
30e103f021
|
|
@ -138,8 +138,15 @@ public class GitManager
|
|||
// we add it to the relevant dictionary
|
||||
if (directorySegmentsFromName.Count == 0)
|
||||
{
|
||||
FullRepositoryPath = absoluteRepositoryLocation;
|
||||
return this;
|
||||
// If this is a new registration, set the FullRepositoryPath and return, otherwise we've got a duplicate
|
||||
// entry and we throw
|
||||
if (FullRepositoryPath == null)
|
||||
{
|
||||
FullRepositoryPath = absoluteRepositoryLocation;
|
||||
return this;
|
||||
}
|
||||
|
||||
throw new Exception($"Registration already exists for {InternalPath}");
|
||||
}
|
||||
|
||||
var nextSegment = directorySegmentsFromName.Peek();
|
||||
|
|
|
|||
|
|
@ -74,4 +74,23 @@ public class AddRegistrationTests
|
|||
|
||||
Assert.Equal("repo", whitespaceName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DuplicateRepoRegistrationShouldFail()
|
||||
{
|
||||
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
||||
|
||||
var gitManager = GitManager.InternalFreshInstance;
|
||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||
string[] paths = ["test", "nested", "path"];
|
||||
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
||||
|
||||
var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator);
|
||||
// TODO: make nested registrations fail in both directions and test
|
||||
var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
|
||||
|
||||
Assert.Equal(Path.Combine(paths), firstRegistration);
|
||||
|
||||
Assert.Throws<Exception>(() => gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue