dtk-client 0.5.17 → 0.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +8 -8
  2. data/lib/command_helpers/git_repo.rb +82 -48
  3. data/lib/command_helpers/service_importer.rb +26 -17
  4. data/lib/command_helpers/test_module_creator.rb +6 -5
  5. data/lib/commands/common/thor/access_control.rb +5 -4
  6. data/lib/commands/common/thor/assembly_template.rb +75 -0
  7. data/lib/commands/common/thor/assembly_workspace.rb +86 -71
  8. data/lib/commands/common/thor/clone.rb +9 -7
  9. data/lib/commands/common/thor/common.rb +17 -10
  10. data/lib/commands/common/thor/edit.rb +65 -6
  11. data/lib/commands/common/thor/list_diffs.rb +4 -3
  12. data/lib/commands/common/thor/module.rb +86 -89
  13. data/lib/commands/common/thor/pull_clone_changes.rb +3 -2
  14. data/lib/commands/common/thor/pull_from_remote.rb +9 -5
  15. data/lib/commands/common/thor/purge_clone.rb +2 -2
  16. data/lib/commands/common/thor/push_clone_changes.rb +39 -16
  17. data/lib/commands/common/thor/push_to_remote.rb +3 -3
  18. data/lib/commands/thor/account.rb +16 -4
  19. data/lib/commands/thor/assembly.rb +66 -89
  20. data/lib/commands/thor/component_module.rb +40 -24
  21. data/lib/commands/thor/node.rb +7 -0
  22. data/lib/commands/thor/provider.rb +45 -23
  23. data/lib/commands/thor/service.rb +4 -7
  24. data/lib/commands/thor/service_module.rb +45 -20
  25. data/lib/commands/thor/test_module.rb +36 -22
  26. data/lib/commands/thor/workspace.rb +6 -6
  27. data/lib/core.rb +18 -17
  28. data/lib/domain/git_adapter.rb +30 -9
  29. data/lib/dtk-client/version.rb +1 -1
  30. data/lib/parser/adapters/thor.rb +47 -25
  31. data/lib/shell/context.rb +10 -2
  32. data/lib/shell.rb +18 -12
  33. data/lib/util/module_util.rb +41 -0
  34. data/lib/util/os_util.rb +25 -7
  35. metadata +4 -2
@@ -43,11 +43,15 @@ module DTK::Client
43
43
  get_cached_response(:service_module, "service_module/list", {})
44
44
  end
45
45
 
46
+ def self.whoami()
47
+ return :service_module, "service_module/list", nil
48
+ end
49
+
46
50
  def self.override_allowed_methods()
