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

#blobs_entries, #branch, #commit_exists?, #empty?, #exclude_paths, #find_commit_id_by_message, #head_commit, #latest_branch_commit, #latest_tag_commit, #lookup_object, #patches, #remote_branches, #remote_origin_url, #remote_origin_url_protocol, #submodule_params, #submodule_url, #submodules, #submodules_git_path, #tags, #tracked_remote_repository?, #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

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



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/dapp/dimg/git_repo/local.rb', line 84

def diff(from, to, **kwargs)
  if from.nil? and to.nil?
    mid_commit = head_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

#get_ruby2go_state_hashObject



12
13
14
15
16
17
18
19
# File 'lib/dapp/dimg/git_repo/local.rb', line 12

def get_ruby2go_state_hash
  super.tap {|res|
    p = @path.to_s
    p = File.dirname(@path) if File.basename(@path) == ".git"
    res["Path"] = p
    res["OrigPath"] = @path.to_s
  }
end

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

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
# File 'lib/dapp/dimg/git_repo/local.rb', line 67

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

#lookup_commit(commit) ⇒ Object



97
98
99
100
101
# File 'lib/dapp/dimg/git_repo/local.rb', line 97

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

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



36
37
38
39
40
41
# File 'lib/dapp/dimg/git_repo/local.rb', line 36

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)


77
78
79
# File 'lib/dapp/dimg/git_repo/local.rb', line 77

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

#raise_submodule_commit_not_found!(commit) ⇒ Object

Raises:



63
64
65
# File 'lib/dapp/dimg/git_repo/local.rb', line 63

def raise_submodule_commit_not_found!(commit)
  raise Error::Rugged, code: :git_local_submodule_commit_not_found, data: { commit: commit, path: path }
end

#set_ruby2go_state_hash(state) ⇒ Object



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

def set_ruby2go_state_hash(state)
  super(state)
  @path = state["OrigPath"]
end

#submodules_git(commit) ⇒ Object



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

def submodules_git(commit)
  if commit.nil?
    git
  else
    super
  end
end

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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dapp/dimg/git_repo/local.rb', line 43

def submodules_params(commit, paths: [], exclude_paths: [])
  submodules(commit, paths: paths, exclude_paths: exclude_paths).map do |submodule|
    submodule_params(submodule).tap do |params|
      params[:commit] = submodule.workdir_oid || params[:commit] if commit.nil?
      if submodule.in_workdir? && !submodule.uninitialized?
        dapp.log_info("Using local submodule repository `#{params[:path]}`!")
        params[:type] = :local
      end
    end
  end.compact
end

#workdir_pathObject



32
33
34
# File 'lib/dapp/dimg/git_repo/local.rb', line 32

def workdir_path
  Pathname(git.workdir)
end