Skip to content
Open
Show file tree
Hide file tree
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
27 changes: 24 additions & 3 deletions lib/git_manager.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'fileutils'
require 'logging'
require 'running'
require 'shellwords'

# Lightweight wrapper over Git, shells out everything.
class GitManager
Expand All @@ -13,7 +15,7 @@ def initialize(basedir)
end

def remote_rails_url
'https://github.com/rails/rails.git'
"#{github_rails_url}.git"
end

def update_main
Expand All @@ -38,8 +40,17 @@ def update_main

def checkout(tag)
Dir.chdir(basedir) do
log "checking out tag #{tag}"
log_and_system "git -c advice.detachedHead=false clone -q --depth 1 --single-branch --branch #{tag} #{remote_rails_url} #{tag}"
log "fetching archive for tag #{tag}"
FileUtils.rm_rf(tag)
FileUtils.mkdir(tag)

archive_url = remote_archive_url(tag)
log "downloading #{archive_url}"

Dir.chdir(tag) do
command = "curl -sSL #{Shellwords.shellescape(archive_url)} | tar -xzf - --strip-components=1"
log_and_system 'sh', '-c', command
end
end
end

Expand All @@ -58,4 +69,14 @@ def sha1
`git rev-parse HEAD`.chomp
end
end

private

def remote_archive_url(tag)
"#{github_rails_url}/archive/refs/tags/#{tag}.tar.gz"
end

def github_rails_url
'https://github.com/rails/rails'
end
end
9 changes: 8 additions & 1 deletion test/git_manager_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative 'test_helper'

require 'git_manager'
require 'shellwords'

class GitManagerTest < Minitest::Test
def create_repository
Expand All @@ -27,10 +28,16 @@ def test_checkout
system 'echo t2 > README'
system 'git commit -aqm "test"'
system 'git tag t2'

%w(t1 t2).each do |tag|
archive_path = File.expand_path("../#{tag}.tar.gz", Dir.pwd)
system 'sh', '-c', "git archive --format=tar --prefix=rails-#{tag}/ #{tag} | gzip > #{Shellwords.escape(archive_path)}"
end
end

gm = GitManager.new('basedir')
gm.stub('remote_rails_url', "file://#{Dir.pwd}/basedir/main") do
archive_dir = File.expand_path('basedir')
gm.stub(:remote_archive_url, ->(requested_tag) { "file://#{File.expand_path("#{requested_tag}.tar.gz", archive_dir)}" }) do
gm.checkout('t1')
end

Expand Down