Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure --local recognizes locally cached shards #638

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/resolvers/git.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "uri"
require "ini"
require "./resolver"
require "../versions"
require "../logger"
Expand Down Expand Up @@ -358,22 +359,30 @@ module Shards
end

private def origin_url
@origin_url ||= capture("git ls-remote --get-url origin").strip
@origin_url ||= begin
git_config_file = File.join(local_path, "config")

return nil unless File.exists?(git_config_file)

config = INI.parse(File.read(git_config_file))

return config.dig("remote \"origin\"", "url")
end
end

# Returns whether origin URLs have differing hosts and/or paths.
protected def origin_changed?
return false if origin_url == git_url
return true if origin_url.nil? || git_url.nil?

origin_parsed = parse_uri(origin_url)
git_parsed = parse_uri(git_url)
origin_parsed = parse_uri(origin_url.not_nil!)
git_parsed = parse_uri(git_url.not_nil!)

(origin_parsed.host != git_parsed.host) || (origin_parsed.path != git_parsed.path)
end

# Parses a URI string, with additional support for ssh+git URI schemes.
private def parse_uri(raw_uri)
private def parse_uri(raw_uri : String)
# Need to check for file URIs early, otherwise generic parsing will fail on a colon.
if (path = raw_uri.lchop?("file://"))
return URI.new(scheme: "file", path: path)
Expand Down