Class: Dapp::Dimg::GitRepo::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/dapp/dimg/git_repo/local.rb

Direct Known Subclasses

Own

Instance Attribute Summary collapse

Attributes inherited from Base

#dapp, #name

Instance Method Summary collapse

Methods inherited from Base

#branch, #commit_at, #commit_exists?, #entries, #exclude_paths, #find_commit_id_by_message, #lookup_object, #patches, #remote_branches, #remote_origin_url, #remote_origin_url_protocol, #submodule_url, #submodules_params_base, #tag_at, #tags, #walker

Methods included from Helper::Trivia

#check_path?, #check_subpath?, #class_to_lowercase, class_to_lowercase, #delete_file, #ignore_path?, #ignore_path_base, #kwargs, #make_path, #path_checker, #search_file_upward

Constructor Details

#initialize(dapp, name, path) ⇒ Local

Returns a new instance of Local.



7
8
9
10
# File 'lib/dapp/dimg/git_repo/local.rb', line 7

def initialize(dapp, name, path)
  super(dapp, name)
  self.path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/dapp/dimg/git_repo/local.rb', line 5

def path
  @path
end

Instance Method Details

#diff(from, to, **kwargs) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dapp/dimg/git_repo/local.rb', line 61

def diff(from, to, **kwargs)
  if from.nil? and to.nil?
    mid_commit = latest_commit
    diff_obj = super(nil, mid_commit, **kwargs)
    diff_obj.merge! git.lookup(mid_commit).diff_workdir(**kwargs)
    diff_obj
  elsif to.nil?
    git.lookup(from).diff_workdir(**kwargs)
  else
    super
  end
end

#ignore_patch?(patch, paths: [], exclude_paths: []) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
# File 'lib/dapp/dimg/git_repo/local.rb', line 47

def ignore_patch?(patch, paths: [], exclude_paths: [])
  delta_new_file = patch.delta.new_file
  args = [delta_new_file[:path], paths: paths, exclude_paths: exclude_paths]
  if nested_git_repository_mode?(delta_new_file[:mode])
    ignore_directory?(*args)
  else
    ignore_path?(*args)
  end
end

#latest_commit(_branch = nil) ⇒ Object



74
75
76
# File 'lib/dapp/dimg/git_repo/local.rb', line 74

def latest_commit(_branch = nil)
  git.head.target_id
end

#lookup_commit(commit) ⇒ Object



78
79
80
81
82
# File 'lib/dapp/dimg/git_repo/local.rb', line 78

def lookup_commit(commit)
  super
rescue Rugged::OdbError, TypeError => _e
  raise Error::Rugged, code: :commit_not_found_in_local_git_repository, data: { commit: commit }
end

#nested_git_directories_patches(paths: [], exclude_paths: [], **kwargs) ⇒ Object



22
23
24
25
26
27
# File 'lib/dapp/dimg/git_repo/local.rb', line 22

def nested_git_directories_patches(paths: [], exclude_paths: [], **kwargs)
  patches(nil, nil, paths: paths, exclude_paths: exclude_paths, **kwargs).select do |patch|
    delta_new_file = patch.delta.new_file
    nested_git_repository_mode?(delta_new_file[:mode])
  end
end

#nested_git_repository_mode?(mode) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/dapp/dimg/git_repo/local.rb', line 57

def nested_git_repository_mode?(mode)
  mode == 0o040000
end

#submodules_params(commit, paths: [], exclude_paths: []) ⇒ Object

NOTICE: Параметры nil, to: nil можно указать только для Own repo. NOTICE: Для Remote repo такой вызов не имеет смысла и это ошибка пользователя класса Remote.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dapp/dimg/git_repo/local.rb', line 32

def submodules_params(commit, paths: [], exclude_paths: [])
  return super unless commit.nil?
  return []    unless File.file?((gitmodules_file_path = File.join(workdir_path, '.gitmodules')))

  submodules_params_base(File.read(gitmodules_file_path),
                         paths: paths,
                         exclude_paths: exclude_paths).each do |submodule_params|
    submodule_path = File.join(workdir_path, submodule_params[:path])
    if git_repo_exist?(submodule_path)
      dapp.log_info("Using local submodule `#{submodule_path}`!")
      submodule_params[:type] = :local
    end
  end
end

#workdir_pathObject



18
19
20
# File 'lib/dapp/dimg/git_repo/local.rb', line 18

def workdir_path
  Pathname(git.workdir)
end