Esempio n. 1
0
            public void DoNotThrowWhenWorkingAndRepoPathsAreSame()
            {
                workingPath = DefaultRepoPath;

                var sp = GetServiceProvider(gitVersionOptions);

                configFileLocator = sp.GetService <IConfigFileLocator>();
                fileSystem        = sp.GetService <IFileSystem>();

                SetupConfigFileContent(string.Empty, path: workingPath);

                Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); });
            }
        public void DoNotThrowWhenWorkingAndRepoPathsAreSame_WithDifferentCasing()
        {
            workingPath = DefaultRepoPath.ToLower();

            var sp = GetServiceProvider(arguments);

            configFileLocator = sp.GetService <IConfigFileLocator>();
            fileSystem        = sp.GetService <IFileSystem>();

            SetupConfigFileContent(string.Empty, path: workingPath);

            Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); });
        }
        public void ThrowsExceptionOnCustomYmlFileDoesNotExist()
        {
            var sp = GetServiceProvider(arguments);

            configFileLocator = sp.GetService <IConfigFileLocator>();

            var exception = Should.Throw <WarningException>(() => { configFileLocator.Verify(workingPath, repoPath); });

            var workingPathFileConfig = Path.Combine(workingPath, arguments.ConfigFile);
            var repoPathFileConfig    = Path.Combine(repoPath, arguments.ConfigFile);
            var expectedMessage       = $"The configuration file was not found at '{workingPathFileConfig}' or '{repoPathFileConfig}'";

            exception.Message.ShouldBe(expectedMessage);
        }
Esempio n. 4
0
            public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile)
            {
                var repositoryConfigFilePath       = SetupConfigFileContent(string.Empty, repoConfigFile, repoPath);
                var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, workingConfigFile, workingPath);

                var exception = Should.Throw <WarningException>(() =>
                {
                    configFileLocator.Verify(workingPath, repoPath);
                });

                var expecedMessage = $"Ambiguous config file selection from '{workingDirectoryConfigFilePath}' and '{repositoryConfigFilePath}'";

                exception.Message.ShouldBe(expecedMessage);
            }
        public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath()
        {
            workingPath = DefaultRepoPath;

            arguments = new Arguments {
                ConfigFile = "./src/my-config.yaml"
            };
            var sp = GetServiceProvider(arguments);

            configFileLocator = sp.GetService <IConfigFileLocator>();
            fileSystem        = sp.GetService <IFileSystem>();

            SetupConfigFileContent(string.Empty, path: workingPath);

            Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); });
        }
        public void ThrowsExceptionOnAmbiguousConfigFileLocation()
        {
            var sp = GetServiceProvider(arguments);

            configFileLocator = sp.GetService <IConfigFileLocator>();
            fileSystem        = sp.GetService <IFileSystem>();

            var repositoryConfigFilePath       = SetupConfigFileContent(string.Empty, path: repoPath);
            var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, path: workingPath);

            var exception = Should.Throw <WarningException>(() => { configFileLocator.Verify(workingPath, repoPath); });

            var expectedMessage = $"Ambiguous config file selection from '{workingDirectoryConfigFilePath}' and '{repositoryConfigFilePath}'";

            exception.Message.ShouldBe(expectedMessage);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 private void VerifyConfiguration()
 {
     configFileLocator.Verify(gitPreparer);
 }
        private bool HandleNonMainCommand(Arguments arguments, out int exitCode)
        {
            if (arguments == null)
            {
                helpWriter.Write();
                exitCode = 1;
                return(true);
            }

            var targetPath = arguments.TargetPath;

            if (arguments.IsVersion)
            {
                var assembly = Assembly.GetExecutingAssembly();
                versionWriter.Write(assembly);
                exitCode = 0;
                return(true);
            }

            if (arguments.IsHelp)
            {
                helpWriter.Write();
                exitCode = 0;
                return(true);
            }

            if (arguments.Diag)
            {
                arguments.NoCache = true;
                arguments.Output.Add(OutputType.BuildServer);
            }

#pragma warning disable CS0612 // Type or member is obsolete
            if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec))
#pragma warning restore CS0612 // Type or member is obsolete
            {
                arguments.Output.Add(OutputType.BuildServer);
            }

            var buildServer = buildServerResolver.Resolve();
            arguments.NoFetch = arguments.NoFetch || buildServer != null && buildServer.PreventFetch();

            ConfigureLogging(arguments, log);

            if (arguments.Diag)
            {
                log.Info("Dumping commit graph: ");
                LibGitExtensions.DumpGraph(targetPath, mess => log.Info(mess), 100);
            }

            if (!Directory.Exists(targetPath))
            {
                log.Warning($"The working directory '{targetPath}' does not exist.");
            }
            else
            {
                log.Info("Working directory: " + targetPath);
            }

            configFileLocator.Verify(gitPreparer);

            if (arguments.Init)
            {
                configProvider.Init(targetPath);
                exitCode = 0;
                return(true);
            }

            if (arguments.ShowConfig)
            {
                var config = configProvider.Provide(targetPath);
                Console.WriteLine(config.ToString());
                exitCode = 0;
                return(true);
            }

            exitCode = 0;
            return(false);
        }
        private void VerifyConfiguration(Arguments arguments)
        {
            var gitPreparer = new GitPreparer(log, arguments);

            configFileLocator.Verify(gitPreparer);
        }