Skip to content

Commit

Permalink
Fix: Git resolver doesnt pull tags anymore (#212)
Browse files Browse the repository at this point in the history
Creating bare Git repositories doesn't configure the local
repository to fetch remote refs, such as branches and tags, which
totally broke the update command.

This patch reverts back to mirroring Git repositories, and verifies
whether a cloned repository is valid, or not before fetching new
refs.

fixes #211
  • Loading branch information
ysbaddaden authored Jun 17, 2018
1 parent 1241113 commit a75a133
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/resolvers/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,23 @@ module Shards
Shards.logger.info "Fetching #{git_url}"

if cloned_repository?
fetch_repository
# repositories cloned with shards v0.8.0 won't fetch any new remote
# refs; we must delete them and clone again!
if valid_repository?
fetch_repository
else
delete_repository
mirror_repository
end
else
clone_repository
mirror_repository
end

@updated_cache = true
end

private def clone_repository
run_in_current_folder "git clone --bare --quiet -- #{FileUtils.escape git_url} #{local_path}"
private def mirror_repository
run_in_current_folder "git clone --mirror --quiet -- #{FileUtils.escape git_url} #{local_path}"
rescue Error
raise Error.new("Failed to clone #{git_url}")
end
Expand All @@ -210,6 +217,13 @@ module Shards
Dir.exists?(local_path)
end

private def valid_repository?
File.each_line(File.join(local_path, "config")) do |line|
return true if line =~ /mirror\s*=\s*true/
end
false
end

private def origin_changed?
(@origin_url ||= capture("git ls-remote --get-url origin").strip) != git_url
end
Expand Down
19 changes: 19 additions & 0 deletions test/integration/update_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ class UpdateCommandTest < Minitest::Test
end
end

def test_finds_then_updates_new_compatible_version
create_git_repository "oopsie", "1.1.0", "1.2.0"

metadata = { dependencies: { oopsie: "~> 1.1.0" } }
lock = { oopsie: "1.1.0" }

with_shard(metadata, lock) do
run "shards install"
assert_installed "oopsie", "1.1.0"
end

create_git_release "oopsie", "1.1.1"

with_shard(metadata, lock) do
run "shards update"
assert_installed "oopsie", "1.1.1"
end
end

def test_wont_generate_lockfile_for_empty_dependencies
metadata = { dependencies: {} of Symbol => String }
with_shard(metadata) do
Expand Down

0 comments on commit a75a133

Please sign in to comment.