Skip to content

Commit

Permalink
Fix: Git resolver doesn't pull tags anymore
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 committed Jun 17, 2018
1 parent 13405a9 commit fdaa712
Showing 1 changed file with 18 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

0 comments on commit fdaa712

Please sign in to comment.