Skip to content

Commit

Permalink
Fix outdated command with non-release installed (#456)
Browse files Browse the repository at this point in the history
* Fix outdated command for non-release versions

* Fix spec
  • Loading branch information
straight-shoota committed Jan 21, 2021
1 parent 4fa1a39 commit 2440f81
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 11 deletions.
138 changes: 135 additions & 3 deletions spec/integration/outdated_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ describe "outdated" do
run "shards install"

stdout = run "shards outdated --no-color"
# FIXME: This should actually report dependencies are up to date (#446)
stdout.should contain("W: Outdated dependencies:")
stdout.should contain(" * missing (installed: 0.1.0 at #{commit[0..6]})")
stdout.should contain("I: Dependencies are up to date!")
end
end

Expand Down Expand Up @@ -150,4 +148,138 @@ describe "outdated" do
stdout.should contain("I: Dependencies are up to date!")
end
end

describe "non-release" do
describe "without relases" do
it "latest any" do
with_shard({dependencies: {missing: "*"}}, {missing: "0.1.0+git.commit.#{git_commits("missing").first}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("I: Dependencies are up to date!")
end
end

it "latest branch" do
with_shard({dependencies: {missing: {git: git_url("missing"), branch: "master"}}}, {missing: "0.1.0+git.commit.#{git_commits("missing").first}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("I: Dependencies are up to date!")
end
end

it "latest commit" do
with_shard({dependencies: {missing: {git: git_url("missing"), commit: git_commits("missing").first}}}, {missing: "0.1.0+git.commit.#{git_commits("missing").first}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("I: Dependencies are up to date!")
end
end

it "outdated any" do
commits = git_commits("inprogress")
with_shard({dependencies: {inprogress: "*"}}, {inprogress: "0.1.0+git.commit.#{commits[1]}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("W: Outdated dependencies:")
stdout.should contain(" * inprogress (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0 at #{commits.first[0..6]})")
end
end

it "outdated branch" do
commits = git_commits("inprogress")
with_shard({dependencies: {inprogress: {git: git_url("inprogress"), branch: "master"}}}, {inprogress: "0.1.0+git.commit.#{commits[1]}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("W: Outdated dependencies:")
stdout.should contain(" * inprogress (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0 at #{commits.first[0..6]})")
end
end

it "outdated commit" do
commits = git_commits("inprogress")
with_shard({dependencies: {inprogress: {git: git_url("inprogress"), commit: commits[1]}}}, {inprogress: "0.1.0+git.commit.#{commits[1]}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("W: Outdated dependencies:")
stdout.should contain(" * inprogress (installed: 0.1.0 at #{commits[1][0..6]}")
# TODO: commit
# stdout.should contain(" * inprogress (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0 at #{commits.first[0..6]})")
end
end
end

describe "with previous releases" do
it "outdated any" do
commits = git_commits("heading")
with_shard({dependencies: {heading: "*"}}, {heading: "0.1.0+git.commit.#{commits[1]}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("W: Outdated dependencies:")
stdout.should contain(" * heading (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0)")
# TODO: stdout.should contain(" * heading (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.1.0 at #{commits.first[0..6]})")
end
end

it "latest any" do
commits = git_commits("heading")
with_shard({dependencies: {heading: "*"}}, {heading: "0.1.0+git.commit.#{commits.first}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("I: Dependencies are up to date!")
end
end

it "latest branch" do
commits = git_commits("heading")
with_shard({dependencies: {heading: {git: git_url("heading"), branch: "master"}}}, {heading: "0.1.0+git.commit.#{commits.first}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("I: Dependencies are up to date!")
end
end
end

it "outdated any with new release" do
commits = git_commits("release_hist")
with_shard({dependencies: {release_hist: "*"}}, {release_hist: "0.1.0+git.commit.#{commits[1]}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("W: Outdated dependencies:")
stdout.should contain(" * release_hist (installed: 0.1.0 at #{commits[1][0..6]}, available: 0.2.0)")
end
end

it "outdated branch without new release" do
installed_commit = git_commits("branched", "feature")[1]
branch_head = git_commits("branched", "feature").first
with_shard({dependencies: {branched: {git: git_url("branched"), branch: "feature"}}}, {branched: "0.1.0+git.commit.#{installed_commit}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("W: Outdated dependencies:")
stdout.should contain(" * branched (installed: 0.1.0 at #{installed_commit[0..6]}, available: 0.1.0 at #{branch_head[0..6]}, latest: 0.2.0)")
end
end

it "latest branch with release on HEAD" do
branch_head = git_commits("branched", "feature").first
with_shard({dependencies: {branched: {git: git_url("branched"), branch: "feature"}}}, {branched: "0.1.0+git.commit.#{branch_head}"}) do
run "shards install"

stdout = run "shards outdated --no-color"
stdout.should contain("W: Outdated dependencies:")
stdout.should contain(" * branched (installed: 0.1.0 at #{branch_head[0..6]}, latest: 0.2.0)")
end
end
end
end
20 changes: 20 additions & 0 deletions spec/integration/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ private def setup_repositories
create_git_release "intermediate", "0.1.0", {
dependencies: {awesome: {git: git_url(:awesome)}},
}

# repo with release and unreleased commits
create_git_repository "heading"
create_git_release "heading", "0.1.0"
create_git_version_commit "heading", "0.1.0"
create_git_version_commit "heading", "0.1.0"

# repo with release and preceding commit
create_git_repository "release_hist"
create_git_release "release_hist", "0.1.0"
create_git_version_commit "release_hist", "0.1.0"
create_git_release "release_hist", "0.2.0"

# repo with branch and new release outside branch
create_git_repository "branched"
create_git_release "branched", "0.1.0"
checkout_new_git_branch "branched", "feature"
create_git_version_commit "branched", "0.1.0"
checkout_git_branch "branched", "master"
create_git_release "branched", "0.2.0"
end

private def assert(value, message, file, line)
Expand Down
50 changes: 42 additions & 8 deletions src/commands/outdated.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,63 @@ module Shards
raise LockConflict.new("#{package.name} requirements changed")
end

# already the latest version?
available_versions =
releases =
if @prereleases
resolver.available_releases
else
Versions.without_prereleases(resolver.available_releases)
end
latest = Versions.sort(available_versions).first?
releases = Versions.sort(releases)
latest_release = releases.first?

return if latest == installed
available_version = package.version

requirement = dependency.try(&.requirement)
case requirement
when GitBranchRef, GitHeadRef
requirement_branch = requirement
else
requirement_branch = nil
end

latest_ref_version = resolver.latest_version_for_ref(requirement_branch)

if installed == latest_ref_version
# If branch HEAD is installed, it is automatically the most recent for
# that requirement.
# We still need to check if a tagged release with a higher version
# is available.
if latest_release
return if Versions.compare(installed, latest_release) <= 0
else
return
end
end

case requirement
when GitBranchRef, GitHeadRef
# On branch requirement that branch's HEAD should be reported as
# available version
available_version = latest_ref_version
when GitTagRef, GitCommitRef
# TODO: Check if pinned commit is an ancestor of HEAD
else
# already the latest version?
return if latest_release == installed
end

@up_to_date = false

@output << " * " << package.name
@output << " (installed: " << resolver.report_version(installed)

unless installed == package.version
@output << ", available: " << resolver.report_version(package.version)
unless installed == available_version
@output << ", available: " << resolver.report_version(available_version)
end

# also report latest version:
if latest && Versions.compare(latest, package.version) < 0
@output << ", latest: " << resolver.report_version(latest)
if latest_release && Versions.compare(latest_release, available_version) < 0
@output << ", latest: " << resolver.report_version(latest_release)
end

@output.puts ')'
Expand Down

0 comments on commit 2440f81

Please sign in to comment.