Class: MGit::Manifest::LightRepo

Inherits:
Struct
  • Object
show all
Defined in:
lib/m-git/manifest/light_repo.rb

Overview

该类用于配置解析后的初步处理,其字段与配置文件一致,但不保证与本地仓库状态一致。 而Repo类则会校验本地仓库,其状态与本地仓库状态一致,主要用于执行多仓库操作。

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#branchObject

Returns the value of attribute branch

Returns:

  • (Object)

    the current value of branch



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def branch
  @branch
end

#change_refObject

Returns the value of attribute change_ref

Returns:

  • (Object)

    the current value of change_ref



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def change_ref
  @change_ref
end

#commit_idObject

Returns the value of attribute commit_id

Returns:

  • (Object)

    the current value of commit_id



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def commit_id
  @commit_id
end

#dummyObject

Returns the value of attribute dummy

Returns:

  • (Object)

    the current value of dummy



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def dummy
  @dummy
end

#is_config_repoObject

Returns the value of attribute is_config_repo

Returns:

  • (Object)

    the current value of is_config_repo



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def is_config_repo
  @is_config_repo
end

#lockObject

Returns the value of attribute lock

Returns:

  • (Object)

    the current value of lock



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def lock
  @lock
end

#mgit_excludedObject

Returns the value of attribute mgit_excluded

Returns:

  • (Object)

    the current value of mgit_excluded



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def mgit_excluded
  @mgit_excluded
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def name
  @name
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def path
  @path
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def tag
  @tag
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



11
12
13
# File 'lib/m-git/manifest/light_repo.rb', line 11

def url
  @url
end

Instance Method Details

#abs_dest(root) ⇒ String

生成绝对路径

Parameters:

  • root (String)

    多仓库根目录

Returns:

  • (String)

    仓库绝对路径



74
75
76
# File 'lib/m-git/manifest/light_repo.rb', line 74

def abs_dest(root)
  Utils.expand_path(self.path, base:root)
end

#cache_store_dir(root) ⇒ String

生成缓存存放完整路径

Parameters:

  • root (String)

    多仓库根目录

Returns:

  • (String)

    缓存存放完整路径



106
107
108
# File 'lib/m-git/manifest/light_repo.rb', line 106

def cache_store_dir(root)
  File.join(git_store_dir(root), 'cache')
end

#clone_url(root, local_url: nil, clone_branch: nil) ⇒ String

根据解析内容拼接一个clone地址

Parameters:

  • root (String)

    mgit根目录

  • local_url (String) (defaults to: nil)

    default: nil 如果从本地clone,可传入一个本地的xxx.git实体地址

Returns:

  • (String)

    clone地址



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/m-git/manifest/light_repo.rb', line 54

def clone_url(root, local_url:nil, clone_branch:nil)
  url = local_url.nil? ? self.url : local_url

  if !clone_branch.nil? && Utils.branch_exist_on_remote?(clone_branch, url)
    branch_opt = "-b #{clone_branch}"
  elsif !self.branch.nil? && Utils.branch_exist_on_remote?(self.branch, url)
    branch_opt = "-b #{self.branch}"
  else
    branch_opt = ''
  end

  "git clone #{branch_opt} -- #{url} #{abs_dest(root)}"
end

#git_store_dir(root) ⇒ String

生成.git存储的完整路径

Parameters:

  • root (String)

    多仓库根目录

Returns:

  • (String)

    .git存储的完整路径



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/m-git/manifest/light_repo.rb', line 84

def git_store_dir(root)
  # 替换key值中的‘/’字符,避免和路径混淆
  name = self.name.gsub(/\//,':')

  # 删除冗余字符
  url = Utils.normalize_url(self.url)

  git_store = Utils.generate_git_store(root, url)
  if git_store.nil?
    git_dir = File.join(root, Constants::PROJECT_DIR[:source_git])
    git_store = File.join(git_dir, name)
  end

  git_store
end