Ejemplo n.º 1
0
        private async Task <bool> IsCurrentDirectoryClonableAsync()
        {
            if (!_directoryCloneEnabled)
            {
                _logger.WriteVerbose("Directory clone is disabled");
                return(false);
            }

            _logger.WriteVerbose("Directory clone is enabled");

            string sourceRoot = VcsPathHelper.TryFindVcsRootPath();

            if (string.IsNullOrWhiteSpace(sourceRoot))
            {
                _logger.WriteWarning("Could not find source root", _Prefix);
                return(false);
            }

            bool isClonable = false;

            string gitExePath = GitHelper.GetGitExePath(_logger);

            if (!string.IsNullOrWhiteSpace(gitExePath))
            {
                string gitDir = Path.Combine(sourceRoot, ".git");

                var statusAllArguments = new[]
                {
                    $"--git-dir={gitDir}",
                    $"--work-tree={sourceRoot}",
                    "status"
                };

                var argumentVariants = new List <string[]> {
                    new[] { "status" }, statusAllArguments
                };

                foreach (string[] argumentVariant in argumentVariants)
                {
                    ExitCode statusExitCode = await ProcessRunner.ExecuteAsync(
                        gitExePath,
                        arguments : argumentVariant,
                        standardOutLog : _logger.WriteVerbose,
                        standardErrorAction : _logger.WriteVerbose,
                        toolAction : _logger.Write,
                        verboseAction : _logger.WriteVerbose);

                    if (statusExitCode.IsSuccess)
                    {
                        isClonable = true;
                        break;
                    }
                }
            }

            _logger.WriteVerbose($"Is directory clonable: {isClonable}");

            return(isClonable);
        }
        public static string?TryFindVcsRootPath(Action <string>?logger = null)
        {
            if (NCrunchEnvironment.NCrunchIsResident())
            {
                var originalSolutionFileInfo = new FileInfo(NCrunchEnvironment.GetOriginalSolutionPath());
                return(VcsPathHelper.TryFindVcsRootPath(originalSolutionFileInfo.Directory?.FullName, logger));
            }

            return(VcsPathHelper.TryFindVcsRootPath(logger: logger));
        }
Ejemplo n.º 3
0
        private async Task <string> CloneDirectoryAsync()
        {
            string targetDirectoryPath = Path.Combine(
                Path.GetTempPath(),
                DefaultPaths.TempPathPrefix,
                "R",
                Guid.NewGuid().ToString().Substring(0, 8));

            var targetDirectory = new DirectoryInfo(targetDirectoryPath);

            targetDirectory.EnsureExists();

            string gitExePath = GitHelper.GetGitExePath(_logger);

            string sourceRoot = VcsPathHelper.TryFindVcsRootPath();

            IEnumerable <string> cloneArguments = new List <string>
            {
                "clone",
                sourceRoot,
                targetDirectory.FullName
            };

            _logger.WriteVerbose($"Using temp storage to clone: '{targetDirectory.FullName}'", _Prefix);

            ExitCode cloneExitCode = await ProcessHelper.ExecuteAsync(
                gitExePath,
                cloneArguments,
                _logger,
                addProcessNameAsLogCategory : true,
                addProcessRunnerCategory : true,
                parentPrefix : _Prefix);

            if (!cloneExitCode.IsSuccess)
            {
                throw new InvalidOperationException(
                          $"Could not clone directory '{sourceRoot}' to '{targetDirectory.FullName}'");
            }

            return(targetDirectory.FullName);
        }