raise ArgumentError.new "invalid sha1 #{sha1}"
end
src_gitdir, _ = git_dir_for repo_name
+ unless src_gitdir
+ raise ArgumentError.new "no local repository for #{repo_name}"
+ end
dst_gitdir = Rails.configuration.git_internal_dir
must_pipe("echo #{sha1.shellescape}",
"git --git-dir #{src_gitdir.shellescape} pack-objects -q --revs --stdout",
end
def self.cache_dir_for git_url
- Rails.root.join('tmp', 'git', Digest::SHA1.hexdigest(git_url) + ".git").
- to_s
+ File.join(cache_dir_base, Digest::SHA1.hexdigest(git_url) + ".git").to_s
+ end
+
+ def self.cache_dir_base
+ Rails.root.join 'tmp', 'git'
end
def self.fetch_remote_repository gitdir, git_url
unless /^[a-z]+:\/\// =~ git_url
raise ArgumentError.new "invalid git url #{git_url}"
end
- FileUtils.mkdir_p gitdir
+ begin
+ must_git gitdir, "branch"
+ rescue GitError => e
+ raise unless /Not a git repository/ =~ e.to_s
+ # OK, this just means we need to create a blank cache repository
+ # before fetching.
+ FileUtils.mkdir_p gitdir
+ must_git gitdir, "init"
+ end
must_git(gitdir,
- "init",
"fetch --no-progress --tags --prune --force --update-head-ok #{git_url.shellescape} 'refs/heads/*:refs/heads/*'")
end