File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 1+ require 'fileutils'
12require 'logging'
23require 'running'
4+ require 'shellwords'
35
46# Lightweight wrapper over Git, shells out everything.
57class GitManager
@@ -13,7 +15,7 @@ def initialize(basedir)
1315 end
1416
1517 def remote_rails_url
16- 'https://github.com/rails/rails. git'
18+ " #{ github_rails_url } . git"
1719 end
1820
1921 def update_main
@@ -38,8 +40,17 @@ def update_main
3840
3941 def checkout ( tag )
4042 Dir . chdir ( basedir ) do
41- log "checking out tag #{ tag } "
42- log_and_system "git -c advice.detachedHead=false clone -q --depth 1 --single-branch --branch #{ tag } #{ remote_rails_url } #{ tag } "
43+ log "fetching archive for tag #{ tag } "
44+ FileUtils . rm_rf ( tag )
45+ FileUtils . mkdir ( tag )
46+
47+ archive_url = remote_archive_url ( tag )
48+ log "downloading #{ archive_url } "
49+
50+ Dir . chdir ( tag ) do
51+ command = "curl -sSL #{ Shellwords . shellescape ( archive_url ) } | tar -xzf - --strip-components=1"
52+ log_and_system 'sh' , '-c' , command
53+ end
4354 end
4455 end
4556
@@ -58,4 +69,14 @@ def sha1
5869 `git rev-parse HEAD` . chomp
5970 end
6071 end
72+
73+ private
74+
75+ def remote_archive_url ( tag )
76+ "#{ github_rails_url } /archive/refs/tags/#{ tag } .tar.gz"
77+ end
78+
79+ def github_rails_url
80+ 'https://github.com/rails/rails'
81+ end
6182end
Original file line number Diff line number Diff line change 11require_relative 'test_helper'
22
33require 'git_manager'
4+ require 'shellwords'
45
56class GitManagerTest < Minitest ::Test
67 def create_repository
@@ -27,10 +28,16 @@ def test_checkout
2728 system 'echo t2 > README'
2829 system 'git commit -aqm "test"'
2930 system 'git tag t2'
31+
32+ %w( t1 t2 ) . each do |tag |
33+ archive_path = File . expand_path ( "../#{ tag } .tar.gz" , Dir . pwd )
34+ system 'sh' , '-c' , "git archive --format=tar --prefix=rails-#{ tag } / #{ tag } | gzip > #{ Shellwords . escape ( archive_path ) } "
35+ end
3036 end
3137
3238 gm = GitManager . new ( 'basedir' )
33- gm . stub ( 'remote_rails_url' , "file://#{ Dir . pwd } /basedir/main" ) do
39+ archive_dir = File . expand_path ( 'basedir' )
40+ gm . stub ( :remote_archive_url , -> ( requested_tag ) { "file://#{ File . expand_path ( "#{ requested_tag } .tar.gz" , archive_dir ) } " } ) do
3441 gm . checkout ( 't1' )
3542 end
3643
You can’t perform that action at this time.
0 commit comments