public void VersionCli_throws_when_repo_is_not_clean_and_doVcs_is_true() { A.CallTo(() => _vcsTool.IsVcsToolPresent()).Returns(true); A.CallTo(() => _vcsTool.IsRepositoryClean()).Returns(false); var ex = Assert.Throws <OperationCanceledException>(() => _cli.Execute(new VersionCliArgs { VersionBump = VersionBump.Major, DoVcs = true })); Assert.Equal("You currently have uncomitted changes in your repository, please commit these and try again", ex.Message); }
public VersionInfo Execute(VersionCliArgs args) { if (!args.DryRun && args.DoVcs && !_vcsTool.IsVcsToolPresent()) { throw new OperationCanceledException( $"Unable to find the vcs tool {_vcsTool.ToolName()} in your path"); } if (!args.DryRun && args.DoVcs && !_vcsTool.IsRepositoryClean()) { throw new OperationCanceledException( "You currently have uncomitted changes in your repository, please commit these and try again"); } var csProjXml = _fileDetector.FindAndLoadCsProj(args.CsProjFilePath); _fileParser.Load(csProjXml); var semVer = SemVer.FromString(_fileParser.Version); semVer.Bump(args.VersionBump, args.SpecificVersionToApply); var newVersion = semVer.ToVersionString(); if (!args.DryRun) // if we are not in dry run mode, then we should go ahead { var patchedCsProjXml = _fileVersionPatcher.Patch( csProjXml, _fileParser.Version, newVersion ); _fileVersionPatcher.Flush( patchedCsProjXml, _fileDetector.ResolvedCsProjFile ); if (args.DoVcs) { // Run git commands _vcsTool.Commit(_fileDetector.ResolvedCsProjFile, $"v{newVersion}"); _vcsTool.Tag($"v{newVersion}"); } } var theOutput = new VersionInfo { Product = new ProductOutputInfo { Name = ProductInfo.Name, Version = ProductInfo.Version }, OldVersion = _fileParser.Version, NewVersion = newVersion, ProjectFile = _fileDetector.ResolvedCsProjFile, VersionStrategy = args.VersionBump.ToString().ToLowerInvariant() }; if (args.OutputFormat == OutputFormat.Json) { WriteJsonToStdout(theOutput); } else { Console.WriteLine($"Bumped {_fileDetector.ResolvedCsProjFile} to version {newVersion}"); } return(theOutput); }