private int RunGitVersionTool(GitVersionOptions gitVersionOptions) { try { var variables = gitVersionCalculateTool.CalculateVersionVariables(); var configuration = configProvider.Provide(overrideConfig: gitVersionOptions.ConfigInfo.OverrideConfig); gitVersionOutputTool.OutputVariables(variables, configuration.UpdateBuildNumber ?? true); gitVersionOutputTool.UpdateAssemblyInfo(variables); gitVersionOutputTool.UpdateWixVersionFile(variables); } catch (WarningException exception) { var error = $"An error occurred:{System.Environment.NewLine}{exception.Message}"; log.Warning(error); return(1); } catch (Exception exception) { var error = $"An unexpected error occurred:{System.Environment.NewLine}{exception}"; log.Error(error); if (gitVersionOptions == null) { return(1); } log.Info("Attempting to show the current git graph (please include in issue): "); log.Info("Showing max of 100 commits"); try { GitExtensions.DumpGraph(gitVersionOptions.WorkingDirectory, mess => log.Info(mess), 100); } catch (Exception dumpGraphException) { log.Error("Couldn't dump the git graph due to the following error: " + dumpGraphException); } return(1); } return(0); }
private static bool RunExecCommandIfNeeded(GitVersionOptions args, string workingDirectory, VersionVariables variables, ILog log) { #pragma warning disable CS0612 // Type or member is obsolete if (string.IsNullOrEmpty(args.Exec)) { return(false); } log.Info($"Launching {args.Exec} {args.ExecArgs}"); var results = ProcessHelper.Run( m => log.Info(m), m => log.Error(m), null, args.Exec, args.ExecArgs, workingDirectory, GetEnvironmentalVariables(variables)); if (results != 0) { throw new WarningException($"Execution of {args.Exec} failed, non-zero return code"); } #pragma warning restore CS0612 // Type or member is obsolete return(true); }
private bool HandleNonMainCommand(GitVersionOptions gitVersionOptions, out int exitCode) { if (gitVersionOptions == null) { helpWriter.Write(); exitCode = 1; return(true); } if (gitVersionOptions.IsVersion) { var assembly = Assembly.GetExecutingAssembly(); versionWriter.Write(assembly); exitCode = 0; return(true); } if (gitVersionOptions.IsHelp) { helpWriter.Write(); exitCode = 0; return(true); } if (gitVersionOptions.Diag) { gitVersionOptions.Settings.NoCache = true; gitVersionOptions.Output.Add(OutputType.BuildServer); } ConfigureLogging(gitVersionOptions, log); var workingDirectory = gitVersionOptions.WorkingDirectory; if (gitVersionOptions.Diag) { log.Info("Dumping commit graph: "); GitExtensions.DumpGraph(workingDirectory, mess => log.Info(mess), 100); } if (!Directory.Exists(workingDirectory)) { log.Warning($"The working directory '{workingDirectory}' does not exist."); } else { log.Info("Working directory: " + workingDirectory); } configFileLocator.Verify(gitVersionOptions, repositoryInfo); if (gitVersionOptions.Init) { configProvider.Init(workingDirectory); exitCode = 0; return(true); } if (gitVersionOptions.ConfigInfo.ShowConfig) { var config = configProvider.Provide(workingDirectory); console.WriteLine(config.ToString()); exitCode = 0; return(true); } exitCode = 0; return(false); }
public GitVersionContext Create(GitVersionOptions gitVersionOptions) { var targetBranch = repositoryMetadataProvider.GetTargetBranch(gitVersionOptions.RepositoryInfo.TargetBranch); return(Init(targetBranch, gitVersionOptions.RepositoryInfo.CommitId, gitVersionOptions.Settings.OnlyTrackedBranches)); }