Module: DTK::Client::PushToRemoteMixin

Included in:
ModuleMixin
Defined in:
lib/commands/common/thor/push_to_remote.rb

Constant Summary collapse

NO_PUSH_CHANGES_MSG =
"There are no changes to push"

Instance Method Summary collapse

Instance Method Details

#push_to_git_remote_aux(full_module_name, module_type, version, opts, force = false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/commands/common/thor/push_to_remote.rb', line 27

def push_to_git_remote_aux(full_module_name, module_type, version, opts, force = false)
  opts.merge!(:force => force)

  response = Helper(:git_repo).push_changes(module_type, full_module_name, version, opts)

  return response unless response.ok?
  if response.data(:diffs) && !response.data(:diffs)[:are_there_changes]
    raise DtkError, NO_PUSH_CHANGES_MSG
  end

  Response::Ok.new()
end

#push_to_git_remote_location_aux(full_module_name, module_type, version, opts, force = false) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/commands/common/thor/push_to_remote.rb', line 40

def push_to_git_remote_location_aux(full_module_name, module_type, version, opts, force = false)
  opts.merge!(:force => force)

  # staging dir which will be removed
  temp_stage_dir = OsUtil.temp_git_remote_location()
  content_dir    = File::join(temp_stage_dir, opts[:remote_repo_location])

  begin
    # clone desired repo
    ::DTK::Client::GitAdapter.clone(opts[:remote_repo_url], temp_stage_dir, opts[:remote_branch])
    # make sure that content dir exist
    FileUtils.mkdir_p(content_dir)
    # copy content of module to new dir (overriding everything in process)
    module_location = OsUtil.module_location(module_type, full_module_name, version)
    FileUtils.cp_r(File.join(module_location, '/.'), content_dir)
    # remove git folder
    FileUtils.rm_rf(File.join(content_dir, '.git'))
    # now we push it
    opts.merge!(:override_repo_dir_location => temp_stage_dir)
    response = Helper(:git_repo).push_changes(module_type, full_module_name, version, opts)
    return response unless response.ok?

    if response.data(:diffs) && !response.data(:diffs)[:are_there_changes]
      raise DtkError, NO_PUSH_CHANGES_MSG
    end

    Response::Ok.new()
  ensure
    FileUtils.rm_rf(temp_stage_dir)
  end
end

#push_to_remote_aux(remote_module_info, module_type, force = false) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/commands/common/thor/push_to_remote.rb', line 72

def push_to_remote_aux(remote_module_info, module_type, force = false)
  full_module_name     = remote_module_info.data(:full_module_name)
  version = remote_module_info.data(:version)

  opts = {
    :remote_repo_url => remote_module_info.data(:remote_repo_url),
    :remote_repo => remote_module_info.data(:remote_repo),
    :remote_branch => remote_module_info.data(:remote_branch),
    :local_branch => remote_module_info.data(:workspace_branch),
    :where => 'catalog',
    :force => force
  }
  response = Helper(:git_repo).push_changes(module_type, full_module_name, version, opts)
  return response unless response.ok?
  if response.data(:diffs) && !response.data(:diffs)[:are_there_changes]
    raise DtkError, NO_PUSH_CHANGES_MSG
  end

  Response::Ok.new()
end