git-pkgs 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f93da5d41eb8fd2680e00b173dec9eb75e139ad0ab5592f04804e70f31434d28
4
- data.tar.gz: 2449898a56c1a1d9b63858095d4c6b5c057b21282700682ce77ed4484744d3bb
3
+ metadata.gz: 1ab0df1352b215987b6611a997fc62aa1e2a3ea05abe597c134812f9ec17d9d7
4
+ data.tar.gz: 5e929d2ebe9f2538d8d6b29ffc6ac89c7164f2d82afc898954159ae1a4a09ca9
5
5
  SHA512:
6
- metadata.gz: 2ea9c7449ef255277f93095601dbaeb59479521333761d1b3dd96d2efc5b96b3caa077d70144d42a3edac2c77fdec5c3ff6125f36d0510ac10a5652a31d99951
7
- data.tar.gz: b7d935a383ac2374efb1bb9279a93de95940beae2a75b219941ea70c98a67a27d2014ef33424146f69d08652403c25fe20d88e5474290231b5cf790435780075
6
+ metadata.gz: 8e8eb54a1557bd2fa965fae8dfc2d2cceca578bec650a95821abef16f19ba2d6d6ab7c88a092cddca87de0b111fa9dd526a76439555144a8638f8507201b552e
7
+ data.tar.gz: 288792ce23dc723dcf61d37606cbe26cd89f33052687156d5ae032885c8e963647d972c7b772d4712da03aab024be61eb313992a213bff88d7c02c826937c5a9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2026-01-01
4
+
5
+ - `git pkgs history` now works without a package argument to show all dependency changes
6
+ - `git pkgs diff` supports git refs (HEAD~10, branch names, tags) not just SHAs
7
+ - `git pkgs diff` lazily inserts commits not found in the database
8
+ - Expanded manifest file pattern matching for all supported ecosystems
9
+ - Switched to ecosystems-bibliothecary
10
+
3
11
  ## [0.1.0] - 2026-01-01
4
12
 
5
13
  - Initial release
data/README.md CHANGED
@@ -20,10 +20,15 @@ gem install git-pkgs
20
20
 
21
21
  ```bash
22
22
  cd your-repo
23
- git pkgs init # analyze history (one-time, ~300 commits/sec)
24
- git pkgs stats # see overview
25
- git pkgs blame # who added each dependency
26
- git pkgs history rails # track a package over time
23
+ git pkgs init # analyze history (one-time, ~300 commits/sec)
24
+ git pkgs list # show current dependencies
25
+ git pkgs stats # see overview
26
+ git pkgs blame # who added each dependency
27
+ git pkgs history # all dependency changes over time
28
+ git pkgs history rails # track a specific package
29
+ git pkgs why rails # why was this added?
30
+ git pkgs diff --from=HEAD~10 # what changed recently?
31
+ git pkgs diff --from=main --to=feature # compare branches
27
32
  ```
28
33
 
29
34
  ## Commands
@@ -105,13 +110,14 @@ Gemfile (rubygems):
105
110
  ...
106
111
  ```
107
112
 
108
- ### View package history
113
+ ### View dependency history
109
114
 
110
115
  ```bash
111
- git pkgs history rails
116
+ git pkgs history # all dependency changes
117
+ git pkgs history rails # changes for a specific package
112
118
  ```
113
119
 
114
- Shows when the package was added, version changes, and removal:
120
+ Shows when packages were added, updated, or removed:
115
121
 
116
122
  ```
117
123
  History for rails:
@@ -19,26 +19,38 @@ module Git
19
19
 
20
20
  Database.connect(repo.git_dir)
21
21
 
22
- from_sha = @options[:from]
23
- to_sha = @options[:to] || repo.head_sha
22
+ from_ref = @options[:from]
23
+ to_ref = @options[:to] || "HEAD"
24
+
25
+ unless from_ref
26
+ $stderr.puts "Usage: git pkgs diff --from=REF [--to=REF]"
27
+ exit 1
28
+ end
29
+
30
+ # Resolve git refs (like HEAD~10) to SHAs
31
+ from_sha = repo.rev_parse(from_ref)
32
+ to_sha = repo.rev_parse(to_ref)
24
33
 
25
34
  unless from_sha
26
- $stderr.puts "Usage: git pkgs diff --from=SHA [--to=SHA]"
35
+ $stderr.puts "Could not resolve '#{from_ref}'"
27
36
  exit 1
28
37
  end
29
38
 
30
- from_commit = Models::Commit.find_by(sha: from_sha) ||
31
- Models::Commit.where("sha LIKE ?", "#{from_sha}%").first
32
- to_commit = Models::Commit.find_by(sha: to_sha) ||
33
- Models::Commit.where("sha LIKE ?", "#{to_sha}%").first
39
+ unless to_sha
40
+ $stderr.puts "Could not resolve '#{to_ref}'"
41
+ exit 1
42
+ end
43
+
44
+ from_commit = find_or_create_commit(repo, from_sha)
45
+ to_commit = find_or_create_commit(repo, to_sha)
34
46
 
35
47
  unless from_commit
36
- $stderr.puts "Commit '#{from_sha}' not found in database"
48
+ $stderr.puts "Commit '#{from_sha[0..7]}' not found"
37
49
  exit 1
38
50
  end
39
51
 
40
52
  unless to_commit
