Class: TerraspaceBundler::Mod::Fetcher::Git
- Inherits:
-
Base
- Object
- Base
- TerraspaceBundler::Mod::Fetcher::Git
show all
- Extended by:
- Memoist
- Defined in:
- lib/terraspace_bundler/mod/fetcher/git.rb
Instance Attribute Summary
Attributes inherited from Base
#sha
Instance Method Summary
collapse
Methods inherited from Base
#extract, #initialize
Instance Method Details
#clone ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/terraspace_bundler/mod/fetcher/git.rb', line 24
def clone
command = ["git clone", ENV['TB_GIT_CLONE_ARGS'], @mod.url].compact.join(' ')
sh command
rescue TB::GitError => e
logger.error "ERROR: #{e.message}".color(:red)
exit 1
end
|
#copy_to_stage ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/terraspace_bundler/mod/fetcher/git.rb', line 60
def copy_to_stage
cache_path = cache_path(rel_dest_dir)
stage_path = stage_path(rel_dest_dir)
FileUtils.rm_rf(stage_path)
FileUtils.mkdir_p(File.dirname(stage_path))
FileUtils.cp_r(cache_path, stage_path)
end
|
#default_branch ⇒ Object
Note: if not in a git repo, will get this error message in stderr
fatal: Not a git repository (or any of the parent directories): .git
42
43
44
45
46
47
48
49
50
|
# File 'lib/terraspace_bundler/mod/fetcher/git.rb', line 42
def default_branch
origin = `git remote show origin`.strip
found = origin.split("\n").find { |l| l.include?("HEAD") }
if found
found.split(':').last.strip
else
'master'
end
end
|
#run ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/terraspace_bundler/mod/fetcher/git.rb', line 5
def run
setup_tmp
org_path = cache_path(@mod.org)
FileUtils.mkdir_p(org_path)
Dir.chdir(org_path) do
logger.debug "Current root dir: #{org_path}"
clone unless File.exist?(@mod.repo)
Dir.chdir(@mod.repo) do
logger.debug "Change dir: #{@mod.repo}"
git "pull"
git "submodule update --init"
stage
end
end
end
|
#stage ⇒ Object
32
33
34
35
36
|
# File 'lib/terraspace_bundler/mod/fetcher/git.rb', line 32
def stage
copy_to_stage
checkout = @mod.checkout_version || default_branch
switch_version(checkout)
end
|
#switch_version(version) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/terraspace_bundler/mod/fetcher/git.rb', line 52
def switch_version(version)
stage_path = stage_path(rel_dest_dir)
Dir.chdir(stage_path) do
git "checkout #{version}"
@sha = git("rev-parse HEAD").strip
end
end
|