dtk-client 0.10.5 → 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.gitignore +1 -0
- data/bin/dtk-puppet +38 -0
- data/lib/cli/command/module/delete_from_remote.rb +3 -4
- data/lib/cli/command/module/pull_dtkn.rb +3 -1
- data/lib/cli/command/module/uninstall.rb +2 -2
- data/lib/cli/command/service/uninstall.rb +3 -3
- data/lib/cli/command/token.rb +1 -1
- data/lib/cli/version.rb +1 -1
- data/lib/client/error/subclasses.rb +7 -0
- data/lib/client/git_repo/adapter/git_gem.rb +38 -5
- data/lib/client/git_repo.rb +8 -3
- data/lib/client/load_source/component_info.rb +1 -4
- data/lib/client/load_source/service_info.rb +5 -7
- data/lib/client/load_source.rb +62 -10
- data/lib/client/module_ref.rb +2 -0
- data/lib/client/operation/client_module_dir/git_repo/internal/dtkn.rb +6 -1
- data/lib/client/operation/client_module_dir/git_repo/internal.rb +8 -2
- data/lib/client/operation/client_module_dir/git_repo.rb +13 -4
- data/lib/client/operation/module/delete_from_remote.rb +2 -2
- data/lib/client/operation/module/install/common_module.rb +1 -1
- data/lib/client/operation/module/list.rb +1 -1
- data/lib/client/operation/module/publish.rb +1 -0
- data/lib/client/operation/module/pull_dtkn.rb +4 -3
- data/lib/client/operation/module/push_dtkn/convert_source.rb +18 -5
- data/lib/client/operation/module/push_dtkn.rb +1 -1
- data/lib/client/operation/module/stage.rb +1 -1
- data/lib/client/operation/module/uninstall.rb +53 -29
- data/lib/client/operation/service/converge.rb +1 -1
- data/lib/client/operation/service/delete.rb +13 -2
- data/lib/client/operation/service/exec.rb +2 -2
- data/lib/client/operation/service/uninstall.rb +11 -8
- data/lib/client/render/view/table/processor.rb +7 -0
- data/lib/client/render.rb +1 -0
- data/lib/client/response/render_helper.rb +5 -2
- data/lib/client/service_and_component_info/transform_from/info/component.rb +1 -1
- data/lib/client/util/os_util.rb +25 -0
- data/lib/dtk_puppet/parse_structure.rb +180 -0
- data/lib/dtk_puppet/parser.rb +92 -0
- data/lib/dtk_puppet.rb +24 -0
- metadata +16 -11
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OGU5NTUzYWM4NzlhOTJiNWFmN2NhNjQwNjE1N2FkN2YwMzc4ZThkYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YjZkZDk4ODA4ZTliNDkyZjdiYjMwMWFiMGRmOWFlYzFjYzJhNzVjNA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTRhOWY0NTkwZTFlNTRlZWVhNDRmNGRjZTc3NmVlMzIzNjU5N2UzZDI1M2I1
|
10
|
+
ZGRjZTQ4MDMxOGFkOGNkNGUyYzBlZDdhOWQzOWJiNmYzNDEzNmE0YjZkNDNk
|
11
|
+
ZTVkYTZkMjdlZTVkMmI3YTk4MGY5YmU0Y2EzY2IxY2QyZDVjN2Q=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDVlYTQxM2Y0M2YwOGE1NjgwMWYzZTY4ZTBjOGEzNGMyYTA1OTE4NTlhZmVj
|
14
|
+
ZmVhMmE0M2I4NjA3ZGVlNWUzN2NiZjVhNzk0ZTY5ODVmOGVhZWRhZTgwMjgy
|
15
|
+
N2VlOWNhY2IyNWJjNjE0OGVlMTlmYjk0YWQ0NzY2MDc3MTdmMWE=
|
data/.gitignore
CHANGED
data/bin/dtk-puppet
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (C) 2010-2016 dtk contributors
|
4
|
+
#
|
5
|
+
# This file is part of the dtk project.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
module DTK
|
20
|
+
require_relative '../lib/dtk_client'
|
21
|
+
module GlobalForDSL
|
22
|
+
Error = ::DTK::Client::Error
|
23
|
+
ErrorUsage = ::DTK::Client::Error::Usage
|
24
|
+
end
|
25
|
+
#dtk_dsl must be loaded after GlobalForDSL set
|
26
|
+
require 'dtk_dsl'
|
27
|
+
|
28
|
+
Client::Error.top_level_trap_error do
|
29
|
+
begin
|
30
|
+
require 'puppet'
|
31
|
+
rescue LoadError => e
|
32
|
+
fail DTK::Client::Error::Usage.new("Puppet gem is not installed on your system. Please install it and try again.")
|
33
|
+
end
|
34
|
+
# lib/dtk_cli must be loaded after lib/client and lib/dsl
|
35
|
+
require_relative '../lib/dtk_puppet'
|
36
|
+
Puppet::Parser.parse(ARGV)
|
37
|
+
end
|
38
|
+
end
|
@@ -23,14 +23,13 @@ module DTK::Client
|
|
23
23
|
command_body c, 'delete-from-remote', 'Delete module from the DTK remote catalog (DTKN)' do |sc|
|
24
24
|
sc.flag Token.version
|
25
25
|
sc.switch Token.skip_prompt
|
26
|
-
|
27
|
-
|
26
|
+
|
28
27
|
sc.action do |_global_options, options, args|
|
29
28
|
module_ref = module_ref_object_from_options_or_context?(:module_ref => args[0], :version => options[:version])
|
30
29
|
operation_args = {
|
31
30
|
:module_ref => module_ref,
|
32
|
-
:skip_prompt => options[:skip_prompt]
|
33
|
-
:force
|
31
|
+
:skip_prompt => options[:skip_prompt]
|
32
|
+
# :force => options[:f]
|
34
33
|
}
|
35
34
|
Operation::Module.delete_from_remote(operation_args)
|
36
35
|
end
|
@@ -22,6 +22,7 @@ module DTK::Client
|
|
22
22
|
command_body c, 'pull-dtkn', 'Pull content from repo manager to client module directory and push to server' do |sc|
|
23
23
|
sc.flag Token.directory_path, :desc => 'Absolute or relative path to module directory containing content to update; not need if in the module directory'
|
24
24
|
sc.switch Token.skip_prompt
|
25
|
+
sc.switch Token.force
|
25
26
|
sc.action do |_global_options, options, _args|
|
26
27
|
module_ref = module_ref_object_from_options_or_context(options)
|
27
28
|
operation_args = {
|
@@ -29,7 +30,8 @@ module DTK::Client
|
|
29
30
|
:base_dsl_file_obj => @base_dsl_file_obj,
|
30
31
|
:has_directory_param => !options["d"].nil?,
|
31
32
|
:directory_path => options[:directory_path],
|
32
|
-
:skip_prompt => options[:skip_prompt]
|
33
|
+
:skip_prompt => options[:skip_prompt],
|
34
|
+
:force => options[:f]
|
33
35
|
}
|
34
36
|
Operation::Module.pull_dtkn(operation_args)
|
35
37
|
Operation::Module.push(operation_args.merge(:method => "pulled"))
|
@@ -32,7 +32,7 @@ module DTK::Client
|
|
32
32
|
if options[:uninstall_name].nil?
|
33
33
|
module_ref =
|
34
34
|
if module_name = args[0]
|
35
|
-
module_ref_object_from_options_or_context?({:module_ref => module_name, :version => (version
|
35
|
+
module_ref_object_from_options_or_context?({:module_ref => module_name, :version => (version)}, module_refs_opts)
|
36
36
|
else
|
37
37
|
module_ref_object_from_options_or_context(options, module_refs_opts)
|
38
38
|
end
|
@@ -42,7 +42,7 @@ module DTK::Client
|
|
42
42
|
|
43
43
|
raise Error::Usage, "You can use version only with 'namespace/name' provided" if version && module_name.nil?
|
44
44
|
|
45
|
-
Operation::Module.uninstall(:module_ref => module_ref, :skip_prompt => options[:skip_prompt], :name => options[:uninstall_name], :version => version)
|
45
|
+
Operation::Module.uninstall(:module_ref => module_ref, :skip_prompt => options[:skip_prompt], :name => options[:uninstall_name] || module_name, :version => version)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -36,14 +36,14 @@ module DTK::Client; module CLI
|
|
36
36
|
if purge && (!directory_path || (directory_path == @base_dsl_file_obj.parent_dir?))
|
37
37
|
raise Error::Usage, "If use option '#{option_ref(:purge)}' then need to call from outside directory and use option '#{option_ref(:directory_path)}'"
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
if name.nil?
|
41
41
|
service_instance = service_instance_in_options_or_context(options, :ignore_parsing_errors => true)
|
42
|
-
else
|
42
|
+
else
|
43
43
|
service_instance = name
|
44
44
|
end
|
45
45
|
|
46
|
-
args = {
|
46
|
+
args = {
|
47
47
|
:service_instance => service_instance,
|
48
48
|
:skip_prompt => options[:skip_prompt],
|
49
49
|
:directory_path => directory_path,
|
data/lib/cli/command/token.rb
CHANGED
@@ -54,7 +54,7 @@ module DTK::Client
|
|
54
54
|
# Switch constructor args order: key, desc, opts={}
|
55
55
|
:all => Switch.new(:all, 'All'),
|
56
56
|
:delete => Switch.new(:delete, 'Delete'),
|
57
|
-
:force => Switch.new(:f, 'Force'),
|
57
|
+
:force => Switch.new([:f, :force], 'Force'),
|
58
58
|
:purge => Switch.new(:purge, 'Purge'),
|
59
59
|
:push => Switch.new(:push, 'Push changes'),
|
60
60
|
:skip_prompt => Switch.new(:y, 'Skip prompt'),
|
data/lib/cli/version.rb
CHANGED
@@ -101,5 +101,12 @@ module DTK::Client
|
|
101
101
|
super("No method#{method_ref} for concrete class #{klass}")
|
102
102
|
end
|
103
103
|
end
|
104
|
+
|
105
|
+
class MissingDslFile < self
|
106
|
+
def initialize(error_msg, _opts = {})
|
107
|
+
msg_to_pass_to_super = "[ERROR] #{error_msg}"
|
108
|
+
super(msg_to_pass_to_super, :backtrace => NO_BACKTRACE)
|
109
|
+
end
|
110
|
+
end
|
104
111
|
end
|
105
112
|
end
|
@@ -38,12 +38,17 @@ module DTK::Client
|
|
38
38
|
def rev_list(sha)
|
39
39
|
self.lib.rev_list(sha)
|
40
40
|
end
|
41
|
+
|
42
|
+
def name_status(branch1 = nil, branch2 = nil, opts = {})
|
43
|
+
self.lib.name_status(branch1, branch2, opts)
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
class ::Git::Lib
|
44
48
|
def merge(branch, message = nil, opts = {})
|
45
49
|
arr_opts = []
|
46
50
|
arr_opts << '--allow-unrelated-histories' if opts[:allow_unrelated_histories]
|
51
|
+
arr_opts << '-Xtheirs' if opts[:use_theirs]
|
47
52
|
arr_opts << '-m' << message if message
|
48
53
|
arr_opts += [branch]
|
49
54
|
command('merge', arr_opts)
|
@@ -53,6 +58,29 @@ module DTK::Client
|
|
53
58
|
arr_opts = [sha]
|
54
59
|
command('rev-list', arr_opts)
|
55
60
|
end
|
61
|
+
|
62
|
+
def name_status(branch1 = nil, branch2 = nil, opts = {})
|
63
|
+
arr_opts = []
|
64
|
+
arr_opts << '--name-status'
|
65
|
+
arr_opts << "--diff-filter=#{opts[:diff_filter]}" if opts[:diff_filter]
|
66
|
+
arr_opts << branch1 if branch1
|
67
|
+
arr_opts << branch2 if branch2
|
68
|
+
|
69
|
+
command_lines('diff', arr_opts).inject({}) do |memo, line|
|
70
|
+
status, path = line.split("\t")
|
71
|
+
memo[path] = status
|
72
|
+
memo
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def command_lines(cmd, opts = [], chdir = true, redirect = '')
|
77
|
+
cmd_op = command(cmd, opts, chdir)
|
78
|
+
op = cmd_op.encode("UTF-8", "binary", {
|
79
|
+
:invalid => :replace,
|
80
|
+
:undef => :replace
|
81
|
+
})
|
82
|
+
op.split("\n")
|
83
|
+
end
|
56
84
|
end
|
57
85
|
|
58
86
|
# opts can have keys
|
@@ -108,8 +136,8 @@ module DTK::Client
|
|
108
136
|
@git_repo.push(remote, branch_for_push, opts)
|
109
137
|
end
|
110
138
|
|
111
|
-
def merge(branch_to_merge_from)
|
112
|
-
@git_repo.merge(branch_to_merge_from, 'merge', :allow_unrelated_histories => allow_unrelated_histories
|
139
|
+
def merge(branch_to_merge_from, opts = {})
|
140
|
+
@git_repo.merge(branch_to_merge_from, 'merge', :allow_unrelated_histories => allow_unrelated_histories?, :use_theirs => opts[:use_theirs])
|
113
141
|
end
|
114
142
|
|
115
143
|
def status
|
@@ -225,6 +253,10 @@ module DTK::Client
|
|
225
253
|
@git_repo.diff
|
226
254
|
end
|
227
255
|
|
256
|
+
def diff_name_status(branch_or_sha_1, branch_or_sha_2, opts = {})
|
257
|
+
@git_repo.name_status(branch_or_sha_1, branch_or_sha_2, opts)
|
258
|
+
end
|
259
|
+
|
228
260
|
def changed?
|
229
261
|
(!(changed().empty? && untracked().empty? && deleted().empty?))
|
230
262
|
end
|
@@ -233,7 +265,7 @@ module DTK::Client
|
|
233
265
|
# :with_diffs (Boolean)
|
234
266
|
def print_status(opts = {})
|
235
267
|
if opts[:with_diffs]
|
236
|
-
print_status_with_diffs
|
268
|
+
print_status_with_diffs(opts)
|
237
269
|
else
|
238
270
|
print_status_simple
|
239
271
|
end
|
@@ -256,9 +288,10 @@ module DTK::Client
|
|
256
288
|
puts ""
|
257
289
|
end
|
258
290
|
|
259
|
-
def print_status_with_diffs
|
291
|
+
def print_status_with_diffs(opts)
|
292
|
+
command = opts[:command]
|
260
293
|
changes = [changed(), untracked(), deleted()]
|
261
|
-
puts "\
|
294
|
+
puts "\nThe command '#{command}' will not be triggered, there are changes not pushed to the server:\n".colorize(:green) unless changes[0].empty?
|
262
295
|
diff = @git_repo.diff.stats[:files]
|
263
296
|
file_changed = changes[0].size
|
264
297
|
deletions = 0
|
data/lib/client/git_repo.rb
CHANGED
@@ -63,7 +63,8 @@ module DTK::Client
|
|
63
63
|
def self.modified_with_diff?(dir, opts = {})
|
64
64
|
repo_dir = {
|
65
65
|
:path => dir,
|
66
|
-
:branch => Git.open(dir).branches.local
|
66
|
+
:branch => Git.open(dir).branches.local,
|
67
|
+
:command => opts[:command]
|
67
68
|
}
|
68
69
|
|
69
70
|
message = DTK::Client::Operation::ClientModuleDir::GitRepo.modified_with_diff(repo_dir)
|
@@ -95,6 +96,10 @@ module DTK::Client
|
|
95
96
|
@git_adapter.diff
|
96
97
|
end
|
97
98
|
|
99
|
+
def diff_name_status(branch_or_sha_1 = nil, branch_or_sha_2 = nil, opts = {})
|
100
|
+
@git_adapter.diff_name_status(branch_or_sha_1, branch_or_sha_2, opts)
|
101
|
+
end
|
102
|
+
|
98
103
|
def fetch(remote = 'origin')
|
99
104
|
@git_adapter.fetch(remote)
|
100
105
|
end
|
@@ -107,8 +112,8 @@ module DTK::Client
|
|
107
112
|
@git_adapter.is_there_remote?(remote_name)
|
108
113
|
end
|
109
114
|
|
110
|
-
def merge(branch_to_merge_from)
|
111
|
-
@git_adapter.merge(branch_to_merge_from)
|
115
|
+
def merge(branch_to_merge_from, opts = {})
|
116
|
+
@git_adapter.merge(branch_to_merge_from, opts)
|
112
117
|
end
|
113
118
|
|
114
119
|
# opts can have keys:
|
@@ -20,10 +20,7 @@ module DTK::Client
|
|
20
20
|
class ComponentInfo < self
|
21
21
|
def fetch_and_cache_info
|
22
22
|
fetch_remote
|
23
|
-
|
24
|
-
merge_from_remote
|
25
|
-
transform_from_component_info
|
26
|
-
end
|
23
|
+
transform_from_component_info if merge_from_remote
|
27
24
|
end
|
28
25
|
|
29
26
|
def fetch_info
|
@@ -20,10 +20,7 @@ module DTK::Client
|
|
20
20
|
class ServiceInfo < self
|
21
21
|
def fetch_and_cache_info
|
22
22
|
fetch_remote
|
23
|
-
|
24
|
-
merge_from_remote
|
25
|
-
transform_from_service_info
|
26
|
-
end
|
23
|
+
transform_from_service_info if merge_from_remote
|
27
24
|
end
|
28
25
|
|
29
26
|
def fetch_info
|
@@ -39,9 +36,10 @@ module DTK::Client
|
|
39
36
|
def transform_from_service_info
|
40
37
|
info_processor.read_inputs_and_compute_outputs!
|
41
38
|
|
42
|
-
# delete
|
43
|
-
|
44
|
-
Operation::ClientModuleDir.
|
39
|
+
# delete only service instance files, since we need component module files for merge
|
40
|
+
info_processor.input_file_paths.map { |path| Operation::ClientModuleDir.rm_f(path) }
|
41
|
+
Operation::ClientModuleDir.rm_f("#{target_repo_dir}/assemblies")
|
42
|
+
# Operation::ClientModuleDir.delete_directory_content(target_repo_dir)
|
45
43
|
end
|
46
44
|
|
47
45
|
end
|
data/lib/client/load_source.rb
CHANGED
@@ -20,12 +20,14 @@ module DTK::Client
|
|
20
20
|
require_relative('load_source/service_info')
|
21
21
|
require_relative('load_source/component_info')
|
22
22
|
|
23
|
-
def initialize(transform_helper, info_type, remote_repo_url, parent)
|
23
|
+
def initialize(transform_helper, info_type, remote_repo_url, parent, force, use_theirs = nil)
|
24
24
|
@info_processor = transform_helper.info_processor(info_type)
|
25
25
|
@info_type = info_type
|
26
26
|
@remote_repo_url = remote_repo_url
|
27
27
|
@target_repo_dir = parent.target_repo_dir
|
28
28
|
@version = parent.version
|
29
|
+
@force = force
|
30
|
+
@use_theirs = use_theirs
|
29
31
|
end
|
30
32
|
private :initialize
|
31
33
|
|
@@ -35,16 +37,30 @@ module DTK::Client
|
|
35
37
|
target_repo_dir = parent.target_repo_dir
|
36
38
|
transform_helper = ServiceAndComponentInfo::TransformFrom.new(target_repo_dir, parent.module_ref, parent.version)
|
37
39
|
info_types_processed = []
|
40
|
+
force = opts[:force]
|
41
|
+
use_theirs = opts[:use_theirs]
|
38
42
|
|
39
43
|
if service_info = remote_module_info.data(:service_info)
|
40
|
-
ServiceInfo.fetch_and_cache_info(transform_helper, service_info['remote_repo_url'], parent)
|
44
|
+
ServiceInfo.fetch_and_cache_info(transform_helper, service_info['remote_repo_url'], parent, force, use_theirs)
|
41
45
|
info_types_processed << ServiceInfo.info_type
|
42
46
|
stage_and_commit(target_repo_dir, commit_msg(info_types_processed)) if opts[:stage_and_commit_steps]
|
43
47
|
end
|
44
48
|
|
45
49
|
if component_info = remote_module_info.data(:component_info)
|
46
|
-
|
47
|
-
|
50
|
+
begin
|
51
|
+
ComponentInfo.fetch_and_cache_info(transform_helper, component_info['remote_repo_url'], parent, force, use_theirs)
|
52
|
+
info_types_processed << ComponentInfo.info_type
|
53
|
+
|
54
|
+
if parent.is_a?(Operation::Module::PullDtkn)
|
55
|
+
stage_and_commit(target_repo_dir, commit_msg([ComponentInfo.info_type]))
|
56
|
+
delete_diffs(target_repo_dir)
|
57
|
+
end
|
58
|
+
rescue Error::MissingDslFile => e
|
59
|
+
# this is special case where in some stage git can recognize that dtk.model.yaml is renamed to dtk.module.yaml
|
60
|
+
# which then will not be introduced on merge and we get error described in the ticket https://reactor8.atlassian.net/browse/DTK-2925
|
61
|
+
raise e unless use_theirs
|
62
|
+
stage_and_commit(target_repo_dir, commit_msg(info_types_processed))
|
63
|
+
end
|
48
64
|
end
|
49
65
|
|
50
66
|
unless info_types_processed.empty?
|
@@ -55,8 +71,19 @@ module DTK::Client
|
|
55
71
|
end
|
56
72
|
end
|
57
73
|
|
58
|
-
def self.
|
59
|
-
|
74
|
+
def self.delete_diffs(target_repo_dir)
|
75
|
+
current_branch = git_repo_operation.current_branch(:path => target_repo_dir).data(:branch)
|
76
|
+
repo = git_repo_operation.create_empty_git_repo?(:repo_dir => target_repo_dir, :branch => current_branch).data(:repo)
|
77
|
+
if delete_files = repo.diff_name_status(current_branch, "remotes/dtkn-component-info/master", { :diff_filter => 'D' })
|
78
|
+
unless delete_files.empty?
|
79
|
+
to_delete = delete_files.keys.select { |key| !key.include?('dtk.model.yaml') && !key.include?('module_refs.yaml') }
|
80
|
+
to_delete.each { |file| Operation::ClientModuleDir.rm_f("#{target_repo_dir}/#{file}") }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.fetch_and_cache_info(transform_helper, remote_repo_url, parent, force, use_theirs = false)
|
86
|
+
new(transform_helper, info_type, remote_repo_url, parent, force, use_theirs).fetch_and_cache_info
|
60
87
|
end
|
61
88
|
|
62
89
|
def self.fetch_from_remote(remote_module_info, parent, opts = {})
|
@@ -71,12 +98,12 @@ module DTK::Client
|
|
71
98
|
transform_helper = ServiceAndComponentInfo::TransformFrom.new(target_repo_dir, parent.module_ref, parent.version)
|
72
99
|
|
73
100
|
if service_info = remote_module_info.data(:service_info)
|
74
|
-
srv_info = ServiceInfo.new(transform_helper, ServiceInfo.info_type, service_info['remote_repo_url'], parent)
|
101
|
+
srv_info = ServiceInfo.new(transform_helper, ServiceInfo.info_type, service_info['remote_repo_url'], parent, opts[:force])
|
75
102
|
srv_info.fetch_info
|
76
103
|
end
|
77
104
|
|
78
105
|
if component_info = remote_module_info.data(:component_info)
|
79
|
-
cmp_info = ComponentInfo.new(transform_helper, ComponentInfo.info_type, component_info['remote_repo_url'], parent)
|
106
|
+
cmp_info = ComponentInfo.new(transform_helper, ComponentInfo.info_type, component_info['remote_repo_url'], parent, opts[:force])
|
80
107
|
cmp_info.fetch_info
|
81
108
|
end
|
82
109
|
|
@@ -107,8 +134,33 @@ module DTK::Client
|
|
107
134
|
end
|
108
135
|
|
109
136
|
def merge_from_remote
|
110
|
-
|
111
|
-
|
137
|
+
merged = true
|
138
|
+
git_repo_args = common_git_repo_args.merge(:remote_branch => git_repo_remote_branch, :no_commit => true, :use_theirs => @use_theirs)
|
139
|
+
|
140
|
+
if local_ahead?.data('local_ahead')
|
141
|
+
if @force
|
142
|
+
git_repo_operation.reset_hard(git_repo_args)
|
143
|
+
else
|
144
|
+
merged = false
|
145
|
+
end
|
146
|
+
else
|
147
|
+
reset_if_merge_conflict(git_repo_operation, git_repo_args)
|
148
|
+
end
|
149
|
+
|
150
|
+
merged
|
151
|
+
end
|
152
|
+
|
153
|
+
def reset_if_merge_conflict(git_repo_operation, git_repo_args)
|
154
|
+
begin
|
155
|
+
git_repo_operation.merge_from_dtkn_remote(git_repo_args)
|
156
|
+
rescue => e
|
157
|
+
unless @force
|
158
|
+
current_branch = Operation::ClientModuleDir::GitRepo.current_branch(:path => @target_repo_dir).data(:branch)
|
159
|
+
git_repo_operation.reset_hard(git_repo_args.merge(:branch => current_branch))
|
160
|
+
raise Error::Usage, "Unable to do fast-forward merge! You can use '--force' option but all local changes will be lost!"
|
161
|
+
end
|
162
|
+
git_repo_operation.reset_hard(git_repo_args)
|
163
|
+
end
|
112
164
|
end
|
113
165
|
|
114
166
|
def local_ahead?
|
data/lib/client/module_ref.rb
CHANGED
@@ -44,6 +44,8 @@ module DTK::Client
|
|
44
44
|
|
45
45
|
def self.pretty_print(module_name, namespace, version = nil)
|
46
46
|
# TODO: update ::DTK::Common::PrettyPrintForm to insert 'master' when version is nil
|
47
|
+
version = version.join(', ') if version.is_a?(Array)
|
48
|
+
|
47
49
|
::DTK::Common::PrettyPrintForm.module_ref(module_name, :namespace => namespace, :version => version || 'master')
|
48
50
|
end
|
49
51
|
def pretty_print
|
@@ -48,7 +48,7 @@ module DTK::Client
|
|
48
48
|
# :no_commit
|
49
49
|
def merge_from_remote(remote_branch, opts = {})
|
50
50
|
merge_from_ref = "#{remote_name}/#{remote_branch}"
|
51
|
-
Internal.merge(@repo, merge_from_ref, :no_commit => opts[:no_commit])
|
51
|
+
Internal.merge(@repo, merge_from_ref, :no_commit => opts[:no_commit], :use_theirs => opts[:use_theirs])
|
52
52
|
end
|
53
53
|
|
54
54
|
def local_ahead?(remote_branch, opts = {})
|
@@ -56,6 +56,11 @@ module DTK::Client
|
|
56
56
|
Internal.local_ahead?(@repo, merge_from_ref, :no_commit => opts[:no_commit])
|
57
57
|
end
|
58
58
|
|
59
|
+
def reset_hard(remote_branch, opts = {})
|
60
|
+
merge_from_ref = opts[:branch] || "#{remote_name}/#{remote_branch}"
|
61
|
+
Internal.reset_hard(@repo, merge_from_ref)
|
62
|
+
end
|
63
|
+
|
59
64
|
private
|
60
65
|
|
61
66
|
# TODO: These constants used in Internal; Deprecate GIT_REMOTE amd LOCAL_BRANCH for remote_name and local_branch
|
@@ -55,7 +55,7 @@ module DTK::Client
|
|
55
55
|
# :no_commit
|
56
56
|
def self.merge(repo, merge_from_ref, opts = {})
|
57
57
|
base_sha = repo.head_commit_sha
|
58
|
-
repo.merge(merge_from_ref)
|
58
|
+
repo.merge(merge_from_ref, :use_theirs => opts[:use_theirs])
|
59
59
|
# the git gem does not take no_commit as merge argument; so doing it with soft reset
|
60
60
|
repo.reset_soft(base_sha) if opts[:no_commit]
|
61
61
|
repo.head_commit_sha
|
@@ -144,11 +144,12 @@ module DTK::Client
|
|
144
144
|
repo_url = args.required(:path)
|
145
145
|
branch = args.required(:branch)
|
146
146
|
repo = git_repo.new(repo_url, :branch => branch)
|
147
|
+
command = args.required(:command)
|
147
148
|
|
148
149
|
original_path = Dir.pwd
|
149
150
|
Dir.chdir(args[:path])
|
150
151
|
changed = repo.changed?
|
151
|
-
repo.print_status(:with_diffs => opts[:with_diffs]) if changed
|
152
|
+
repo.print_status(:with_diffs => opts[:with_diffs], :command => command) if changed
|
152
153
|
Dir.chdir(original_path)
|
153
154
|
changed
|
154
155
|
end
|
@@ -286,6 +287,11 @@ module DTK::Client
|
|
286
287
|
::DTK::Client::GitRepo
|
287
288
|
end
|
288
289
|
|
290
|
+
def self.reset_hard(repo, merge_from_ref)
|
291
|
+
repo.reset_hard(merge_from_ref)
|
292
|
+
repo.head_commit_sha
|
293
|
+
end
|
294
|
+
|
289
295
|
private
|
290
296
|
|
291
297
|
def self.branch_from_local_branch_type(local_branch_type)
|
@@ -106,11 +106,12 @@ module DTK::Client
|
|
106
106
|
|
107
107
|
def self.merge_from_dtkn_remote(args)
|
108
108
|
wrap_operation(args) do |args|
|
109
|
-
remote_branch
|
110
|
-
no_commit
|
111
|
-
repo_with_remote
|
109
|
+
remote_branch = args.required(:remote_branch)
|
110
|
+
no_commit = args[:no_commit]
|
111
|
+
repo_with_remote = repo_with_dtkn_remote(args)
|
112
|
+
use_theirs = args[:use_theirs]
|
112
113
|
|
113
|
-
response_data_hash(:head_sha => repo_with_remote.merge_from_remote(remote_branch, :no_commit => no_commit))
|
114
|
+
response_data_hash(:head_sha => repo_with_remote.merge_from_remote(remote_branch, :no_commit => no_commit, :use_theirs => use_theirs))
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
@@ -217,6 +218,14 @@ module DTK::Client
|
|
217
218
|
end
|
218
219
|
end
|
219
220
|
|
221
|
+
def self.reset_hard(args)
|
222
|
+
wrap_operation(args) do |args|
|
223
|
+
remote_branch = args.required(:remote_branch)
|
224
|
+
repo_with_remote = repo_with_dtkn_remote(args)
|
225
|
+
branch = args[:branch]
|
226
|
+
response_data_hash(:head_sha => repo_with_remote.reset_hard(remote_branch, :branch => branch))
|
227
|
+
end
|
228
|
+
end
|
220
229
|
|
221
230
|
private
|
222
231
|
|
@@ -37,8 +37,8 @@ module DTK::Client
|
|
37
37
|
query_string_hash = QueryStringHash.new(
|
38
38
|
:module_name => module_ref.module_name,
|
39
39
|
:namespace => module_ref.namespace,
|
40
|
-
:rsa_pub_key => SSHUtil.rsa_pub_key_content
|
41
|
-
:force?
|
40
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content
|
41
|
+
# :force? => opts[:force]
|
42
42
|
)
|
43
43
|
|
44
44
|
unless version = module_ref.version
|
@@ -38,7 +38,7 @@ module DTK::Client
|
|
38
38
|
repo_dir = file_obj.parent_dir # repo dir is directory that directly holds the base file object file_obj
|
39
39
|
git_response = ClientModuleDir::GitRepo.fetch_merge_and_push(:repo_dir => repo_dir, :repo_url => repo_url, :branch => branch)
|
40
40
|
commit_sha = git_response.data(:head_sha)
|
41
|
-
rest_post("#{BaseRoute}/update_from_repo", common_post_body.merge(:commit_sha => commit_sha))
|
41
|
+
rest_post("#{BaseRoute}/update_from_repo", common_post_body.merge(:commit_sha => commit_sha, :initial_update => true))
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -69,6 +69,7 @@ module DTK::Client
|
|
69
69
|
# this part will fetch remote branches from repo manager after publish from server is finished
|
70
70
|
LoadSource.fetch_from_remote(remote_module_info, self)
|
71
71
|
|
72
|
+
OsUtil.print_info("'#{module_ref.pretty_print}' has been published successfully.")
|
72
73
|
nil
|
73
74
|
end
|
74
75
|
end
|
@@ -39,6 +39,7 @@ module DTK::Client
|
|
39
39
|
directory_path = args[:directory_path]
|
40
40
|
has_directory_param = args[:has_directory_param]
|
41
41
|
skip_prompt = args[:skip_prompt]
|
42
|
+
force = args[:force]
|
42
43
|
|
43
44
|
if has_directory_param
|
44
45
|
file_obj = base_dsl_file_obj.raise_error_if_no_content_flag(:module_ref)
|
@@ -46,7 +47,7 @@ module DTK::Client
|
|
46
47
|
file_obj = base_dsl_file_obj.raise_error_if_no_content
|
47
48
|
end
|
48
49
|
|
49
|
-
new('dtkn', module_ref, directory_path, version, file_obj).pull_dtkn(:skip_prompt => skip_prompt)
|
50
|
+
new('dtkn', module_ref, directory_path, version, file_obj).pull_dtkn(:skip_prompt => skip_prompt, :force => force)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
@@ -61,7 +62,7 @@ module DTK::Client
|
|
61
62
|
end
|
62
63
|
|
63
64
|
error_msg = "To allow pull-dtkn to go through, invoke 'dtk push' to push the changes to server before invoking pull-dtkn again"
|
64
|
-
GitRepo.modified_with_diff?(@target_repo_dir, { :error_msg => error_msg })
|
65
|
+
GitRepo.modified_with_diff?(@target_repo_dir, { :error_msg => error_msg, :command => 'pull-dtkn' })
|
65
66
|
|
66
67
|
query_string_hash = QueryStringHash.new(
|
67
68
|
:module_name => @module_ref.module_name,
|
@@ -87,7 +88,7 @@ module DTK::Client
|
|
87
88
|
end
|
88
89
|
|
89
90
|
@print_helper.print_continuation_pulling_base_module
|
90
|
-
LoadSource.fetch_transform_and_merge(remote_module_info, self, :stage_and_commit_steps => true)
|
91
|
+
LoadSource.fetch_transform_and_merge(remote_module_info, self, :stage_and_commit_steps => true, :force => opts[:force], :use_theirs => true)
|
91
92
|
|
92
93
|
nil
|
93
94
|
end
|