aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorVlad Shablinsky2016-07-22 12:21:22 +0300
committerXu Cheng2016-08-06 21:25:56 +0800
commit1693ddbdcbaa9f92355e46af2b28ae5d05afb516 (patch)
tree7b0a068928b71bb952792cbf67f51bfa4e504373 /Library
parent1114219384baf0948cabcce8752a4537896f7704 (diff)
downloadbrew-1693ddbdcbaa9f92355e46af2b28ae5d05afb516.tar.bz2
Introduce GitHubGitDownloadStrategy
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/download_strategy.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 3016b8833..0c38e8a46 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -147,6 +147,16 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
end
end
+ def fetch_last_commit
+ fetch
+ last_commit
+ end
+
+ def commit_outdated?(commit)
+ @last_commit ||= fetch_last_commit
+ commit != @last_commit
+ end
+
def cached_location
@clone
end
@@ -756,6 +766,45 @@ class GitDownloadStrategy < VCSDownloadStrategy
end
end
+class GitHubGitDownloadStrategy < GitDownloadStrategy
+ def initialize(name, resource)
+ super
+ if @url =~ %r{^https?://github\.com/([^/]+)/([^/]+)\.git$}
+ @user = $1
+ @repo = $2
+ end
+ end
+
+ def github_last_commit
+ return if ENV["HOMEBREW_NO_GITHUB_API"]
+
+ output, _, status = curl_output "-H", "Accept: application/vnd.github.v3.sha", \
+ "-I", "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}"
+
+ commit = output[/^ETag: \"(\h+)\"/, 1] if status.success?
+ version.update_commit(commit) if commit
+ commit
+ end
+
+ def multiple_short_commits_exist?(commit)
+ return if ENV["HOMEBREW_NO_GITHUB_API"]
+ output, _, status = curl_output "-H", "Accept: application/vnd.github.v3.sha", \
+ "-I", "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}"
+
+ !(status.success? && output && output[/^Status: (200)/, 1] == "200")
+ end
+
+ def commit_outdated?(commit)
+ @last_commit ||= github_last_commit
+ if !@last_commit
+ super
+ else
+ return true unless @last_commit.start_with?(commit)
+ multiple_short_commits_exist?(commit)
+ end
+ end
+end
+
class CVSDownloadStrategy < VCSDownloadStrategy
def initialize(name, resource)
super
@@ -957,6 +1006,8 @@ class DownloadStrategyDetector
def self.detect_from_url(url)
case url
+ when %r{^https?://github\.com/[^/]+/[^/]+\.git$}
+ GitHubGitDownloadStrategy
when %r{^https?://.+\.git$}, %r{^git://}
GitDownloadStrategy
when %r{^https?://www\.apache\.org/dyn/closer\.cgi}, %r{^https?://www\.apache\.org/dyn/closer\.lua}