Module: Squared::Workspace::Git

Included in:
Application
Defined in:
lib/squared/workspace/project/git.rb

Instance Method Summary collapse

Instance Method Details

#git(name, uri = nil, base: nil, repo: [], options: {}) ⇒ Object



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
# File 'lib/squared/workspace/project/git.rb', line 10

def git(name, uri = nil, base: nil, repo: [], options: {})
  data = {}
  check = ->(proj) { proj.is_a?(Project::Git) && !proj.exclude?(Project::Git.ref) && git_clone?(proj.path) }
  if uri.is_a?(Array)
    base = name
    uri.each do |val|
      if (proj = @project[val.to_s]) && check.(proj)
        repo << proj
      end
    end
  elsif uri
    data[name.to_s] = uri
  elsif name.is_a?(Enumerable)
    data = name.to_h
  elsif name.is_a?(String) && name =~ GIT_PROTO
    base = name
    @project.each_value { |proj| repo << proj if !proj.parent && check.(proj) }
  else
    warn log_message(Logger::WARN, name, subject: 'git', hint: 'invalid') if warning
    return self
  end
  if base
    base = base =~ GIT_PROTO ? "#{base.chomp('/')}/" : @root.join(base)
    repo.each do |target|
      if target.is_a?(Project::Git)
        data[target.localname] = target.project
      else
        data[target.to_s] = nil
      end
    end
  end
  data.each do |key, val|
    if val.is_a?(Hash)
      uri = val.fetch(:uri, '')
      opts = val.fetch(:options, {})
    else
      uri = val.is_a?(String) ? val : key.to_s
      opts = options
    end
    unless uri.match?(GIT_PROTO) || Pathname.new(uri).absolute?
      if uri.start_with?('.')
        uri = @root.join(uri)
      elsif base
        uri = base.is_a?(Pathname) ? base.join(uri) : base + uri
      else
        next
      end
    end
    key = task_name(key)
    (GIT_REPO[main] ||= {})[key] = [uri.to_s, opts]
    (@kind[key] ||= []) << Project::Git
  end
  self
end

#git_clone?(path, name = nil) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/squared/workspace/project/git.rb', line 69

def git_clone?(path, name = nil)
  return false if name && !git_repo(name)

  !path.exist? || path.empty?
end

#git_repo(name) ⇒ Object



65
66
67
# File 'lib/squared/workspace/project/git.rb', line 65

def git_repo(name)
  (ret = GIT_REPO[main]) && ret[name]
end