Exemplo n.º 1
0
        /// <summary>
        /// Returns all the files at a specific commit by listing the file tree
        /// </summary>
        /// <param name="tree">The file tree</param>
        /// <param name="currentPath">The initial file path. (Default is "")</param>
        /// <param name="repo">The repository containing the file tree</param>
        /// <returns>List of nodes that are in the file tree.</returns>
        public IReadOnlyList <GitFileInfo> ListTree(LibGit2Sharp.Tree tree, string currentPath, LibGit2Sharp.Repository repo)
        {
            var files = new List <GitFileInfo>();

            foreach (var node in tree)
            {
                var nodePath = string.IsNullOrWhiteSpace(currentPath) ?
                               node.Path :
                               Path.Combine(currentPath, node.Path);

                if (node.TargetType == LibGit2Sharp.TreeEntryTargetType.Tree)
                {
                    files.AddRange(
                        ListTree(
                            (LibGit2Sharp.Tree)repo.Lookup(node.Target.Id),
                            nodePath,
                            repo));
                    continue;
                }

                // Only handle files
                if (node.TargetType != LibGit2Sharp.TreeEntryTargetType.Blob)
                {
                    continue;
                }

                var blobSize = ((LibGit2Sharp.Blob)node.Target).Size;
                var nodeInfo = new GitFileInfo(nodePath, blobSize);
                files.Add(nodeInfo);
            }

            return(files);
        }
Exemplo n.º 2
0
        private bool ShouldCheckOutFile(GitFileInfo file)
        {
            // Only checkout files that are known to declare NuGet dependencies.
            if (Filters.GetConfigFileType(file.Path) == Filters.ConfigFileType.None)
            {
                return(false);
            }

            if (file.BlobSize > MaxBlobSizeBytes)
            {
                _logger.LogWarning("File is too big! {FilePath} {FileSizeBytes} bytes", file.Path, file.BlobSize);
                return(false);
            }

            return(true);
        }