Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 87a4648

Browse files
committed
Add configuration options for ecosystems and ignored files/directories
1 parent 6d5ad28 commit 87a4648

File tree

8 files changed

+330
-4
lines changed

8 files changed

+330
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## [Unreleased]
22

33
- `git pkgs init` now installs git hooks by default (use `--no-hooks` to skip)
4+
- Configuration via git config: `pkgs.ecosystems`, `pkgs.ignoredDirs`, `pkgs.ignoredFiles`
5+
- `git pkgs info --ecosystems` to show available ecosystems and their status
46

57
## [0.4.0] - 2026-01-04
68

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,21 @@ git-pkgs respects [standard git configuration](https://git-scm.com/docs/git-conf
379379

380380
**Pager** follows git's precedence: `GIT_PAGER` env, `core.pager` config, `PAGER` env, then `less -FRSX`. Use `--no-pager` flag or `git config core.pager cat` to disable.
381381

382+
**Ecosystem filtering** lets you limit which package ecosystems are tracked:
383+
384+
```bash
385+
git config --add pkgs.ecosystems rubygems
386+
git config --add pkgs.ecosystems npm
387+
git pkgs info --ecosystems # show enabled/disabled ecosystems
388+
```
389+
390+
**Ignored paths** let you skip directories or files from analysis:
391+
392+
```bash
393+
git config --add pkgs.ignoredDirs third_party
394+
git config --add pkgs.ignoredFiles test/fixtures/package.json
395+
```
396+
382397
**Environment variables:**
383398

384399
- `GIT_DIR` - git directory location (standard git variable)
@@ -399,7 +414,11 @@ Optimizations:
399414

400415
git-pkgs uses [ecosystems-bibliothecary](https://github.com/ecosyste-ms/bibliothecary) for parsing, supporting:
401416

402-
Actions, Anaconda, BentoML, Bower, Cargo, CocoaPods, Cog, CPAN, CRAN, CycloneDX, Docker, Dub, DVC, Elm, Go, Haxelib, Homebrew, Julia, Maven, Meteor, MLflow, npm, NuGet, Ollama, Packagist, Pub, PyPI, RubyGems, Shards, SPDX, Vcpkg
417+
Actions, BentoML, Bower, Cargo, CocoaPods, Cog, Conda, CPAN, CRAN, Docker, Dub, DVC, Elm, Go, Haxelib, Homebrew, Julia, Maven, Meteor, MLflow, npm, NuGet, Ollama, Packagist, Pub, PyPI, RubyGems, Shards, Vcpkg
418+
419+
Some ecosystems require remote parsing services and are disabled by default: Carthage, Clojars, Hackage, Hex, SwiftPM. Enable with `git config --add pkgs.ecosystems <name>`.
420+
421+
SBOM formats (CycloneDX, SPDX) are not supported as they duplicate information from the actual lockfiles.
403422

404423
## Contributing
405424

lib/git/pkgs.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_relative "pkgs/version"
44
require_relative "pkgs/output"
55
require_relative "pkgs/color"
6+
require_relative "pkgs/config"
67
require_relative "pkgs/cli"
78
require_relative "pkgs/database"
89
require_relative "pkgs/repository"

lib/git/pkgs/analyzer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class Analyzer
2424
Podfile Podfile.lock *.podspec *.podspec.json
2525
packages.config packages.lock.json Project.json Project.lock.json
2626
*.nuspec paket.lock *.csproj project.assets.json
27-
cyclonedx.xml cyclonedx.json *.cdx.xml *.cdx.json
28-
*.spdx *.spdx.json
2927
bower.json bentofile.yaml
3028
META.json META.yml
3129
environment.yml environment.yaml
@@ -56,6 +54,7 @@ class Analyzer
5654
def initialize(repository)
5755
@repository = repository
5856
@blob_cache = {}
57+
Config.configure_bibliothecary
5958
end
6059

6160
# Quick check if any paths might be manifests (fast regex check)
@@ -262,6 +261,7 @@ def parse_manifest_by_oid(blob_oid, manifest_path)
262261
return nil unless content
263262

264263
result = Bibliothecary.analyse_file(manifest_path, content).first
264+
result = nil if result && Config.filter_ecosystem?(result[:platform])
265265
@blob_cache[cache_key] = { result: result, hits: 0 }
266266
result
267267
end

lib/git/pkgs/commands/diff_driver.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class DiffDriver
4242
def initialize(args)
4343
@args = args
4444
@options = parse_options
45+
Config.configure_bibliothecary
4546
end
4647

4748
def run
@@ -132,6 +133,7 @@ def parse_deps(path, content)
132133

133134
result = Bibliothecary.analyse_file(path, content).first
134135
return {} unless result
136+
return {} if Config.filter_ecosystem?(result[:platform])
135137

136138
result[:dependencies].map { |d| [d[:name], d] }.to_h
137139
rescue StandardError

lib/git/pkgs/commands/info.rb

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ def initialize(args)
1212
end
1313

1414
def run
15+
if @options[:ecosystems]
16+
output_ecosystems
17+
return
18+
end
19+
1520
repo = Repository.new
1621
require_database(repo)
1722

@@ -77,6 +82,61 @@ def run
7782
end
7883
end
7984

85+
def output_ecosystems
86+
require "bibliothecary"
87+
88+
all_ecosystems = Bibliothecary::Parsers.constants.map do |c|
89+
parser = Bibliothecary::Parsers.const_get(c)
90+
parser.platform_name if parser.respond_to?(:platform_name)
91+
end.compact.sort
92+
93+
configured = Config.ecosystems
94+
filtering = configured.any?
95+
96+
puts "Available Ecosystems"
97+
puts "=" * 40
98+
puts
99+
100+
enabled_ecos = []
101+
disabled_ecos = []
102+
103+
all_ecosystems.each do |eco|
104+
if Config.filter_ecosystem?(eco)
105+
remote = Config.remote_ecosystem?(eco)
106+
disabled_ecos << { name: eco, remote: remote }
107+
else
108+
enabled_ecos << eco
109+
end
110+
end
111+
112+
puts "Enabled:"
113+
if enabled_ecos.any?
114+
enabled_ecos.each { |eco| puts " #{Color.green(eco)}" }
115+
else
116+
puts " (none)"
117+
end
118+
119+
puts
120+
puts "Disabled:"
121+
if disabled_ecos.any?
122+
disabled_ecos.each do |eco|
123+
suffix = eco[:remote] ? " (remote)" : ""
124+
puts " #{eco[:name]}#{suffix}"
125+
end
126+
else
127+
puts " (none)"
128+
end
129+
130+
puts
131+
if filtering
132+
puts "Filtering: only #{configured.join(', ')}"
133+
else
134+
puts "All local ecosystems enabled"
135+
end
136+
puts "Remote ecosystems require explicit opt-in"
137+
puts "Configure with: git config --add pkgs.ecosystems <name>"
138+
end
139+
80140
def format_size(bytes)
81141
units = %w[B KB MB GB]
82142
unit_index = 0
@@ -94,7 +154,11 @@ def parse_options
94154
options = {}
95155

96156
parser = OptionParser.new do |opts|
97-
opts.banner = "Usage: git pkgs info"
157+
opts.banner = "Usage: git pkgs info [options]"
158+
159+
opts.on("--ecosystems", "Show available ecosystems and filter status") do
160+
options[:ecosystems] = true
161+
end
98162

99163
opts.on("-h", "--help", "Show this help") do
100164
puts opts

lib/git/pkgs/config.rb

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# frozen_string_literal: true
2+
3+
require "bibliothecary"
4+
5+
module Git
6+
module Pkgs
7+
module Config
8+
# Ecosystems that require remote parsing services - disabled by default
9+
REMOTE_ECOSYSTEMS = %w[carthage clojars hackage hex swiftpm].freeze
10+
11+
# File patterns ignored by default (SBOM formats not supported)
12+
DEFAULT_IGNORED_FILES = %w[
13+
cyclonedx.xml
14+
cyclonedx.json
15+
*.cdx.xml
16+
*.cdx.json
17+
*.spdx
18+
*.spdx.json
19+
].freeze
20+
21+
def self.ignored_dirs
22+
@ignored_dirs ||= read_config_list("pkgs.ignoredDirs")
23+
end
24+
25+
def self.ignored_files
26+
@ignored_files ||= read_config_list("pkgs.ignoredFiles")
27+
end
28+
29+
def self.ecosystems
30+
@ecosystems ||= read_config_list("pkgs.ecosystems")
31+
end
32+
33+
def self.configure_bibliothecary
34+
dirs = ignored_dirs
35+
files = DEFAULT_IGNORED_FILES + ignored_files
36+
37+
Bibliothecary.configure do |config|
38+
config.ignored_dirs += dirs unless dirs.empty?
39+
config.ignored_files += files
40+
end
41+
end
42+
43+
def self.filter_ecosystem?(platform)
44+
platform_lower = platform.to_s.downcase
45+
46+
# Remote ecosystems are disabled unless explicitly enabled
47+
if REMOTE_ECOSYSTEMS.include?(platform_lower)
48+
return !ecosystems.map(&:downcase).include?(platform_lower)
49+
end
50+
51+
# If no filter configured, allow all non-remote ecosystems
52+
return false if ecosystems.empty?
53+
54+
# Otherwise, only allow explicitly listed ecosystems
55+
!ecosystems.map(&:downcase).include?(platform_lower)
56+
end
57+
58+
def self.remote_ecosystem?(platform)
59+
REMOTE_ECOSYSTEMS.include?(platform.to_s.downcase)
60+
end
61+
62+
def self.reset!
63+
@ignored_dirs = nil
64+
@ignored_files = nil
65+
@ecosystems = nil
66+
end
67+
68+
def self.read_config_list(key)
69+
`git config --get-all #{key} 2>/dev/null`.split("\n").map(&:strip).reject(&:empty?)
70+
end
71+
end
72+
end
73+
end

0 commit comments

Comments
 (0)