public static void Run(Arguments arguments, IFileSystem fileSystem) { Logger.WriteInfo(string.Format("Running on {0}.", runningOnMono ? "Mono" : "Windows")); var noFetch = arguments.NoFetch; var authentication = arguments.Authentication; var targetPath = arguments.TargetPath; var targetUrl = arguments.TargetUrl; var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation; var targetBranch = arguments.TargetBranch; var commitId = arguments.CommitId; var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null; var executeCore = new ExecuteCore(fileSystem); var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig); if (arguments.Output == OutputType.BuildServer) { foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) { buildServer.WriteIntegration(Console.WriteLine, variables); } } if (arguments.Output == OutputType.Json) { switch (arguments.ShowVariable) { case null: Console.WriteLine(JsonOutputFormatter.ToJson(variables)); break; default: string part; if (!variables.TryGetValue(arguments.ShowVariable, out part)) { throw new WarningException(string.Format("'{0}' variable does not exist", arguments.ShowVariable)); } Console.WriteLine(part); break; } } using (var assemblyInfoUpdate = new AssemblyInfoFileUpdate(arguments, targetPath, variables, fileSystem)) { var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables); var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables); if (!execRun && !msbuildRun) { assemblyInfoUpdate.DoNotRestoreAssemblyInfo(); //TODO Put warning back //if (!context.CurrentBuildServer.IsRunningInBuildAgent()) //{ // Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed"); // Console.WriteLine(); // Console.WriteLine("Run GitVersion.exe /? for help"); //} } } }
string RepositoryScope(ExecuteCore executeCore = null, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null) { // Make sure GitVersion doesn't trigger build server mode when we are running the tests Environment.SetEnvironmentVariable("APPVEYOR", null); var infoBuilder = new StringBuilder(); Action<string> infoLogger = s => { infoBuilder.AppendLine(s); }; executeCore = executeCore ?? new ExecuteCore(fileSystem); Logger.SetLoggers(infoLogger, s => { }, s => { }); using (var fixture = new EmptyRepositoryFixture(new Config())) { fixture.Repository.MakeACommit(); var vv = executeCore.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); vv.AssemblySemVer.ShouldBe("0.1.0.0"); vv.FileName.ShouldNotBeNullOrEmpty(); if (fixtureAction != null) { fixtureAction(fixture, vv); } } return infoBuilder.ToString(); }
public static void Run(Arguments arguments, IFileSystem fileSystem) { Logger.WriteInfo(string.Format("Running on {0}.", runningOnMono ? "Mono" : "Windows")); var noFetch = arguments.NoFetch; var authentication = arguments.Authentication; var targetPath = arguments.TargetPath; var targetUrl = arguments.TargetUrl; var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation; var targetBranch = arguments.TargetBranch; var commitId = arguments.CommitId; var overrideConfig = arguments.OverrideConfig; var executeCore = new ExecuteCore(fileSystem); var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig: overrideConfig); if (arguments.Output == OutputType.BuildServer) { foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) { buildServer.WriteIntegration(Console.WriteLine, variables); } } if (arguments.Output == OutputType.Json) { switch (arguments.ShowVariable) { case null: Console.WriteLine(JsonOutputFormatter.ToJson(variables)); break; default: string part; if (!variables.TryGetValue(arguments.ShowVariable, out part)) { throw new WarningException(string.Format("'{0}' variable does not exist", arguments.ShowVariable)); } Console.WriteLine(part); break; } } using (var assemblyInfoUpdate = new AssemblyInfoFileUpdate(arguments, targetPath, variables, fileSystem)) { var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables); var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables); if (!execRun && !msbuildRun) { assemblyInfoUpdate.DoNotRestoreAssemblyInfo(); //TODO Put warning back //if (!context.CurrentBuildServer.IsRunningInBuildAgent()) //{ // Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed"); // Console.WriteLine(); // Console.WriteLine("Run GitVersion.exe /? for help"); //} } } }
public static int Main(string[] args) { Logger.SetLoggers( Console.WriteLine, Console.WriteLine, Console.WriteLine); var options = Options.Parse(args); if (options.Help) { Console.WriteLine(Options.GetHelpMessage()); return(0); } if (options.NoFilesSpecified && !TryFindNetCoreProject(out options)) { Console.Error.WriteLine($"Could not locate {ProjectJsonFile} or {CsprojFile} in current directory and no command line arguments were specified."); Console.WriteLine(Options.GetHelpMessage()); return(-1); } var fs = new FileSystem(); var gv = new GitVersion.ExecuteCore(fs); var auth = new GitVersion.Authentication(); var version = gv.ExecuteGitVersion(null, null, auth, null, false, ".", null); Console.WriteLine($"Setting version: {version.LegacySemVerPadded}"); if (!string.IsNullOrEmpty(options.ProjectJson)) { UpdateProjectJson(options.ProjectJson, version.LegacySemVerPadded); } if (!string.IsNullOrEmpty(options.CsProj)) { UpdateCsproj(options.CsProj, version.LegacySemVerPadded); } return(0); }
public void CacheFileExistsOnDisk() { const string versionCacheFileContent = @" Major: 4 Minor: 10 Patch: 3 PreReleaseTag: test.19 PreReleaseTagWithDash: -test.19 PreReleaseLabel: test PreReleaseNumber: 19 BuildMetaData: BuildMetaDataPadded: FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f MajorMinorPatch: 4.10.3 SemVer: 4.10.3-test.19 LegacySemVer: 4.10.3-test19 LegacySemVerPadded: 4.10.3-test0019 AssemblySemVer: 4.10.3.0 FullSemVer: 4.10.3-test.19 InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f BranchName: feature/test Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f NuGetVersionV2: 4.10.3-test0019 NuGetVersion: 4.10.3-test0019 NuGetPreReleaseTagV2: test0019 NuGetPreReleaseTag: test0019 CommitsSinceVersionSource: 19 CommitsSinceVersionSourcePadded: 0019 CommitDate: 2015-11-10 "; var versionAndBranchFinder = new ExecuteCore(fileSystem); var info = RepositoryScope(versionAndBranchFinder, (fixture, vv) => { fileSystem.WriteAllText(vv.FileName, versionCacheFileContent); vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); vv.AssemblySemVer.ShouldBe("4.10.3.0"); }); info.ShouldContain("Deserializing version variables from cache file", () => info); }
public static void Run(Arguments arguments, IFileSystem fileSystem) { Logger.WriteInfo($"Running on {(runningOnUnix ? "Unix" : "Windows")}."); var noFetch = arguments.NoFetch; var authentication = arguments.Authentication; var targetPath = arguments.TargetPath; var targetUrl = arguments.TargetUrl; var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation; var targetBranch = arguments.TargetBranch; var commitId = arguments.CommitId; var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null; var noCache = arguments.NoCache; var executeCore = new ExecuteCore(fileSystem, arguments.ConfigFileLocator); var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache); if (arguments.Output == OutputType.BuildServer) { foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) { buildServer.WriteIntegration(Console.WriteLine, variables); } } if (arguments.Output == OutputType.Json) { switch (arguments.ShowVariable) { case null: Console.WriteLine(JsonOutputFormatter.ToJson(variables)); break; default: if (!variables.TryGetValue(arguments.ShowVariable, out var part)) { throw new WarningException($"'{arguments.ShowVariable}' variable does not exist"); } Console.WriteLine(part); break; } } if (arguments.UpdateWixVersionFile) { using (var wixVersionFileUpdater = new WixVersionFileUpdater(targetPath, variables, fileSystem)) { wixVersionFileUpdater.Update(); } } using (var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, targetPath, variables, fileSystem, arguments.EnsureAssemblyInfo)) { if (arguments.UpdateAssemblyInfo) { assemblyInfoUpdater.Update(); } var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables); var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables); if (!execRun && !msbuildRun) { assemblyInfoUpdater.CommitChanges(); //TODO Put warning back //if (!context.CurrentBuildServer.IsRunningInBuildAgent()) //{ // Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed"); // Console.WriteLine(); // Console.WriteLine("Run GitVersion.exe /? for help"); //} } } }
public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDynamicallyCalculatedWithoutSavingInCache() { const string versionCacheFileContent = @" Major: 4 Minor: 10 Patch: 3 PreReleaseTag: test.19 PreReleaseTagWithDash: -test.19 PreReleaseLabel: test PreReleaseNumber: 19 BuildMetaData: BuildMetaDataPadded: FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f MajorMinorPatch: 4.10.3 SemVer: 4.10.3-test.19 LegacySemVer: 4.10.3-test19 LegacySemVerPadded: 4.10.3-test0019 AssemblySemVer: 4.10.3.0 FullSemVer: 4.10.3-test.19 InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f BranchName: feature/test Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f NuGetVersionV2: 4.10.3-test0019 NuGetVersion: 4.10.3-test0019 NuGetPreReleaseTagV2: test0019 NuGetPreReleaseTag: test0019 CommitsSinceVersionSource: 19 CommitsSinceVersionSourcePadded: 0019 CommitDate: 2015-11-10 "; var versionAndBranchFinder = new ExecuteCore(fileSystem); RepositoryScope(versionAndBranchFinder, (fixture, vv) => { fileSystem.WriteAllText(vv.FileName, versionCacheFileContent); var gitPreparer = new GitPreparer(null, null, null, false, fixture.RepositoryPath); var cacheDirectory = GitVersionCache.GetCacheDirectory(gitPreparer); var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory); vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null, new Config() { TagPrefix = "prefix" }); vv.AssemblySemVer.ShouldBe("0.1.0.0"); var cachedDirectoryTimestampAfter = fileSystem.GetLastDirectoryWrite(cacheDirectory); cachedDirectoryTimestampAfter.ShouldBe(cacheDirectoryTimestamp, () => "Cache was updated when override config was set"); }); // TODO info.ShouldContain("Override config from command line", () => info); }
public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory() { var versionAndBranchFinder = new ExecuteCore(fileSystem); RepositoryScope(versionAndBranchFinder, (fixture, vv) => { versionAndBranchFinder.ExecuteGitVersion("https://github.com/GitTools/GitVersion.git", null, new Authentication(), "refs/head/master", false, fixture.RepositoryPath, null); }); }
public void WorkingDirectoryWithoutGit() { var versionAndBranchFinder = new ExecuteCore(fileSystem); RepositoryScope(versionAndBranchFinder, (fixture, vv) => { var exception = Assert.Throws<DirectoryNotFoundException>(() => versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, Environment.SystemDirectory, null)); exception.Message.ShouldContain("Can't find the .git directory in"); }); }
public void ConfigChangeInvalidatesCache() { const string versionCacheFileContent = @" Major: 4 Minor: 10 Patch: 3 PreReleaseTag: test.19 PreReleaseTagWithDash: -test.19 PreReleaseLabel: test PreReleaseNumber: 19 BuildMetaData: BuildMetaDataPadded: FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f MajorMinorPatch: 4.10.3 SemVer: 4.10.3-test.19 LegacySemVer: 4.10.3-test19 LegacySemVerPadded: 4.10.3-test0019 AssemblySemVer: 4.10.3.0 FullSemVer: 4.10.3-test.19 InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f BranchName: feature/test Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f NuGetVersionV2: 4.10.3-test0019 NuGetVersion: 4.10.3-test0019 NuGetPreReleaseTagV2: test0019 NuGetPreReleaseTag: test0019 CommitsSinceVersionSource: 19 CommitsSinceVersionSourcePadded: 0019 CommitDate: 2015-11-10 "; var versionAndBranchFinder = new ExecuteCore(fileSystem); RepositoryScope(versionAndBranchFinder, (fixture, vv) => { fileSystem.WriteAllText(vv.FileName, versionCacheFileContent); vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); vv.AssemblySemVer.ShouldBe("4.10.3.0"); var configPath = Path.Combine(fixture.RepositoryPath, "GitVersionConfig.yaml"); fileSystem.WriteAllText(configPath, "next-version: 5.0"); vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); vv.AssemblySemVer.ShouldBe("5.0.0.0"); }); }
LogMessages RepositoryScope(ExecuteCore executeCore = null, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null) { // Make sure GitVersion doesn't trigger build server mode when we are running the tests Environment.SetEnvironmentVariable(AppVeyor.EnvironmentVariableName, null); Environment.SetEnvironmentVariable(TravisCI.EnvironmentVariableName, null); var debugBuilder = new StringBuilder(); Action<string> debugLogger = s => { debugBuilder.AppendLine(s); }; var infoBuilder = new StringBuilder(); Action<string> infoLogger = s => { infoBuilder.AppendLine(s); }; var warnBuilder = new StringBuilder(); Action<string> warnLogger = s => { warnBuilder.AppendLine(s); }; var errorBuilder = new StringBuilder(); Action<string> errorLogger = s => { errorBuilder.AppendLine(s); }; executeCore = executeCore ?? new ExecuteCore(fileSystem); using (Logger.AddLoggersTemporarily(debugLogger, infoLogger, warnLogger, errorLogger)) using (var fixture = new EmptyRepositoryFixture()) { fixture.Repository.MakeACommit(); var vv = executeCore.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); vv.AssemblySemVer.ShouldBe("0.1.0.0"); vv.FileName.ShouldNotBeNullOrEmpty(); if (fixtureAction != null) { fixtureAction(fixture, vv); } } return new LogMessages { Debug = debugBuilder.ToString(), Info = infoBuilder.ToString(), Warn = warnBuilder.ToString(), Error = errorBuilder.ToString() }; }