public void GetRepository_returns_expected_GitRepository_for_remote_urls(string remoteUrl) { using var sut = GitRepositoryFactory.GetRepository(remoteUrl); sut.Kind.Should().Be(RepositoryKind.Remote); sut.Should().BeAssignableTo <RemoteGitRepository>(); }
public void GetRepository_returns_expected_GitRepository_for_local_paths(string remoteUrl) { using var sut = GitRepositoryFactory.GetRepository(remoteUrl); sut.Kind.Should().Be(RepositoryKind.Local); sut.Should().BeAssignableTo <LocalGitRepository>(); }
public void TestErrorThrownForInvalidRepository() { var repoName = Guid.NewGuid().ToString(); var tempPath = Path.GetTempPath(); var tempDir = Path.Combine(tempPath, repoName); Directory.CreateDirectory(tempDir); try { var repositoryInfo = new RepositoryInfo { Url = "http://127.0.0.1/testrepo.git", Branch = "master" }; Should.Throw <Exception>(() => { using (var gitRepository = GitRepositoryFactory.CreateRepository(repositoryInfo)) { // this code shouldn't throw } }); } finally { Directory.Delete(tempDir, true); } }
public void UsingDynamicRepositoryWithoutTargetBranchFails() { var repoName = Guid.NewGuid().ToString(); var tempPath = Path.GetTempPath(); var tempDir = Path.Combine(tempPath, repoName); Directory.CreateDirectory(tempDir); try { using (var mainRepositoryFixture = new EmptyRepositoryFixture()) { mainRepositoryFixture.Repository.MakeACommit(); var repositoryInfo = new RepositoryInfo { Url = mainRepositoryFixture.RepositoryPath, Branch = null }; Should.Throw <Exception>(() => { using (var gitRepository = GitRepositoryFactory.CreateRepository(repositoryInfo)) { // this code shouldn't throw } }); } } finally { Directory.Delete(tempDir, true); } }
protected override async Task <IEnumerable <IDocument> > ExecuteContextAsync(IExecutionContext context) { m_RepositoryUrl.EnsureNonDocument(); var repositoryUrl = await m_RepositoryUrl.GetValueAsync(null, context); // load repository using var repository = GitRepositoryFactory.GetRepository(repositoryUrl); var matchingBranches = GetMatchingBranches(context, repository); var matchingTags = GetMatchingTags(context, repository); if (!matchingBranches.Any() && !matchingTags.Any()) { context.LogWarning("No branches or tags found that match any of the specified tag or branch names"); return(Enumerable.Empty <IDocument>()); } var outputs = new List <IDocument>(); // for each branch, read documents and add them to the output. foreach (var branchName in matchingBranches) { var commitId = repository.GetHeadCommitId(branchName); var rootDir = repository.GetRootDirectory(commitId); var branchOutputs = Globber .GetFiles(rootDir, m_FilePatterns) .Select(file => ReadFile( context: context, repository: repository, file: file, branchName: branchName, tagName: null) ); outputs.AddRange(branchOutputs); } // for each tag, read documents and add them to the output. foreach (var tag in matchingTags) { var rootDir = repository.GetRootDirectory(tag.Commit); var tagOutputs = Globber .GetFiles(rootDir, m_FilePatterns) .Select(file => ReadFile( context: context, repository: repository, file: file, branchName: null, tagName: tag.Name) ); outputs.AddRange(tagOutputs); } return(outputs); }
public void No_delete_and_clone_when_repo_is_valid( [Frozen] IRepositoryStaticWrapper wrapper, [Frozen] IFileUtilities fileUtils, GitRepositoryFactory sut) { wrapper.IsValid(Arg.Any <string>()).Returns(true); sut.CreateAndCloneIfNeeded("repo_url", "repo_path", "branch"); wrapper.Received().IsValid("repo_path"); fileUtils.DidNotReceiveWithAnyArgs().DeleteReadOnlyDirectory(default !);
public void Init(ProjectModel projectModel, GitRepositoryFactory factory) { _projectModel = projectModel; ProjectRootDir = _projectModel.ProjectRootDir; Type = (ProjectType)_projectModel.ProjectType; LiveRootDir = _projectModel.LiveRootDir; ProjectPublishedDir = Path.Combine(ProjectRootDir, "publish"); _gitRepository = factory.GetRepository(ProjectRootDir); _projectBuilder = ProjectBuilderFactory.GetBuilder(Type); _logger.LogInformation($"LiveRootDir = {LiveRootDir}, ProjectRootDir = {ProjectRootDir}, ProjectPublishedDir = {ProjectPublishedDir}"); }
public void ThrowsExceptionWhenNotEnoughInfo() { var tempDir = Path.GetTempPath(); var repositoryInfo = new RepositoryInfo { Url = tempDir, Branch = "master" }; Should.Throw <Exception>(() => GitRepositoryFactory.CreateRepository(repositoryInfo)); }
public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName) { var repoName = Guid.NewGuid().ToString(); var tempPath = Path.GetTempPath(); var tempDir = Path.Combine(tempPath, repoName); Directory.CreateDirectory(tempDir); string dynamicRepositoryPath = null; try { using (var fixture = new EmptyRepositoryFixture()) { var expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last()); fixture.Repository.MakeCommits(5); fixture.Repository.CreateFileAndCommit("TestFile.txt"); fixture.Repository.CreateBranch(SpecificBranchName); // Copy contents into working directory File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt")); var repositoryInfo = new RepositoryInfo { Url = fixture.RepositoryPath, Branch = branchName }; using (var gitRepository = GitRepositoryFactory.CreateRepository(repositoryInfo)) { dynamicRepositoryPath = gitRepository.DotGitDirectory; gitRepository.IsDynamic.ShouldBe(true); gitRepository.DotGitDirectory.ShouldBe(Path.Combine(expectedDynamicRepoLocation, ".git")); var currentBranch = gitRepository.Repository.Head.CanonicalName; currentBranch.ShouldEndWith(expectedBranchName); } } } finally { Directory.Delete(tempDir, true); if (dynamicRepositoryPath != null) { DeleteHelper.DeleteGitRepository(dynamicRepositoryPath); } } }
public void Delete_and_clone_when_repo_is_not_valid( [Frozen] IRepositoryStaticWrapper wrapper, [Frozen] IFileUtilities fileUtils, GitRepositoryFactory sut) { wrapper.IsValid(Arg.Any <string>()).Returns(false); sut.CreateAndCloneIfNeeded("repo_url", "repo_path", "branch"); Received.InOrder(() => { wrapper.IsValid("repo_path"); fileUtils.DeleteReadOnlyDirectory("repo_path"); wrapper.Clone("repo_url", "repo_path", Verify.That <CloneOptions>(x => x.BranchName.Should().Be("branch"))); }); }
public void UpdatesExistingDynamicRepository() { var repoName = Guid.NewGuid().ToString(); var tempPath = Path.GetTempPath(); var tempDir = Path.Combine(tempPath, repoName); Directory.CreateDirectory(tempDir); string dynamicRepositoryPath = null; try { using (var mainRepositoryFixture = new EmptyRepositoryFixture()) { mainRepositoryFixture.Repository.MakeCommits(1); var repositoryInfo = new RepositoryInfo { Url = mainRepositoryFixture.RepositoryPath, Branch = "master" }; using (var gitRepository = GitRepositoryFactory.CreateRepository(repositoryInfo)) { dynamicRepositoryPath = gitRepository.DotGitDirectory; } var newCommit = mainRepositoryFixture.Repository.MakeACommit(); using (var gitRepository = GitRepositoryFactory.CreateRepository(repositoryInfo)) { mainRepositoryFixture.Repository.DumpGraph(); gitRepository.Repository.DumpGraph(); gitRepository.Repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha); } } } finally { Directory.Delete(tempDir, true); if (dynamicRepositoryPath != null) { DeleteHelper.DeleteGitRepository(dynamicRepositoryPath); } } }
public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken() { var repoName = Guid.NewGuid().ToString(); var tempPath = Path.GetTempPath(); var tempDir = Path.Combine(tempPath, repoName); Directory.CreateDirectory(tempDir); string expectedDynamicRepoLocation = null; try { using (var fixture = new EmptyRepositoryFixture()) { fixture.Repository.CreateFileAndCommit("TestFile.txt"); File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt")); expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last()); Directory.CreateDirectory(expectedDynamicRepoLocation); var repositoryInfo = new RepositoryInfo { Url = fixture.RepositoryPath, Branch = "master" }; using (var gitRepository = GitRepositoryFactory.CreateRepository(repositoryInfo)) { gitRepository.IsDynamic.ShouldBe(true); gitRepository.DotGitDirectory.ShouldBe(Path.Combine(expectedDynamicRepoLocation + "_1", ".git")); } } } finally { DeleteHelper.DeleteDirectory(tempDir, true); if (expectedDynamicRepoLocation != null) { DeleteHelper.DeleteDirectory(expectedDynamicRepoLocation, true); } if (expectedDynamicRepoLocation != null) { DeleteHelper.DeleteGitRepository(expectedDynamicRepoLocation + "_1"); } } }
public void UsingDynamicRepositoryWithFeatureBranchWorks() { var repoName = Guid.NewGuid().ToString(); var tempPath = Path.GetTempPath(); var tempDir = Path.Combine(tempPath, repoName); Directory.CreateDirectory(tempDir); try { using (var mainRepositoryFixture = new EmptyRepositoryFixture()) { mainRepositoryFixture.Repository.MakeACommit(); var repositoryInfo = new RepositoryInfo { Url = mainRepositoryFixture.RepositoryPath, Branch = "feature1" }; mainRepositoryFixture.Repository.Checkout(mainRepositoryFixture.Repository.CreateBranch("feature1")); Should.NotThrow(() => { using (var gitRepository = GitRepositoryFactory.CreateRepository(repositoryInfo)) { // this code shouldn't throw } }); } } finally { Directory.Delete(tempDir, true); } }
public void GetRepository_throws_ArgumentException_for_unsupported_remote_urls(string remoteUrl) { Action act = () => GitRepositoryFactory.GetRepository(remoteUrl); act.Should().Throw <ArgumentException>(); }