41
- $stderr.puts "Commit '#{to_sha}' not found in database"
53
+ $stderr.puts "Commit '#{to_sha[0..7]}' not found"
42
54
  exit 1
43
55
  end
44
56
 
@@ -98,17 +110,38 @@ module Git
98
110
  puts "Summary: +#{added.map(&:name).uniq.count} -#{removed.map(&:name).uniq.count} ~#{modified.map(&:name).uniq.count}"
99
111
  end
100
112
 
113
+ def find_or_create_commit(repo, sha)
114
+ commit = Models::Commit.find_by(sha: sha) ||
115
+ Models::Commit.where("sha LIKE ?", "#{sha}%").first
116
+ return commit if commit
117
+
118
+ # Lazily insert commit if it exists in git but not in database
119
+ rugged_commit = repo.lookup(sha)
120
+ return nil unless rugged_commit
121
+
122
+ Models::Commit.create!(
123
+ sha: rugged_commit.oid,
124
+ message: rugged_commit.message,
125
+ author_name: rugged_commit.author[:name],
126
+ author_email: rugged_commit.author[:email],
127
+ committed_at: rugged_commit.time,
128
+ has_dependency_changes: false
129
+ )
130
+ rescue Rugged::OdbError
131
+ nil
132
+ end
133
+
101
134
  def parse_options
102
135
  options = {}
103
136
 
104
137
  parser = OptionParser.new do |opts|
105
- opts.banner = "Usage: git pkgs diff --from=SHA [--to=SHA] [options]"
138
+ opts.banner = "Usage: git pkgs diff --from=REF [--to=REF] [options]"
106
139
 
107
- opts.on("-f", "--from=SHA", "Start commit (required)") do |v|
140
+ opts.on("-f", "--from=REF", "Start commit (required)") do |v|
108
141
  options[:from] = v
109
142
  end
110
143
 
111
- opts.on("-t", "--to=SHA", "End commit (default: HEAD)") do |v|
144
+ opts.on("-t", "--to=REF", "End commit (default: HEAD)") do |v|
112
145
  options[:to] = v
113
146
  end
114
147
 
@@ -12,11 +12,6 @@ module Git
12
12
  def run
13
13
  package_name = @args.shift
14
14
 
15
- unless package_name
16
- $stderr.puts "Usage: git pkgs history <package>"
17
- exit 1
18
- end
19
-
20
15
  repo = Repository.new
21
16
 
22
17
  unless Database.exists?(repo.git_dir)
@@ -28,15 +23,20 @@ module Git
28
23
 
29
24
  changes = Models::DependencyChange
30
25
  .includes(:commit, :manifest)
31
- .for_package(package_name)
32
26
  .order("commits.committed_at ASC")
33
27
 
28
+ changes = changes.for_package(package_name) if package_name
29
+
34
30
  if @options[:ecosystem]
35
31
  changes = changes.for_platform(@options[:ecosystem])
36
32
  end
37
33
 
38
34
  if changes.empty?
39
- puts "No history found for '#{package_name}'"
35
+ if package_name
36
+ puts "No history found for '#{package_name}'"
37
+ else
38
+ puts "No dependency changes found"
39
+ end
40
40
  return
41
41
  end
42
42
 
@@ -48,7 +48,11 @@ module Git
48
48
  end
49
49
 
50
50
  def output_text(changes, package_name)
51
- puts "History for #{package_name}:"
51
+ if package_name
52
+ puts "History for #{package_name}:"
53
+ else
54
+ puts "Dependency history:"
55
+ end
52
56
  puts
53
57
 
54
58
  changes.each do |change|
@@ -67,7 +71,8 @@ module Git
67
71
  version_info = change.requirement
68
72
  end
69
73
 
70
- puts "#{date} #{action} #{version_info}"
74
+ name_prefix = package_name ? "" : "#{change.name} "
75
+ puts "#{date} #{action} #{name_prefix}#{version_info}"
71
76
  puts " Commit: #{commit.short_sha} #{commit.message&.lines&.first&.strip}"
72
77
  puts " Author: #{commit.author_name} <#{commit.author_email}>"
73
78
  puts " Manifest: #{change.manifest.path}"
@@ -80,6 +85,7 @@ module Git
80
85
 
81
86
  data = changes.map do |change|
82
87
  {
88
+ name: change.name,
83
89
  date: change.commit.committed_at.iso8601,
84
90
  change_type: change.change_type,
85
91
  requirement: change.requirement,
@@ -102,7 +108,7 @@ module Git
102
108
  options = {}
103
109
 
104
110
  parser = OptionParser.new do |opts|
105
- opts.banner = "Usage: git pkgs history <package> [options]"
111
+ opts.banner = "Usage: git pkgs history [package] [options]"
106
112
 
107
113
  opts.on("-e", "--ecosystem=NAME", "Filter by ecosystem") do |v|
108
114
  options[:ecosystem] = v
@@ -120,6 +120,12 @@ module Git
120
120
  def head_sha
121
121
  @rugged.head.target_id
122
122
  end
123
+
124
+ def rev_parse(ref)
125
+ @rugged.rev_parse(ref).oid
126
+ rescue Rugged::ReferenceError, Rugged::InvalidError
127
+ nil
128
+ end
123
129
  end
124
130
  end
125
131
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Git
4
4
  module Pkgs
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-pkgs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt