Class: Rake::GitDependency

Inherits:
Task
  • Object
show all
Includes:
DSL
Defined in:
lib/rake-plus/git_dep.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Task

#file_missing?, #out_of_date?

Instance Attribute Details

#branch(val = nil) ⇒ Object

Returns the value of attribute branch.



6
7
8
# File 'lib/rake-plus/git_dep.rb', line 6

def branch
  @branch
end

#commit_id(val = nil) ⇒ Object

Returns the value of attribute commit_id.



6
7
8
# File 'lib/rake-plus/git_dep.rb', line 6

def commit_id
  @commit_id
end

Class Method Details

.scope_name(scope, task_name) ⇒ Object

Git based tasks ignore the scope when creating the name.



85
# File 'lib/rake-plus/git_dep.rb', line 85

def scope_name(scope, task_name); task_name end

Instance Method Details

#basenameObject



47
48
49
50
51
52
53
54
# File 'lib/rake-plus/git_dep.rb', line 47

def basename
  base = File.basename(name)
  unless File.extname(base) == ".git"
    base + ".git"
  else
    base
  end
end

#clone_to(dir, branch = nil) ⇒ Object

Utility



69
70
71
72
73
74
75
76
# File 'lib/rake-plus/git_dep.rb', line 69

def clone_to(dir, branch=nil)
  sh "git clone #{local_path} #{dir}"
  if commit_or_branch
    Dir.chdir(dir) do
      sh "git checkout #{commit_or_branch}"
    end
  end
end

#commit_or_branchObject



18
19
20
# File 'lib/rake-plus/git_dep.rb', line 18

def commit_or_branch
  @commit_id || @branch
end

#execute(args = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rake-plus/git_dep.rb', line 56

def execute(args=nil)
  if File.directory?(local_path)
    Dir.chdir(local_path) do
      sh "git remote update"
    end
  else
    FileUtils.mkdir_p File.dirname(local_path)
    sh "git clone --mirror #{name} #{local_path}"
  end
  super
end

#local_pathObject



43
44
45
# File 'lib/rake-plus/git_dep.rb', line 43

def local_path
  RakePlus.cache_dir / "git" / basename
end

#needed?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rake-plus/git_dep.rb', line 22

def needed?
  return :checkout_missing unless File.directory?(local_path)
  # check if that revision exists
  if commit_or_branch
    Dir.chdir(local_path) do
      sh("git log #{commit_or_branch} -- >/dev/null 2>&1") do |ok, res|
        return "commit_missing: #{commit_or_branch}" unless ok
      end
    end
  end
  return
end

#timestampObject



35
36
37
38
39
40
41
# File 'lib/rake-plus/git_dep.rb', line 35

def timestamp
  if File.exist?(local_path / 'HEAD')
    File.mtime(local_path / 'HEAD')
  else
    Rake::EARLY
  end
end

#unpack_to(dir) ⇒ Object

Like .tar archives, creates a folder beneath it



79
80
81
# File 'lib/rake-plus/git_dep.rb', line 79

def unpack_to(dir)
  clone_to(File.join(dir, basename))
end