Skip to content

Commit

Permalink
Fix: always install locked versions
Browse files Browse the repository at this point in the history
fixes #141 #107
  • Loading branch information
ysbaddaden committed Nov 24, 2016
1 parent 4fd5f8f commit 54b8003
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/commands/install.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module Shards
end
end

# TODO: add locks as additional version requirements
private def install(packages : Set, locks : Array(Dependency))
packages.each do |package|
version = nil
Expand Down Expand Up @@ -50,7 +49,7 @@ module Shards
private def install(package : Package, version = nil)
version ||= package.version

if package.installed?(version, loose: true)
if package.installed?(version)
Shards.logger.info "Using #{package.name} (#{version})"
else
Shards.logger.info "Installing #{package.name} (#{version})"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/update.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Shards
manager.resolve

manager.packages.each do |package|
if package.installed?(loose: false)
if package.installed?
Shards.logger.info "Using #{package.name} (#{package.version})"
else
Shards.logger.info "Installing #{package.name} (#{package.version})"
Expand Down
13 changes: 3 additions & 10 deletions src/package.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ module Shards
end
end

def installed?(version = nil, loose = false)
def installed?(version = self.version)
if spec = resolver.installed_spec
version ||= spec.version

if resolver.installed_commit_hash == version
true
elsif loose
matching_versions.includes?(version)
else
self.version == version
end
resolver.installed_commit_hash == version ||
spec.version == version
else
false
end
Expand Down
20 changes: 20 additions & 0 deletions test/integration/install_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ class InstallCommandTest < Minitest::Test
end
end

def test_always_installs_locked_versions
metadata = { dependencies: { minitest: "0.1.0" }, }
lock = { minitest: "0.1.0" }

with_shard(metadata, lock) do
run "shards install"
assert_installed "minitest", "0.1.0"
assert_locked "minitest", "0.1.0"
end

metadata = { dependencies: { minitest: "0.1.2" }, }
lock = { minitest: "0.1.2" }

with_shard(metadata, lock) do
run "shards install"
assert_installed "minitest", "0.1.2"
assert_locked "minitest", "0.1.2"
end
end

def test_installs_dependency_at_locked_commit_when_refs_is_a_branch
metadata = {
dependencies: { web: { git: git_url(:web), branch: "master" } }
Expand Down

0 comments on commit 54b8003

Please sign in to comment.