-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
temporary_repos.rb
106 lines (91 loc) · 2.85 KB
/
temporary_repos.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module SpecHelper
def self.tmp_repos_path
TemporaryRepos.tmp_repos_path
end
module TemporaryRepos
extend Pod::Executable
executable :git
# @return [Pathname] The path for the repo with the given name.
#
def repo_path(name)
tmp_repos_path + name
end
# Makes a repo with the given name.
#
def repo_make(name)
path = repo_path(name)
path.mkpath
Dir.chdir(path) do
`git init`
repo_make_readme_change(name, 'Added')
`git add .`
`git commit -m "Initialized."`
end
path
end
# Clones a repo to the given name.
#
def repo_clone(from_name, to_name)
Dir.chdir(tmp_repos_path) { `git clone #{from_name} #{to_name} 2>&1 > /dev/null` }
repo_path(to_name)
end
def repo_make_readme_change(name, string)
file = repo_path(name) + 'README'
file.open('w') { |f| f << "#{string}" }
end
#--------------------------------------#
def test_repo_path
repo_path('master')
end
# Sets up a lighweight master repo in `tmp/cocoapods/repos/master` with the
# contents of `spec/fixtures/spec-repos/test_repo`.
#
def set_up_test_repo
require 'fileutils'
test_repo_path.mkpath
origin = ROOT + 'spec/fixtures/spec-repos/test_repo/.'
destination = tmp_repos_path + 'master'
FileUtils.cp_r(origin, destination)
FileUtils.rm_r(destination + './.git')
repo_make('master')
end
def test_old_repo_path
repo_path('../master')
end
# Sets up a lighweight master repo in `tmp/cocoapods/master` with the
# contents of `spec/fixtures/spec-repos/test_repo`.
#
def set_up_old_test_repo
require 'fileutils'
test_old_repo_path.mkpath
origin = ROOT + 'spec/fixtures/spec-repos/test_repo/.'
destination = tmp_repos_path + '../master'
FileUtils.cp_r(origin, destination)
FileUtils.rm_r(destination + './.git')
repo_make('../master')
end
#--------------------------------------#
def tmp_repos_path
TemporaryRepos.tmp_repos_path
end
def self.tmp_repos_path
SpecHelper.temporary_directory + 'cocoapods/repos'
end
def self.extended(base)
# Make Context methods available
# WORKAROUND: Bacon auto-inherits singleton methods to child contexts
# by using the runtime and won't include methods in modules included
# by the parent context. We have to ensure that the methods will be
# accessible by the child contexts by defining them as singleton methods.
TemporaryRepos.instance_methods.each do |method|
unbound_method = base.method(method).unbind
base.define_singleton_method method do |*args, &b|
unbound_method.bind(self).call(*args, &b)
end
end
base.before do
tmp_repos_path.mkpath
end
end
end
end