47
51
  return DTK::Shell::OverrideTasks.new({
48
52
  :command_only => {
49
53
  :self => [
50
- ["list"," list [--remote] [--diff]","# List service modules (local/remote). Use --diff to compare loaded and remote modules."]
54
+ ["list"," list [--remote] [--diff] [-n NAMESPACE]","# List service modules (local/remote). Use --diff to compare loaded and remote modules."]
51
55
  ],
52
56
  :"assembly" => [
53
57
  ["list","list","# List assemblies for given service module."]
@@ -63,8 +67,10 @@ module DTK::Client
63
67
  ["stage", "stage [INSTANCE-NAME] [-t TARGET-NAME/ID]", "# Stage assembly in target."],
64
68
  # ["deploy","deploy [-v VERSION] [INSTANCE-NAME] [-t TARGET-NAME/ID] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
65
69
  # ["deploy","deploy [INSTANCE-NAME] [-t TARGET-NAME/ID] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
70
+ ["deploy","deploy [INSTANCE-NAME] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
66
71
  ["list-nodes","list-nodes", "# List all nodes for given assembly."],
67
- ["list-components","list-components", "# List all components for given assembly."]
72
+ ["list-components","list-components", "# List all components for given assembly."],
73
+ ["list-settings","list-settings", "# List all settings for given assembly."]
68
74
  ]
69
75
  }
70
76
 
@@ -91,9 +97,13 @@ module DTK::Client
91
97
  list(context_params)
92
98
  end
93
99
 
94
- desc "list [--remote] [--diff]","List service modules (local/remote). Use --diff to compare loaded and remote modules."
100
+ desc "list [--remote] [--diff] [-n NAMESPACE]","List service modules (local/remote). Use --diff to compare loaded and remote modules."
95
101
  method_option :remote, :type => :boolean, :default => false
96
102
  method_option :diff, :type => :boolean, :default => false
103
+ method_option :namespace, :aliases => "-n" ,
104
+ :type => :string,
105
+ :banner => "NAMESPACE",
106
+ :desc => "List modules only in specific namespace."
97
107
  def list(context_params)
98
108
  service_module_id, about, service_module_name = context_params.retrieve_arguments([:service_module_id, :option_1, :option_2],method_argument_names)
99
109
  datatype = nil
@@ -111,6 +121,7 @@ module DTK::Client
111
121
  action = options.remote? ? "list_remote" : "list"
112
122
  post_body = (options.remote? ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
113
123
  post_body[:diff] = options.diff? ? options.diff : {}
124
+ post_body.merge!(:module_namespace => options.namespace)
114
125
 
115
126
  response = post rest_url("service_module/#{action}"), post_body
116
127
  # If user is on service identifier level, list task can't have '--remote' option.
@@ -125,8 +136,7 @@ module DTK::Client
125
136
  data_type = :assembly_template
126
137
  action = "list_assemblies"
127
138
  when "modules"
128
- #data_type is set by server
129
- data_type = options.remote? ? :component_remote : :component
139
+ data_type = options.remote? ? :component_remote : :component_module
130
140
  action = "list_component_modules"
131
141
  else
132
142
  raise_validation_error_method_usage('list')
@@ -159,7 +169,7 @@ module DTK::Client
159
169
  # end
160
170
 
161
171
  # version_method_option
162
- desc "install [NAMESPACE/]REMOTE-SERVICE-MODULE-NAME [-y] [-i]", "Install remote service module into local environment. -y will automatically clone component modules. -i will ignore component import error."
172
+ desc "install NAMESPACE/REMOTE-SERVICE-MODULE-NAME [-y] [-i]", "Install remote service module into local environment. -y will automatically clone component modules. -i will ignore component import error."
163
173
  method_option :force, :aliases => '-y', :type => :boolean, :default => false
164
174
  method_option :ignore, :aliases => '-i', :type => :boolean, :default => false
165
175
  def install(context_params)
@@ -388,12 +398,13 @@ module DTK::Client
388
398
  # end
389
399
 
390
400
  # TODO: put in two versions, one that creates empty and anotehr taht creates from local dir; use --empty flag
391
- desc "import SERVICE-MODULE-NAME", "Create new service module from local clone"
401
+ desc "import [NAMESPACE:]SERVICE-MODULE-NAME", "Create new service module from local clone"
392
402
  def import(context_params)
393
403
  module_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
404
+ namespace, local_module_name = get_namespace_and_name(module_name, ':')
394
405
 
395
406
  # first check that there is a directory there and it is not already a git repo, and it ha appropriate content
396
- response = Helper(:git_repo).check_local_dir_exists_with_content(:service_module,module_name)
407
+ response = Helper(:git_repo).check_local_dir_exists_with_content(:service_module, local_module_name, nil, namespace)
397
408
  return response unless response.ok?
398
409
  service_directory = response.data(:module_directory)
399
410
 
@@ -401,23 +412,20 @@ module DTK::Client
401
412
  reparse_aux(service_directory)
402
413
 
403
414
  # first call to create empty module
404
- response = post rest_url("service_module/create"), { :module_name => module_name }
415
+ response = post rest_url("service_module/create"), { :module_name => local_module_name, :module_namespace => namespace }
405
416
  return response unless response.ok?
406
417
  @@invalidate_map << :service_module
407
418
 
408
- if error = response.data(:dsl_parsed_info)
409
- dsl_parsed_message = ServiceImporter.error_message(module_name, error)
410
- DTK::Client::OsUtil.print(dsl_parsed_message, :red)
411
- end
412
-
413
419
  # initial commit for given service module
414
- service_module_id, repo_info, module_id = response.data(:service_module_id, :repo_info)
415
- repo_url,repo_id,module_id,branch = [:repo_url,:repo_id,:module_id,:workspace_branch].map { |k| repo_info[k.to_s] }
416
- response = Helper(:git_repo).initialize_client_clone_and_push(:service_module, module_name,branch,repo_url,service_directory)
420
+ service_module_id, repo_info = response.data(:service_module_id, :repo_info)
421
+ repo_url,repo_id,module_id,branch,new_module_name = [:repo_url,:repo_id,:module_id,:workspace_branch,:full_module_name].map { |k| repo_info[k.to_s] }
422
+
423
+ response = Helper(:git_repo).rename_and_initialize_clone_and_push(:service_module, local_module_name, new_module_name,branch,repo_url,service_directory)
417
424
  return response unless response.ok?
425
+
418
426
  repo_obj,commit_sha = response.data(:repo_obj,:commit_sha)
419
427
 
420
- context_params.add_context_to_params(module_name, :"service-module", module_id)
428
+ context_params.add_context_to_params(local_module_name, :"service-module", module_id)
421
429
  push(context_params,true)
422
430
  end
423
431
 
@@ -517,13 +525,13 @@ module DTK::Client
517
525
  response
518
526
  end
519
527
 
520
- desc "delete-from-catalog [NAMESPACE/]REMOTE-SERVICE-MODULE-NAME [-y]", "Delete the service module from the DTK Network catalog"
528
+ desc "delete-from-catalog NAMESPACE/REMOTE-SERVICE-MODULE-NAME [-y]", "Delete the service module from the DTK Network catalog"
521
529
  method_option :force, :aliases => '-y', :type => :boolean, :default => false
522
530
  def delete_from_catalog(context_params)
523
531
  delete_from_catalog_aux(context_params)
524
532
  end
525
533
 
526
- desc "SERVICE-MODULE-NAME/ID delete-assembly ASSEMBLY-ID [-y]", "Delete assembly from service module."
534
+ desc "SERVICE-MODULE-NAME/ID delete-assembly ASSEMBLY-NAME [-y]", "Delete assembly from service module."
527
535
  method_option :force, :aliases => '-y', :type => :boolean, :default => false
528
536
  def delete_assembly(context_params)
529
537
  response = delete_assembly_aux(context_params)
@@ -531,6 +539,23 @@ module DTK::Client
531
539
 
532
540
  response
533
541
  end
542
+
543
+ #
544
+ # DEVELOPMENT MODE METHODS
545
+ #
546
+ if DTK::Configuration.get(:development_mode)
547
+
548
+ desc "delete-all","Delete all service modules"
549
+ def delete_all(context_params)
550
+ return unless Console.confirmation_prompt("This will DELETE ALL service modules, are you sure"+'?')
551
+ response = list(context_params)
552
+
553
+ response.data().each do |e|
554
+ run_shell_command("delete #{e['display_name']} -y -p")
555
+ end
556
+ end
557
+
558
+ end
534
559
  =begin
535
560
  desc "SERVICE-NAME/ID assembly-templates list", "List assembly templates optionally filtered by service ID/NAME."
536
561
  def assembly_template(context_params)
@@ -47,25 +47,24 @@ module DTK::Client
47
47
  set_attribute_module_aux(context_params)
48
48
  end
49
49
 
50
- desc "list [--remote] [--diff]", "List loaded or remote test modules. Use --diff to compare loaded and remote test modules."
50
+ desc "list [--remote] [--diff] [-n NAMESPACE]", "List loaded or remote test modules. Use --diff to compare loaded and remote test modules."
51
51
  method_option :remote, :type => :boolean, :default => false
52
52
  method_option :diff, :type => :boolean, :default => false
53
+ method_option :namespace, :aliases => "-n" ,
54
+ :type => :string,
55
+ :banner => "NAMESPACE",
56
+ :desc => "List modules only in specific namespace."
53
57
  def list(context_params)
54
- # Amar: attribute context commented out per Rich suggeston
55
- #if context_params.is_there_command?(:attribute)
56
- # return module_info_about(context_params, :attributes, :attribute)
57
- #elsif context_params.is_there_command?(:"component-template")
58
- # if context_params.is_there_command?(:"component-template")
59
- if context_params.is_there_command?(:"component")
60
- return module_info_about(context_params, :components, :component)
61
- end
58
+ return module_info_about(context_params, :components, :component) if context_params.is_there_command?(:"component")
62
59
 
63
60
  forwarded_remote = context_params.get_forwarded_options()["remote"] if context_params.get_forwarded_options()
64
61
  remote = options.remote? || forwarded_remote
65
62
  action = (remote ? "list_remote" : "list")
66
- # post_body = (options.remote? ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes","versions"]})
63
+
67
64
  post_body = (remote ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
68
65
  post_body[:diff] = options.diff? ? options.diff : {}
66
+ post_body.merge!(:module_namespace => options.namespace)
67
+
69
68
  response = post rest_url("test_module/#{action}"),post_body
70
69
 
71
70
  return response unless response.ok?
@@ -87,7 +86,7 @@ module DTK::Client
87
86
  module_info_about(context_params, :instances, :component)
88
87
  end
89
88
 
90
- desc "import TEST-MODULE-NAME", "Create new test module from local clone"
89
+ desc "import [NAMESPACE:]TEST-MODULE-NAME", "Create new test module from local clone"
91
90
  def import(context_params)
92
91
  response = import_module_aux(context_params)
93
92
  @@invalidate_map << :test_module if response && response.ok?
@@ -95,7 +94,15 @@ module DTK::Client
95
94
  response
96
95
  end
97
96
 
98
- desc "install [NAMESPACE/]REMOTE-TEST-MODULE-NAME","Install remote test module into local environment"
97
+ #
98
+ # Creates component module from input git repo, removing .git dir to rid of pointing to user github, and creates component module
99
+ #
100
+ desc "import-git GIT-SSH-REPO-URL [NAMESPACE:]TEST-MODULE-NAME", "Create new local test module by importing from provided git repo URL"
101
+ def import_git(context_params)
102
+ import_git_module_aux(context_params)
103
+ end
104
+
105
+ desc "install NAMESPACE/REMOTE-TEST-MODULE-NAME","Install remote test module into local environment"
99
106
  method_option "repo-manager",:aliases => "-r" ,
100
107
  :type => :string,
101
108
  :banner => "REPO-MANAGER",
@@ -107,20 +114,12 @@ module DTK::Client
107
114
  response
108
115
  end
109
116
 
110
- #
111
- # Creates component module from input git repo, removing .git dir to rid of pointing to user github, and creates component module
112
- #
113
- desc "import-git GIT-SSH-REPO-URL TEST-MODULE-NAME", "Create new local test module by importing from provided git repo URL"
114
- def import_git(context_params)
115
- import_git_module_aux(context_params)
116
- end
117
-
118
- desc "create TEST-MODULE-NAME", "Create template test module and generate all needed test module helper files"
117
+ desc "create [NAMESPACE:]TEST-MODULE-NAME", "Create template test module and generate all needed test module helper files"
119
118
  def create(context_params)
120
119
  create_test_module_aux(context_params)
121
120
  end
122
121
 
123
- desc "delete-from-catalog [NAMESPACE/]REMOTE-TEST-MODULE-NAME [-y]", "Delete the test module from the DTK Network catalog"
122
+ desc "delete-from-catalog NAMESPACE/REMOTE-TEST-MODULE-NAME [-y]", "Delete the test module from the DTK Network catalog"
124
123
  method_option :force, :aliases => '-y', :type => :boolean, :default => false
125
124
  def delete_from_catalog(context_params)
126
125
  delete_from_catalog_aux(context_params)
@@ -225,5 +224,20 @@ module DTK::Client
225
224
  list_diffs_module_aux(context_params)
226
225
  end
227
226
 
227
+
228
+ #
229
+ # DEVELOPMENT MODE METHODS
230
+ #
231
+ if DTK::Configuration.get(:development_mode)
232
+ desc "delete-all","Delete all service modules"
233
+ def delete_all(context_params)
234
+ return unless Console.confirmation_prompt("This will DELETE ALL test modules, are you sure"+'?')
235
+ response = list(context_params)
236
+
237
+ response.data().each do |e|
238
+ run_shell_command("delete #{e['display_name']} -y -p")
239
+ end
240
+ end
241
+ end
228
242
  end
229
243
  end
@@ -179,7 +179,7 @@ module DTK::Client
179
179
  push_module_updates_aux(context_params)
180
180
  end
181
181
 
182
- desc "WORKSPACE-NAME/ID push-assembly-updates SERVICE-MODULE-NAME/ASSEMBLY-NAME", "Push changes made to this workspace to the designated assembly."
182
+ desc "WORKSPACE-NAME/ID push-assembly-updates [NAMESPACE:]SERVICE-MODULE-NAME/ASSEMBLY-NAME", "Push changes made to this workspace to the designated assembly."
183
183
  def push_assembly_updates(context_params)
184
184
  workspace_id, qualified_assembly_name = context_params.retrieve_arguments([:workspace_id!,:option_1!],method_argument_names)
185
185
  if qualified_assembly_name =~ /(^[^\/]*)\/([^\/]*$)/
@@ -193,12 +193,12 @@ module DTK::Client
193
193
  Response::Ok.new()
194
194
  end
195
195
 
196
- desc "WORKSPACE-NAME/ID create-assembly SERVICE-MODULE-NAME ASSEMBLY-NAME [-p]", "Create a new assembly from the workspace instance in the designated service module."
196
+ desc "WORKSPACE-NAME/ID create-assembly [NAMESPACE:]SERVICE-MODULE-NAME ASSEMBLY-NAME [-p]", "Create a new assembly from the workspace instance in the designated service module."
197
197
  # The option -p will purge the workspace after assembly creation."
198
198
  method_option :purge, :aliases => '-p', :type => :boolean, :default => false
199
199
  def create_assembly(context_params)
200
- workspace_id, service_module_name, assembly_template_name = context_params.retrieve_arguments([:workspace_id!,:option_1!,:option_2!],method_argument_names)
201
- response = promote_assembly_aux(:create,workspace_id,service_module_name,assembly_template_name)
200
+ workspace_id, service_module_full_name, assembly_template_name = context_params.retrieve_arguments([:workspace_id!,:option_1!,:option_2!],method_argument_names)
201
+ response = promote_assembly_aux(:create,workspace_id,service_module_full_name,assembly_template_name)
202
202
  return response unless response.ok?
203
203
  if options.purge?
204
204
  response = purge_aux(context_params)
@@ -303,12 +303,12 @@ module DTK::Client
303
303
  def edit_workflow(context_params)
304
304
  edit_workflow_aux(context_params)
305
305
  end
306
- =begin
306
+
307
307
  desc "WORKSPACE-NAME/ID edit-attributes", "Edit workspace's attributes."
308
308
  def edit_attributes(context_params)
309
309
  edit_attributes_aux(context_params)
310
310
  end
311
- =end
311
+
312
312
  # using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
313
313
  desc "HIDE_FROM_BASE get-netstats", "Get netstats"
314
314
  def get_netstats(context_params)
data/lib/core.rb CHANGED
@@ -15,6 +15,7 @@ dtk_require_from_base('util/ssh_util')
15
15
  dtk_require_from_base('util/common_util')
16
16
  dtk_require_from_base('util/permission_util')
17
17
  dtk_require_from_base('util/remote_dependency_util')
18
+ dtk_require_from_base('util/module_util')
18
19
 
19
20
  dtk_require("config/configuration")
20
21
 
@@ -43,7 +44,7 @@ def top_level_execute_core(entity_name, method_name, context_params=nil, options
43
44
 
44
45
  # if connection parameters are not set up properly then don't execute any command
45
46
  return if validate_connection(conn)
46
-
47
+
47
48
  # call proper thor class and task
48
49
  entity_class = DTK::Client.const_get "#{cap_form(entity_name)}"
49
50
 
@@ -53,12 +54,12 @@ def top_level_execute_core(entity_name, method_name, context_params=nil, options
53
54
  end
54
55
 
55
56
  response_ruby_obj = entity_class.execute_from_cli(conn,method_name,context_params,options_args,shell_execute)
56
-
57
+
57
58
  # this will raise error if found
58
59
  DTK::Client::ResponseErrorHandler.check(response_ruby_obj)
59
60
 
60
61
  # this will find appropriate render adapter and give output, returns boolean
61
- if print = response_ruby_obj.render_data()
62
+ if print = response_ruby_obj.render_data()
62
63
  print = [print] unless print.kind_of?(Array)
63
64
  print.each do |el|
64
65
 
@@ -76,7 +77,7 @@ def top_level_execute_core(entity_name, method_name, context_params=nil, options
76
77
  DTK::Client::OsUtil.print(e.message, :red)
77
78
  rescue DTK::Client::DtkValidationError => e
78
79
  validation_message = e.message
79
-
80
+
80
81
  # if !e.skip_usage_info && entity_class && method_name
81
82
  # usage_info = entity_class.get_usage_info(entity_name, method_name)
82
83
  # validation_message += ", usage: #{usage_info}"
@@ -122,9 +123,9 @@ def resolve_direct_access(params, config_exists=nil)
122
123
  puts "Processing..." if config_exists
123
124
  # response = DTK::Client::Account.add_access(params[:ssh_key_path])
124
125
  response, matched_pub_key, matched_username = DTK::Client::Account.add_key(params[:ssh_key_path])
125
-
126
+
126
127
  if !response.ok?
127
- DTK::Client::OsUtil.print("We were not able to add access for current user. #{response.error_message}. In order to properly use dtk-shell you will have to add access manually ('dtk account add-ssh-key').\n", :yellow)
128
+ DTK::Client::OsUtil.print("We were not able to add access for current user. #{response.error_message}. In order to properly use dtk-shell you will have to add access manually ('dtk account add-ssh-key').\n", :yellow)
128
129
  elsif matched_pub_key
129
130
  # message will be displayed by add key # TODO: Refactor this flow
130
131
  DTK::Client::OsUtil.print("Provided SSH PUB key has already been added.", :yellow)
@@ -136,7 +137,7 @@ def resolve_direct_access(params, config_exists=nil)
136
137
  # DTK::Client::OsUtil.print("Your SSH PUB key has been successfully added.", :yellow)
137
138
  DTK::Client::Configurator.add_current_user_to_direct_access()
138
139
  end
139
-
140
+
140
141
 
141
142
  response
142
143
  end
@@ -159,7 +160,7 @@ module DTK
159
160
 
160
161
  def check(response_ruby_obj)
161
162
  # check for errors in response
162
-
163
+
163
164
  unless response_ruby_obj["errors"].nil?
164
165
  error_msg = ""
165
166
  error_internal = nil
@@ -179,7 +180,7 @@ module DTK
179
180
 
180
181
  # normalize it for display
181
182
  error_msg = error_msg.empty? ? 'Internal DTK Client error, please try again' : "#{error_msg}"
182
-
183
+
183
184
  # if error_internal.first == true
184
185
  if error_code == "unauthorized"
185
186
  raise DTK::Client::DtkError, "[UNAUTHORIZED] Your session has been suspended, please log in again."
@@ -190,7 +191,7 @@ module DTK
190
191
  elsif error_code == "forbidden"
191
192
  raise DTK::Client::DtkLoginRequiredError, "[FORBIDDEN] Access not granted, please log in again."
192
193
  elsif error_code == "timeout"
193
- raise DTK::Client::DtkError, "[TIMEOUT ERROR] Server is taking too long to respond."
194
+ raise DTK::Client::DtkError, "[TIMEOUT ERROR] Server is taking too long to respond."
194
195
  elsif error_code == "connection_refused"
195
196
  raise DTK::Client::DtkError, "[CONNECTION REFUSED] Connection refused by server."
196
197
  elsif error_code == "resource_not_found"
@@ -235,7 +236,7 @@ module DTK
235
236
 
236
237
  CONFIG_FILE = ::DTK::Client::Configurator::CONFIG_FILE
237
238
  CRED_FILE = ::DTK::Client::Configurator::CRED_FILE
238
-
239
+
239
240
  REQUIRED_KEYS = [:server_host]
240
241
 
241
242
  def self.[](k)
@@ -255,9 +256,9 @@ module DTK
255
256
  end
256
257
 
257
258
  def load_config_file()
258
- parse_key_value_file(CONFIG_FILE).each{|k,v|self[k]=v}
259
+ parse_key_value_file(CONFIG_FILE).each{|k,v|self[k]=v}
259
260
  end
260
-
261
+
261
262
  def validate
262
263
  #TODO: need to check for legal values
263
264
  missing_keys = REQUIRED_KEYS - keys
@@ -318,12 +319,12 @@ module DTK
318
319
  def self.set_timeout(timeout_sec)
319
320
  DefaultRestOpts[:timeout] = timeout_sec
320
321
  end
321
-
322
+
322
323
 
323
324
  def rest_url(route=nil)
324
325
  protocol, port = "http", Config[:server_port].to_s
325
326
  protocol, port = "https", Config[:secure_connection_server_port].to_s if Config[:secure_connection] == "true"
326
-
327
+
327
328
  "#{protocol}://#{Config[:server_host]}:#{port}/rest/#{route}"
328
329
  end
329
330
 
@@ -444,10 +445,10 @@ module DTK
444
445
  # enable SSL verification
445
446
  DefaultRestOpts.merge!(:verify_ssl => OpenSSL::SSL::VERIFY_PEER)
446
447
  # Net:HTTP from Ruby 1.8.7 doesn't verify SSL certs correctly
447
- # this is a CA bundle downloaded from http://curl.haxx.se/docs/caextract.html,
448
+ # this is a CA bundle downloaded from http://curl.haxx.se/docs/caextract.html,
448
449
  # and it will only be used for 1.8.7, otherwise the default (system) CA will be used
449
450
  DefaultRestOpts.merge!(:ssl_ca_file => File.expand_path('../lib/config/cacert.pem', File.dirname(__FILE__)))
450
-
451
+
451
452
  def get_raw(url)
452
453
  RestClientWrapper.get_raw(url, {}, DefaultRestOpts.merge(:cookies => @cookies))
453
454
  end
@@ -5,9 +5,9 @@ module DTK
5
5
  class GitAdapter
6
6
  attr_accessor :git_repo
7
7
 
8
- def initialize(repo_dir, branch = nil, opts = {})
8
+ def initialize(repo_dir, local_branch_name = nil)
9
9
  @git_repo = Git.init(repo_dir)
10
- @git_repo.branch(branch) if branch
10
+ @local_branch_name = local_branch_name
11
11
  end
12
12
 
13
13
  def changed?
@@ -103,7 +103,7 @@ module DTK
103
103
  end
104
104
 
105
105
  def head_commit_sha()
106
- current_branch.gcommit.sha
106
+ ret_local_branch.gcommit.sha
107
107
  end
108
108
 
109
109
  def find_remote_sha(ref)
@@ -129,7 +129,7 @@ module DTK
129
129
  raise Error.new("Illegal type parameter (#{type}) passed to merge_relationship")
130
130
  end
131
131
 
132
- local_sha = current_branch.gcommit.sha
132
+ local_sha = ret_local_branch.gcommit.sha
133
133
 
134
134
  opts[:ret_commit_shas][:local_sha] = local_sha if opts[:ret_commit_shas]
135
135
 
@@ -162,7 +162,7 @@ module DTK
162
162
  end
163
163
 
164
164
  def push_with_remote(remote, remote_branch)
165
- branch_for_push = "#{current_branch_name}:refs/heads/#{remote_branch||current_branch_name}"
165
+ branch_for_push = "#{local_branch_name}:refs/heads/#{remote_branch||local_branch_name}"
166
166
  @git_repo.push(remote, branch_for_push)
167
167
  end
168
168
 
@@ -174,7 +174,15 @@ module DTK
174
174
  end
175
175
 
176
176
  def pull_remote_to_local(remote_branch, local_branch, remote='origin')
177
+ # special case; if no branches and local_branch differs from master
178
+ # creates master plus local_branch
179
+ # special_case must be calculated before pull
180
+ special_case = current_branch().nil? and local_branch != 'master'
177
181
  @git_repo.pull(remote,"#{remote_branch}:#{local_branch}")
182
+ if special_case
183
+ @git_repo.branch(local_branch).checkout
184
+ @git_repo.branch('master').delete
185
+ end
178
186
  end
179
187
 
180
188
  def merge(remote_branch_ref)
@@ -195,18 +203,31 @@ module DTK
195
203
  File.exists?(repo_dir)
196
204
  end
197
205
 
198
- def current_branch_name
199
- current_branch.name
206
+ def local_branch_name
207
+ ret_local_branch.name
208
+ end
209
+
210
+ def ret_local_branch
211
+ # This build in assumption that just one local branch
212
+ unless ret = current_branch()
213
+ raise Error.new("Unexpected that current_branch() is nil")
214
+ end
215
+ if @local_branch_name
216
+ unless ret.name == @local_branch_name
217
+ raise Error.new("Unexpected that @local_branch_name (#{@local_branch_name}) does not equal current branch (#{current_branch()})")
218
+ end
219
+ end
220
+ ret
200
221
  end
201
222
 
202
- def current_branch
223
+ def current_branch()
203
224
  @git_repo.branches.local.find { |b| b.current }
204
225
  end
205
226
 
206
227
  TEMP_BRANCH = "temp_branch"
207
228
 
208
229
  def merge_theirs(remote_branch_ref)
209
- branch = current_branch_name
230
+ branch = local_branch_name
210
231
 
211
232
  # Git is not agile enoguh to work with following commands so we are using native commands to achive this
212
233
  Dir.chdir(repo_dir) do
@@ -1,3 +1,3 @@
1
1
  module DtkClient
2
- VERSION="0.5.17"
2
+ VERSION="0.5.18"
3
3
  end