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

Commit f5e1266

Browse files
committed
Fix update classification logic to return nil for invalid formats and downgrades
1 parent 25a781d commit f5e1266

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

CHANGELOG.md

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

33
- Auto-upgrade outdated database schemas instead of erroring
4+
- Fix `outdated` command suggesting downgrades when current version is newer than registry
45

56
## [0.9.0] - 2026-01-14
67

lib/git/pkgs/commands/outdated.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def run
115115
next if current == latest
116116

117117
update_type = classify_update(current, latest)
118+
next unless update_type
118119
next if @options[:major_only] && update_type != :major
119120
next if @options[:minor_only] && update_type == :patch
120121

@@ -129,7 +130,7 @@ def run
129130
return
130131
end
131132

132-
type_order = { major: 0, minor: 1, patch: 2, unknown: 3 }
133+
type_order = { major: 0, minor: 1, patch: 2 }
133134
outdated.sort_by! { |o| [type_order[o[:update_type]], o[:name]] }
134135

135136
if @options[:format] == "json"
@@ -173,16 +174,15 @@ def classify_update(current, latest)
173174
current_parts = parse_version(current)
174175
latest_parts = parse_version(latest)
175176

176-
return :unknown if current_parts.nil? || latest_parts.nil?
177+
return nil if current_parts.nil? || latest_parts.nil?
178+
return nil if (current_parts <=> latest_parts) >= 0
177179

178180
if latest_parts[0] > current_parts[0]
179181
:major
180182
elsif latest_parts[1] > current_parts[1]
181183
:minor
182-
elsif latest_parts[2] > current_parts[2]
183-
:patch
184184
else
185-
:unknown
185+
:patch
186186
end
187187
end
188188

test/git/pkgs/test_outdated_command.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,26 @@ def test_classify_update_with_v_prefix
5151
assert_equal :minor, cmd.classify_update("v1.0.0", "1.1.0")
5252
end
5353

54-
def test_classify_update_unknown_format
54+
def test_classify_update_invalid_format
5555
cmd = Git::Pkgs::Commands::Outdated.new([])
5656

57-
assert_equal :unknown, cmd.classify_update("abc", "def")
58-
assert_equal :unknown, cmd.classify_update("", "1.0.0")
57+
assert_nil cmd.classify_update("abc", "def")
58+
assert_nil cmd.classify_update("", "1.0.0")
59+
end
60+
61+
def test_classify_update_downgrade_returns_nil
62+
cmd = Git::Pkgs::Commands::Outdated.new([])
63+
64+
assert_nil cmd.classify_update("2.0.0", "1.0.0")
65+
assert_nil cmd.classify_update("1.5.0", "1.4.0")
66+
assert_nil cmd.classify_update("1.0.5", "1.0.4")
67+
assert_nil cmd.classify_update("2.0.0", "1.5.0")
68+
end
69+
70+
def test_classify_update_same_version_returns_nil
71+
cmd = Git::Pkgs::Commands::Outdated.new([])
72+
73+
assert_nil cmd.classify_update("1.0.0", "1.0.0")
5974
end
6075

6176
def test_parse_version

0 commit comments

Comments
 (0)