public void GetVersionHeight_AddingExcludeDoesNotLowerHeight(string excludePathFilter) { this.InitializeSourceControl(); string relativeDirectory = "some-sub-dir"; var versionData = VersionOptions.FromVersion(new Version("1.2")); this.WriteVersionFile(versionData, relativeDirectory); Assert.Equal(1, this.GetVersionHeight(relativeDirectory)); // Commit a file which will later be ignored var ignoredFilePath = Path.Combine(this.RepoPath, "excluded-dir", "ignore.txt"); Directory.CreateDirectory(Path.GetDirectoryName(ignoredFilePath)); File.WriteAllText(ignoredFilePath, "hello"); Commands.Stage(this.Repo, ignoredFilePath); this.Repo.Commit("Add file which will later be excluded", this.Signer, this.Signer); Assert.Equal(2, this.GetVersionHeight(relativeDirectory)); versionData.PathFilters = new[] { new FilterPath(excludePathFilter, relativeDirectory), }; this.WriteVersionFile(versionData, relativeDirectory); Assert.Equal(3, this.GetVersionHeight(relativeDirectory)); // Committing a change to an ignored file does not increment the version height File.WriteAllText(ignoredFilePath, "changed"); Commands.Stage(this.Repo, ignoredFilePath); this.Repo.Commit("Change now excluded file", this.Signer, this.Signer); Assert.Equal(3, this.GetVersionHeight(relativeDirectory)); }
public void GetVersionHeight_IncludeExcludeFilter() { var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { "./", ":^/some-sub-dir/ignore.txt", ":^excluded-dir" }; this.WriteVersionFile(versionData, "some-sub-dir"); Assert.Equal(1, this.Repo.GetVersionHeight("some-sub-dir")); // Commit touching excluded path does not affect version height var ignoredFilePath = Path.Combine(this.RepoPath, "some-sub-dir", "ignore.txt"); File.WriteAllText(ignoredFilePath, "hello"); Commands.Stage(this.Repo, ignoredFilePath); this.Repo.Commit("Add excluded file", this.Signer, this.Signer); Assert.Equal(1, this.Repo.GetVersionHeight("some-sub-dir")); // Commit touching both excluded and included path does affect height var includedFilePath = Path.Combine(this.RepoPath, "some-sub-dir", "another-file.txt"); File.WriteAllText(includedFilePath, "hello"); File.WriteAllText(ignoredFilePath, "changed"); Commands.Stage(this.Repo, includedFilePath); Commands.Stage(this.Repo, ignoredFilePath); this.Repo.Commit("Change both excluded and included file", this.Signer, this.Signer); Assert.Equal(2, this.Repo.GetVersionHeight("some-sub-dir")); // Commit touching excluded directory does not affect version height var fileInExcludedDirPath = Path.Combine(this.RepoPath, "some-sub-dir", "excluded-dir", "ignore.txt"); Directory.CreateDirectory(Path.GetDirectoryName(fileInExcludedDirPath)); File.WriteAllText(fileInExcludedDirPath, "hello"); Commands.Stage(this.Repo, fileInExcludedDirPath); this.Repo.Commit("Add file to excluded dir", this.Signer, this.Signer); Assert.Equal(2, this.Repo.GetVersionHeight("some-sub-dir")); }
public void GetVersionHeight_IncludeRoot() { this.InitializeSourceControl(); string relativeDirectory = "some-sub-dir"; var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { new FilterPath(":/", relativeDirectory) }; this.WriteVersionFile(versionData, relativeDirectory); Assert.Equal(1, this.GetVersionHeight(relativeDirectory)); // Expect commit outside of project tree to affect version height var otherFilePath = Path.Combine(this.RepoPath, "my-file.txt"); File.WriteAllText(otherFilePath, "hello"); Commands.Stage(this.Repo, otherFilePath); this.Repo.Commit("Add other file outside of project root", this.Signer, this.Signer); Assert.Equal(2, this.GetVersionHeight(relativeDirectory)); // Expect commit inside project tree to affect version height var containedFilePath = Path.Combine(this.RepoPath, relativeDirectory, "another-file.txt"); File.WriteAllText(containedFilePath, "hello"); Commands.Stage(this.Repo, containedFilePath); this.Repo.Commit("Add file within project root", this.Signer, this.Signer); Assert.Equal(3, this.GetVersionHeight(relativeDirectory)); }
public void GetVersionHeight_IncludeRootExcludeSome() { string relativeDirectory = "some-sub-dir"; var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { new FilterPath(":/", relativeDirectory), new FilterPath(":^/excluded-dir", relativeDirectory), }; this.WriteVersionFile(versionData, relativeDirectory); Assert.Equal(1, this.Repo.GetVersionHeight(relativeDirectory)); // Expect commit in an excluded directory to not affect version height var ignoredFilePath = Path.Combine(this.RepoPath, "excluded-dir", "my-file.txt"); Directory.CreateDirectory(Path.GetDirectoryName(ignoredFilePath)); File.WriteAllText(ignoredFilePath, "hello"); Commands.Stage(this.Repo, ignoredFilePath); this.Repo.Commit("Add other file to excluded directory", this.Signer, this.Signer); Assert.Equal(1, this.Repo.GetVersionHeight(relativeDirectory)); // Expect commit within another directory to affect version height var otherFilePath = Path.Combine(this.RepoPath, "another-dir", "another-file.txt"); Directory.CreateDirectory(Path.GetDirectoryName(otherFilePath)); File.WriteAllText(otherFilePath, "hello"); Commands.Stage(this.Repo, otherFilePath); this.Repo.Commit("Add file within project root", this.Signer, this.Signer); Assert.Equal(2, this.Repo.GetVersionHeight(relativeDirectory)); }
public void GetIdAsVersion_Roundtrip_WithSubdirectoryVersionFiles() { var rootVersionExpected = VersionOptions.FromVersion(new Version(1, 0)); VersionFile.SetVersion(this.RepoPath, rootVersionExpected); var subPathVersionExpected = VersionOptions.FromVersion(new Version(1, 1)); const string subPathRelative = "a"; string subPath = Path.Combine(this.RepoPath, subPathRelative); Directory.CreateDirectory(subPath); VersionFile.SetVersion(subPath, subPathVersionExpected); this.InitializeSourceControl(); Commit head = this.Repo.Head.Commits.First(); Version rootVersionActual = head.GetIdAsVersion(); Version subPathVersionActual = head.GetIdAsVersion(subPathRelative); // Verify that the versions calculated took the path into account. Assert.Equal(rootVersionExpected.Version.Version.Minor, rootVersionActual?.Minor); Assert.Equal(subPathVersionExpected.Version.Version.Minor, subPathVersionActual?.Minor); // Verify that we can find the commit given the version and path. Assert.Equal(head, this.Repo.GetCommitFromVersion(rootVersionActual)); Assert.Equal(head, this.Repo.GetCommitFromVersion(subPathVersionActual, subPathRelative)); // Verify that mismatching path and version results in a null value. Assert.Null(this.Repo.GetCommitFromVersion(rootVersionActual, subPathRelative)); Assert.Null(this.Repo.GetCommitFromVersion(subPathVersionActual)); }
public void GetCommitsFromVersion_WithPathFilters() { string relativeDirectory = "some-sub-dir"; var commitsAt121 = new List <Commit>(); var commitsAt122 = new List <Commit>(); var commitsAt123 = new List <Commit>(); var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { new FilterPath("./", relativeDirectory), new FilterPath(":^/some-sub-dir/ignore.txt", relativeDirectory), new FilterPath(":^excluded-dir", relativeDirectory) }; commitsAt121.Add(this.WriteVersionFile(versionData, relativeDirectory)); // Commit touching excluded path does not affect version height var ignoredFilePath = Path.Combine(this.RepoPath, relativeDirectory, "ignore.txt"); File.WriteAllText(ignoredFilePath, "hello"); Commands.Stage(this.LibGit2Repository, ignoredFilePath); commitsAt121.Add(this.LibGit2Repository.Commit("Add excluded file", this.Signer, this.Signer)); // Commit touching both excluded and included path does affect height var includedFilePath = Path.Combine(this.RepoPath, relativeDirectory, "another-file.txt"); File.WriteAllText(includedFilePath, "hello"); File.WriteAllText(ignoredFilePath, "changed"); Commands.Stage(this.LibGit2Repository, includedFilePath); Commands.Stage(this.LibGit2Repository, ignoredFilePath); commitsAt122.Add(this.LibGit2Repository.Commit("Change both excluded and included file", this.Signer, this.Signer)); // Commit touching excluded directory does not affect version height var fileInExcludedDirPath = Path.Combine(this.RepoPath, relativeDirectory, "excluded-dir", "ignore.txt"); Directory.CreateDirectory(Path.GetDirectoryName(fileInExcludedDirPath)); File.WriteAllText(fileInExcludedDirPath, "hello"); Commands.Stage(this.LibGit2Repository, fileInExcludedDirPath); commitsAt122.Add(this.LibGit2Repository.Commit("Add file to excluded dir", this.Signer, this.Signer)); // Commit touching project directory affects version height File.WriteAllText(includedFilePath, "more changes"); Commands.Stage(this.LibGit2Repository, includedFilePath); commitsAt123.Add(this.LibGit2Repository.Commit("Changed included file", this.Signer, this.Signer)); this.Context.RepoRelativeProjectDirectory = relativeDirectory; Assert.Equal( commitsAt121.OrderBy(c => c.Sha), LibGit2GitExtensions.GetCommitsFromVersion(this.Context, new Version(1, 2, 1)).OrderBy(c => c.Sha)); Assert.Equal( commitsAt122.OrderBy(c => c.Sha), LibGit2GitExtensions.GetCommitsFromVersion(this.Context, new Version(1, 2, 2)).OrderBy(c => c.Sha)); Assert.Equal( commitsAt123.OrderBy(c => c.Sha), LibGit2GitExtensions.GetCommitsFromVersion(this.Context, new Version(1, 2, 3)).OrderBy(c => c.Sha)); }
public void FromVersion() { var vo = VersionOptions.FromVersion(new Version(1, 2), "-pre"); Assert.Equal(new Version(1, 2), vo.Version.Version); Assert.Equal("-pre", vo.Version.Prerelease); Assert.Null(vo.AssemblyVersion); Assert.Equal(0, vo.BuildNumberOffsetOrDefault); }
public void GetVersionHeight_IntroducingFiltersIncrementsHeight() { this.WriteVersionFile(relativeDirectory: "some-sub-dir"); Assert.Equal(1, this.Repo.GetVersionHeight("some-sub-dir")); var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { "./" }; this.WriteVersionFile(versionData, "some-sub-dir"); Assert.Equal(2, this.Repo.GetVersionHeight("some-sub-dir")); }
public async Task GetBuildVersion_UnstablePreRelease() { const string majorMinorVersion = "5.8"; const string prerelease = "-beta"; this.WriteVersionFile(majorMinorVersion, prerelease); this.InitializeSourceControl(); this.AddCommits(this.random.Next(15)); var buildResult = await this.BuildAsync(); this.AssertStandardProperties(VersionOptions.FromVersion(new Version(majorMinorVersion), prerelease), buildResult); }
public void GetVersionHeight_ProjectDirectoryIsMoved() { this.InitializeSourceControl(); string relativeDirectory = "some-sub-dir"; var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { new FilterPath("./", relativeDirectory), new FilterPath(":^/some-sub-dir/ignore.txt", relativeDirectory), new FilterPath(":^excluded-dir", relativeDirectory), }; this.WriteVersionFile(versionData, relativeDirectory); Assert.Equal(1, this.GetVersionHeight(relativeDirectory)); // Commit touching excluded path does not affect version height var ignoredFilePath = Path.Combine(this.RepoPath, relativeDirectory, "ignore.txt"); File.WriteAllText(ignoredFilePath, "hello"); Commands.Stage(this.Repo, ignoredFilePath); this.Repo.Commit("Add excluded file", this.Signer, this.Signer); Assert.Equal(1, this.GetVersionHeight(relativeDirectory)); // Commit touching both excluded and included path does affect height var includedFilePath = Path.Combine(this.RepoPath, relativeDirectory, "another-file.txt"); File.WriteAllText(includedFilePath, "hello"); File.WriteAllText(ignoredFilePath, "changed"); Commands.Stage(this.Repo, includedFilePath); Commands.Stage(this.Repo, ignoredFilePath); this.Repo.Commit("Change both excluded and included file", this.Signer, this.Signer); Assert.Equal(2, this.GetVersionHeight(relativeDirectory)); // Commit touching excluded directory does not affect version height var fileInExcludedDirPath = Path.Combine(this.RepoPath, relativeDirectory, "excluded-dir", "ignore.txt"); Directory.CreateDirectory(Path.GetDirectoryName(fileInExcludedDirPath)); File.WriteAllText(fileInExcludedDirPath, "hello"); Commands.Stage(this.Repo, fileInExcludedDirPath); this.Repo.Commit("Add file to excluded dir", this.Signer, this.Signer); Assert.Equal(2, this.GetVersionHeight(relativeDirectory)); // Rename the project directory Directory.Move(Path.Combine(this.RepoPath, relativeDirectory), Path.Combine(this.RepoPath, "new-project-dir")); Commands.Stage(this.Repo, relativeDirectory); Commands.Stage(this.Repo, "new-project-dir"); this.Repo.Commit("Move project directory", this.Signer, this.Signer); // Version is reset as project directory cannot be find in the ancestor commit Assert.Equal(1, this.GetVersionHeight("new-project-dir")); }
public void GetIdAsVersion_VersionFileNeverCheckedIn_2Ints() { this.AddCommits(); var expectedVersion = new Version(1, 1); var unstagedVersionData = VersionOptions.FromVersion(expectedVersion); string versionFilePath = VersionFile.SetVersion(this.RepoPath, unstagedVersionData); Version actualVersion = this.Repo.GetIdAsVersion(); Assert.Equal(expectedVersion.Major, actualVersion.Major); Assert.Equal(expectedVersion.Minor, actualVersion.Minor); Assert.Equal(0, actualVersion.Build); // height is 0 since the change hasn't been committed. Assert.Equal(this.Repo.Head.Commits.First().GetTruncatedCommitIdAsUInt16(), actualVersion.Revision); }
public async Task GetBuildVersion_In_Git_With_Version_File_In_Subdirectory_Works() { const string majorMinorVersion = "5.8"; const string prerelease = ""; const string subdirectory = "projdir"; this.WriteVersionFile(majorMinorVersion, prerelease, subdirectory); this.InitializeSourceControl(); this.AddCommits(this.random.Next(15)); var buildResult = await this.BuildAsync(); this.AssertStandardProperties(VersionOptions.FromVersion(new Version(majorMinorVersion)), buildResult, subdirectory); }
public async Task GetBuildVersion_In_Git_But_WorkingCopy_Has_Changes() { const string majorMinorVersion = "5.8"; const string prerelease = ""; this.WriteVersionFile(majorMinorVersion, prerelease); this.InitializeSourceControl(); var workingCopyVersion = VersionOptions.FromVersion(new Version("6.0")); VersionFile.SetVersion(this.RepoPath, workingCopyVersion); var buildResult = await this.BuildAsync(); this.AssertStandardProperties(workingCopyVersion, buildResult); }
public void GetVersionHeight_IntroducingFiltersIncrementsHeight() { this.InitializeSourceControl(); string relativeDirectory = "some-sub-dir"; this.WriteVersionFile(relativeDirectory: relativeDirectory); Assert.Equal(1, this.GetVersionHeight(relativeDirectory)); var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { new FilterPath("./", relativeDirectory) }; this.WriteVersionFile(versionData, relativeDirectory); Assert.Equal(2, this.GetVersionHeight(relativeDirectory)); }
public void GetIdAsVersion_VersionFileNeverCheckedIn_3Ints() { this.AddCommits(); var expectedVersion = new Version(1, 1, 0); var unstagedVersionData = VersionOptions.FromVersion(expectedVersion); string versionFilePath = VersionFile.SetVersion(this.RepoPath, unstagedVersionData); Version actualVersion = this.Repo.GetIdAsVersion(); Assert.Equal(expectedVersion.Major, actualVersion.Major); Assert.Equal(expectedVersion.Minor, actualVersion.Minor); Assert.Equal(expectedVersion.Build, actualVersion.Build); // Height is expressed in the 4th integer since 3 were specified in version.json. // height is 0 since the change hasn't been committed. Assert.Equal(0, actualVersion.Revision); }
public async Task GetBuildVersion_StableRelease() { const string majorMinorVersion = "5.8"; const string prerelease = ""; this.WriteVersionFile(majorMinorVersion, prerelease); this.InitializeSourceControl(); this.AddCommits(this.random.Next(15)); this.globalProperties["PublicRelease"] = "true"; var buildResult = await this.BuildAsync(); this.AssertStandardProperties(VersionOptions.FromVersion(new Version(majorMinorVersion)), buildResult); Version version = this.Repo.Head.Commits.First().GetIdAsVersion(); Assert.Equal($"{version.Major}.{version.Minor}.{buildResult.GitVersionHeight}", buildResult.NuGetPackageVersion); }
public void GetVersionHeight_IncludeExcludeFilter() { this.InitializeSourceControl(); string relativeDirectory = "some-sub-dir"; var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { new FilterPath("./", relativeDirectory), new FilterPath(":^/some-sub-dir/ignore.txt", relativeDirectory), new FilterPath(":^excluded-dir", relativeDirectory) }; this.WriteVersionFile(versionData, relativeDirectory); Assert.Equal(1, this.GetVersionHeight(relativeDirectory)); // Commit touching excluded path does not affect version height var ignoredFilePath = Path.Combine(this.RepoPath, relativeDirectory, "ignore.txt"); File.WriteAllText(ignoredFilePath, "hello"); Commands.Stage(this.LibGit2Repository, ignoredFilePath); this.LibGit2Repository.Commit("Add excluded file", this.Signer, this.Signer); Assert.Equal(1, this.GetVersionHeight(relativeDirectory)); // Commit touching both excluded and included path does affect height var includedFilePath = Path.Combine(this.RepoPath, relativeDirectory, "another-file.txt"); File.WriteAllText(includedFilePath, "hello"); File.WriteAllText(ignoredFilePath, "changed"); Commands.Stage(this.LibGit2Repository, includedFilePath); Commands.Stage(this.LibGit2Repository, ignoredFilePath); this.LibGit2Repository.Commit("Change both excluded and included file", this.Signer, this.Signer); Assert.Equal(2, this.GetVersionHeight(relativeDirectory)); // Commit touching excluded directory does not affect version height var fileInExcludedDirPath = Path.Combine(this.RepoPath, relativeDirectory, "excluded-dir", "ignore.txt"); Directory.CreateDirectory(Path.GetDirectoryName(fileInExcludedDirPath)); File.WriteAllText(fileInExcludedDirPath, "hello"); Commands.Stage(this.LibGit2Repository, fileInExcludedDirPath); this.LibGit2Repository.Commit("Add file to excluded dir", this.Signer, this.Signer); Assert.Equal(2, this.GetVersionHeight(relativeDirectory)); }
public void GetVersionHeight_ProjectDirectoryDifferentToVersionJsonDirectory() { string relativeDirectory = "some-sub-dir"; var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { new FilterPath(".", "") }; this.WriteVersionFile(versionData, ""); Assert.Equal(1, this.Repo.GetVersionHeight(relativeDirectory)); // Expect commit in an excluded directory to not affect version height var ignoredFilePath = Path.Combine(this.RepoPath, "other-dir", "my-file.txt"); Directory.CreateDirectory(Path.GetDirectoryName(ignoredFilePath)); File.WriteAllText(ignoredFilePath, "hello"); Commands.Stage(this.Repo, ignoredFilePath); this.Repo.Commit("Add file to other directory", this.Signer, this.Signer); Assert.Equal(2, this.Repo.GetVersionHeight(relativeDirectory)); }
public async Task GetBuildVersion_OutsideGit_PointingToGit() { // Write a version file to the 'virtualized' repo. string version = "3.4"; this.WriteVersionFile(version); // Update the repo path so we create the 'normal' one elsewhere this.RepoPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); this.InitializeSourceControl(); // Write the same version file to the 'real' repo this.WriteVersionFile(version); // Point the project to the 'real' repo this.testProject.AddProperty("GitRepoRoot", this.RepoPath); var buildResult = await this.BuildAsync(); var workingCopyVersion = VersionOptions.FromVersion(new Version(version)); this.AssertStandardProperties(workingCopyVersion, buildResult); }
public void GetVersionHeight_IncludeRoot() { var versionData = VersionOptions.FromVersion(new Version("1.2")); versionData.PathFilters = new[] { ":/" }; this.WriteVersionFile(versionData, "some-sub-dir"); Assert.Equal(1, this.Repo.GetVersionHeight("some-sub-dir")); // Expect commit outside of project tree to affect version height var otherFilePath = Path.Combine(this.RepoPath, "my-file.txt"); File.WriteAllText(otherFilePath, "hello"); Commands.Stage(this.Repo, otherFilePath); this.Repo.Commit("Add other file outside of project root", this.Signer, this.Signer); Assert.Equal(2, this.Repo.GetVersionHeight("some-sub-dir")); // Expect commit inside project tree to affect version height var containedFilePath = Path.Combine(this.RepoPath, "some-sub-dir", "another-file.txt"); File.WriteAllText(containedFilePath, "hello"); Commands.Stage(this.Repo, containedFilePath); this.Repo.Commit("Add file within project root", this.Signer, this.Signer); Assert.Equal(3, this.Repo.GetVersionHeight("some-sub-dir")); }
protected Commit WriteVersionFile(string version = "1.2", string prerelease = "", string relativeDirectory = null) { var versionData = VersionOptions.FromVersion(new System.Version(version), prerelease); return(this.WriteVersionFile(versionData, relativeDirectory)); }