public static string GetCacheDirectory(GitPreparer gitPreparer) { var gitDir = gitPreparer.GetDotGitDirectory(); var cacheDir = Path.Combine(gitDir, "gitversion_cache"); return(cacheDir); }
public void GetDotGitDirectoryWorktree() { RepositoryScope((fixture, vv) => { var worktreePath = Path.Combine(Directory.GetParent(fixture.RepositoryPath).FullName, Guid.NewGuid().ToString()); try { // create a branch and a new worktree for it var repo = new Repository(fixture.RepositoryPath); repo.Worktrees.Add("worktree", worktreePath, false); var targetUrl = "https://github.com/GitTools/GitVersion.git"; var arguments = new Arguments { TargetUrl = targetUrl, TargetPath = worktreePath }; var gitPreparer = new GitPreparer(log, environment, Options.Create(arguments)); var expectedPath = Path.Combine(fixture.RepositoryPath, ".git"); gitPreparer.GetDotGitDirectory().ShouldBe(expectedPath); } finally { DirectoryHelper.DeleteDirectory(worktreePath); } }); }
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(new Config())) { var expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split('\\').Last()); fixture.Repository.MakeCommits(5); fixture.Repository.CreateFileAndCommit("TestFile.txt"); fixture.Repository.CreateBranch(SpecificBranchName); var arguments = new Arguments { TargetPath = tempDir, TargetUrl = fixture.RepositoryPath }; // Copy contents into working directory File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt")); if (!string.IsNullOrWhiteSpace(branchName)) { arguments.TargetBranch = branchName; } var gitPreparer = new GitPreparer(arguments); gitPreparer.InitialiseDynamicRepositoryIfNeeded(); dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); gitPreparer.IsDynamicGitRepository.ShouldBe(true); gitPreparer.DynamicGitRepositoryPath.ShouldBe(expectedDynamicRepoLocation + "\\.git"); using (var repository = new Repository(dynamicRepositoryPath)) { var currentBranch = repository.Head.CanonicalName; currentBranch.EndsWith(expectedBranchName).ShouldBe(true); } } } finally { Directory.Delete(tempDir, true); if (dynamicRepositoryPath != null) { DeleteHelper.DeleteGitRepository(dynamicRepositoryPath); } } }
static string GetGitSystemHash(GitPreparer gitPreparer) { var dotGitDirectory = gitPreparer.GetDotGitDirectory(); // traverse the directory and get a list of files, use that for GetHash var contents = CalculateDirectoryContents(Path.Combine(dotGitDirectory, "refs")); return(GetHash(contents.ToArray())); }
public void WorksCorrectlyWithLocalRepository() { var tempDir = Path.GetTempPath(); var gitPreparer = new GitPreparer(null, null, null, false, tempDir); var dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); dynamicRepositoryPath.ShouldBe(null); gitPreparer.IsDynamicGitRepository.ShouldBe(false); }
public void GetDotGitDirectory_NoWorktree() { var versionAndBranchFinder = new ExecuteCore(fileSystem, environment); RepositoryScope(versionAndBranchFinder, (fixture, vv) => { var targetUrl = "https://github.com/GitTools/GitVersion.git"; var gitPreparer = new GitPreparer(targetUrl, null, new Authentication(), false, fixture.RepositoryPath); var expectedPath = Path.Combine(fixture.RepositoryPath, ".git"); gitPreparer.GetDotGitDirectory().ShouldBe(expectedPath); }); }
public void WorksCorrectlyWithLocalRepository() { using (var fixture = new EmptyRepositoryFixture(new Config())) { var targetPath = Path.Combine(fixture.RepositoryPath, "tools\\gitversion\\"); Directory.CreateDirectory(targetPath); var gitPreparer = new GitPreparer(null, null, null, false, targetPath); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); dotGitDirectory.ShouldBe(Path.Combine(fixture.RepositoryPath, ".git")); projectRoot.ShouldBe(fixture.RepositoryPath); } }
public void WorksCorrectlyWithLocalRepository() { var tempDir = Path.GetTempPath(); var arguments = new Arguments { TargetPath = tempDir }; var gitPreparer = new GitPreparer(arguments); var dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); dynamicRepositoryPath.ShouldBe(null); gitPreparer.IsDynamicGitRepository.ShouldBe(false); }
public void WorksCorrectlyWithLocalRepository() { var tempDir = Path.GetTempPath(); var arguments = new Arguments { TargetPath = tempDir }; var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath); var dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); dynamicRepositoryPath.ShouldBe(null); gitPreparer.IsDynamicGitRepository.ShouldBe(false); }
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(new Config())) { mainRepositoryFixture.Repository.MakeCommits(1); var arguments = new Arguments { TargetPath = tempDir, TargetUrl = mainRepositoryFixture.RepositoryPath, TargetBranch = "master" }; var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath); gitPreparer.Initialise(false); dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); var newCommit = mainRepositoryFixture.Repository.MakeACommit(); gitPreparer.Initialise(false); using (var repository = new Repository(dynamicRepositoryPath)) { mainRepositoryFixture.Repository.DumpGraph(); repository.DumpGraph(); repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha); } } } finally { Directory.Delete(tempDir, true); if (dynamicRepositoryPath != null) { DeleteHelper.DeleteGitRepository(dynamicRepositoryPath); } } }
public void GetDotGitDirectoryNoWorktree() { RepositoryScope((fixture, vv) => { var targetUrl = "https://github.com/GitTools/GitVersion.git"; var arguments = new Arguments { TargetUrl = targetUrl, TargetPath = fixture.RepositoryPath }; var gitPreparer = new GitPreparer(log, environment, Options.Create(arguments)); var expectedPath = Path.Combine(fixture.RepositoryPath, ".git"); gitPreparer.GetDotGitDirectory().ShouldBe(expectedPath); }); }
public void GetDotGitDirectory_Worktree() { var versionAndBranchFinder = new ExecuteCore(fileSystem, environment); RepositoryScope(versionAndBranchFinder, (fixture, vv) => { var worktreePath = Path.Combine(Directory.GetParent(fixture.RepositoryPath).FullName, Guid.NewGuid().ToString()); try { // create a branch and a new worktree for it var repo = new Repository(fixture.RepositoryPath); repo.Worktrees.Add("worktree", worktreePath, false); var targetUrl = "https://github.com/GitTools/GitVersion.git"; var gitPreparer = new GitPreparer(targetUrl, null, new Authentication(), false, worktreePath); var expectedPath = Path.Combine(fixture.RepositoryPath, ".git"); gitPreparer.GetDotGitDirectory().ShouldBe(expectedPath); } finally { DirectoryHelper.DeleteDirectory(worktreePath); } }); }