mortar 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mortar/auth.rb CHANGED
@@ -117,7 +117,10 @@ class Mortar::Auth
117
117
  def netrc_path
118
118
  default = Netrc.default_path
119
119
  encrypted = default + ".gpg"
120
- if File.exists?(encrypted)
120
+ from_env = ENV['MORTAR_LOGIN_FILE']
121
+ if from_env
122
+ from_env
123
+ elsif File.exists?(encrypted)
121
124
  encrypted
122
125
  else
123
126
  default
@@ -160,11 +160,11 @@ class Mortar::Command::Base
160
160
  end
161
161
  end
162
162
 
163
- def initialize_gitless_project(api_registration_result)
163
+ def initialize_embedded_project(api_registration_result)
164
164
  File.open(".mortar-project-remote", "w") do |f|
165
165
  f.puts api_registration_result["git_url"]
166
166
  end
167
- git.sync_gitless_project(project, "master")
167
+ git.sync_embedded_project(project, "master")
168
168
  end
169
169
 
170
170
  protected
@@ -303,7 +303,7 @@ protected
303
303
  end
304
304
  end
305
305
 
306
- def validate_gitless_project!
306
+ def validate_embedded_project!
307
307
  unless project.root_path
308
308
  error("#{current_command[:command]} must be run from the project root directory")
309
309
  end
@@ -399,8 +399,8 @@ protected
399
399
 
400
400
  def sync_code_with_cloud
401
401
  # returns git_ref
402
- if project.gitless_project?
403
- return git.sync_gitless_project(project, embedded_project_user_branch)
402
+ if project.embedded_project?
403
+ return git.sync_embedded_project(project, embedded_project_user_branch)
404
404
  else
405
405
  validate_git_based_project!
406
406
  return git.create_and_push_snapshot_branch(project)
@@ -60,7 +60,7 @@ class Mortar::Command::Projects < Mortar::Command::Base
60
60
  #
61
61
  # Used when you want to start a new Mortar project using Mortar generated code.
62
62
  #
63
- # --withoutgit # Create a Mortar project that is not its own git repo. Your code will still be synced with a git repo in the cloud.
63
+ # --embedded # Create a Mortar project that is not its own git repo. Your code will still be synced with a git repo in the cloud.
64
64
  #
65
65
  def create
66
66
  name = shift_argument
@@ -71,8 +71,8 @@ class Mortar::Command::Projects < Mortar::Command::Base
71
71
  Mortar::Command::run("generate:project", [name])
72
72
 
73
73
  FileUtils.cd(name)
74
- if options[:withoutgit]
75
- Mortar::Command::run("projects:register", [name, "--withoutgit"])
74
+ if options[:embedded]
75
+ Mortar::Command::run("projects:register", [name, "--embedded"])
76
76
  else
77
77
  git.git_init
78
78
  git.git("add .")
@@ -87,7 +87,7 @@ class Mortar::Command::Projects < Mortar::Command::Base
87
87
  #
88
88
  # Used when you want to start a new Mortar project using your existing code in the current directory.
89
89
  #
90
- # --withoutgit # Register code that is not its own git repo as a Mortar project. Your code will still be synced with a git repo in the cloud.
90
+ # --embedded # Register code that is not its own git repo as a Mortar project. Your code will still be synced with a git repo in the cloud.
91
91
  #
92
92
  def register
93
93
  name = shift_argument
@@ -96,12 +96,12 @@ class Mortar::Command::Projects < Mortar::Command::Base
96
96
  end
97
97
  validate_arguments!
98
98
 
99
- if options[:withoutgit]
99
+ if options[:embedded]
100
100
  validate_project_name(name)
101
101
  validate_project_structure()
102
102
 
103
103
  register_project(name) do |project_result|
104
- initialize_gitless_project(project_result)
104
+ initialize_embedded_project(project_result)
105
105
  end
106
106
  else
107
107
  unless git.has_dot_git?
@@ -109,7 +109,7 @@ class Mortar::Command::Projects < Mortar::Command::Base
109
109
  if File.exists? name
110
110
  error("mortar projects:register must be run from within the project directory.\nPlease \"cd #{name}\" and rerun this command.")
111
111
  else
112
- error("No git repository found in the current directory.\nTo register a project that is not its own git repository, use the --withoutgit option.\nIf you do want this project to be its own git repository, please initialize git in this directory, and then rerun the register command.\nTo initialize your project in git, use:\n\ngit init\ngit add .\ngit commit -a -m \"first commit\"")
112
+ error("No git repository found in the current directory.\nTo register a project that is not its own git repository, use the --embedded option.\nIf you do want this project to be its own git repository, please initialize git in this directory, and then rerun the register command.\nTo initialize your project in git, use:\n\ngit init\ngit add .\ngit commit -a -m \"first commit\"")
113
113
  end
114
114
  end
115
115
 
@@ -139,7 +139,7 @@ class Mortar::Command::Projects < Mortar::Command::Base
139
139
  # co-worker creates a Mortar project from an internal repository you would clone the internal
140
140
  # repository and then after cloning call mortar projects:set_remote.
141
141
  #
142
- # --withoutgit # make this a gitless project tied to the specified remote
142
+ # --embedded # make this a embedded project tied to the specified remote
143
143
  #
144
144
  def set_remote
145
145
  project_name = shift_argument
@@ -148,7 +148,7 @@ class Mortar::Command::Projects < Mortar::Command::Base
148
148
  error("Usage: mortar projects:set_remote PROJECT\nMust specify PROJECT.")
149
149
  end
150
150
 
151
- unless options[:withoutgit]
151
+ unless options[:embedded]
152
152
  unless git.has_dot_git?
153
153
  error("Can only set the remote for an existing git project. Please run:\n\ngit init\ngit add .\ngit commit -a -m \"first commit\"\n\nto initialize your project in git.")
154
154
  end
@@ -165,11 +165,11 @@ class Mortar::Command::Projects < Mortar::Command::Base
165
165
  error("No project named: #{project_name} exists. You can create this project using:\n\n mortar projects:create")
166
166
  end
167
167
 
168
- if options[:withoutgit]
168
+ if options[:embedded]
169
169
  File.open(".mortar-project-remote", "w") do |f|
170
170
  f.puts project["git_url"]
171
171
  end
172
- git.sync_gitless_project(project, embedded_project_user_branch)
172
+ git.sync_embedded_project(project, embedded_project_user_branch)
173
173
  else
174
174
  git.remote_add("mortar", project["git_url"])
175
175
  end
data/lib/mortar/git.rb CHANGED
@@ -242,7 +242,7 @@ module Mortar
242
242
  "/tmp/mortar-git-mirrors"
243
243
  end
244
244
 
245
- def sync_gitless_project(project, branch)
245
+ def sync_embedded_project(project, branch)
246
246
  # the project is not a git repo, so we manage a mirror directory that is a git repo
247
247
  # branch is which branch to sync to. this will be master if the cloud repo
248
248
  # is being initialized, or a branch based on the user's name in any other circumstance
@@ -250,15 +250,15 @@ module Mortar
250
250
  project_dir = project.root_path
251
251
  mirror_dir = "#{mortar_mirrors_dir}/#{project.name}"
252
252
 
253
- ensure_gitless_project_mirror_exists(mirror_dir)
254
- sync_gitless_project_with_mirror(mirror_dir, project_dir, branch)
255
- git_ref = sync_gitless_project_mirror_with_cloud(mirror_dir, branch)
253
+ ensure_embedded_project_mirror_exists(mirror_dir)
254
+ sync_embedded_project_with_mirror(mirror_dir, project_dir, branch)
255
+ git_ref = sync_embedded_project_mirror_with_cloud(mirror_dir, branch)
256
256
 
257
257
  Dir.chdir(project_dir)
258
258
  return git_ref
259
259
  end
260
260
 
261
- def ensure_gitless_project_mirror_exists(mirror_dir)
261
+ def ensure_embedded_project_mirror_exists(mirror_dir)
262
262
  # create and initialize mirror git repo if it doesn't already exist
263
263
  unless File.directory? mirror_dir
264
264
  unless File.directory? mortar_mirrors_dir
@@ -275,14 +275,14 @@ module Mortar
275
275
  # initialization is not necessary if this is not the first user to use it
276
276
  File.open(".gitkeep", "w").close()
277
277
  git("add .")
278
- git("commit -m \"Setting up gitless Mortar project\"")
278
+ git("commit -m \"Setting up embedded Mortar project\"")
279
279
  git("remote add mortar #{remote_path}")
280
- push_with_retry("mortar", "master", "Setting up gitless Mortar project")
280
+ push_with_retry("mortar", "master", "Setting up embedded Mortar project")
281
281
  end
282
282
  end
283
283
  end
284
284
 
285
- def sync_gitless_project_with_mirror(mirror_dir, project_dir, branch)
285
+ def sync_embedded_project_with_mirror(mirror_dir, project_dir, branch)
286
286
  # pull from remote branch and overwrite everything, if it exists.
287
287
  # if it doesn't exist, create it.
288
288
  Dir.chdir(mirror_dir)
@@ -315,7 +315,7 @@ module Mortar
315
315
  end
316
316
  end
317
317
 
318
- def sync_gitless_project_mirror_with_cloud(mirror_dir, branch)
318
+ def sync_embedded_project_mirror_with_cloud(mirror_dir, branch)
319
319
  # checkout snapshot branch.
320
320
  # it will permenantly keep the code in this state (as opposed to the user's base branch, which will be updated)
321
321
  Dir.chdir(mirror_dir)
@@ -83,7 +83,7 @@ module Mortar
83
83
  path = File.join(@root_path, "fixtures")
84
84
  end
85
85
 
86
- def gitless_project?()
86
+ def embedded_project?()
87
87
  File.exists?(File.join(@root_path, ".mortar-project-remote"))
88
88
  end
89
89
  end
@@ -16,5 +16,5 @@
16
16
 
17
17
  module Mortar
18
18
  # see http://semver.org/
19
- VERSION = "0.8.3"
19
+ VERSION = "0.8.4"
20
20
  end
@@ -170,5 +170,18 @@ module Mortar
170
170
  expect(@cli.has_credentials).to be_false
171
171
  end
172
172
 
173
+ it "uses path from env when specified" do
174
+ netrc_path = '/foo/bar/baz'
175
+ ENV['MORTAR_LOGIN_FILE'] = netrc_path
176
+ expect(@cli.netrc_path).to eq(netrc_path)
177
+ ENV.delete('MORTAR_LOGIN_FILE')
178
+ end
179
+
180
+ it "uses the default path when no environment setting" do
181
+ FakeFS do
182
+ expect(@cli.netrc_path).to eq(Netrc.default_path)
183
+ end
184
+ end
185
+
173
186
  end
174
187
  end
@@ -189,8 +189,8 @@ STDERR
189
189
  end
190
190
  end
191
191
 
192
- it "requests and reports a describe for a gitless project" do
193
- with_gitless_project do |p|
192
+ it "requests and reports a describe for an embedded project" do
193
+ with_embedded_project do |p|
194
194
  # stub api requests
195
195
  describe_id = "c571a8c7f76a4fd4a67c103d753e2dd5"
196
196
  describe_url = "https://api.mortardata.com/describe/#{describe_id}"
@@ -202,7 +202,7 @@ STDERR
202
202
  mock(Mortar::Auth.api).get_describe(describe_id, :exclude_result => true).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Describe::STATUS_PROGRESS, "status_description" => "Starting pig"})).ordered
203
203
  mock(Mortar::Auth.api).get_describe(describe_id, :exclude_result => true).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Describe::STATUS_SUCCESS, "status_description" => "Success", "web_result_url" => describe_url})).ordered
204
204
 
205
- mock(@git).sync_gitless_project.with_any_args.times(1) { "somewhere_over_the_rainbow" }
205
+ mock(@git).sync_embedded_project.with_any_args.times(1) { "somewhere_over_the_rainbow" }
206
206
 
207
207
  # stub launchy
208
208
  mock(Launchy).open(describe_url) {Thread.new {}}
@@ -258,8 +258,8 @@ STDERR
258
258
  end
259
259
  end
260
260
 
261
- it "requests and reports an illustrate for a gitless project" do
262
- with_gitless_project do |p|
261
+ it "requests and reports an illustrate for an embedded project" do
262
+ with_embedded_project do |p|
263
263
  # stub api requests
264
264
  illustrate_id = "c571a8c7f76a4fd4a67c103d753e2dd5"
265
265
  illustrate_url = "https://api.mortardata.com/illustrates/#{illustrate_id}"
@@ -274,7 +274,7 @@ STDERR
274
274
  mock(Mortar::Auth.api).get_illustrate(illustrate_id, :exclude_result => true).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Illustrate::STATUS_PRUNING_DATA, "status_description" => "Pruning data"})).ordered
275
275
  mock(Mortar::Auth.api).get_illustrate(illustrate_id, :exclude_result => true).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Illustrate::STATUS_SUCCESS, "status_description" => "Succeeded", "web_result_url" => illustrate_url})).ordered
276
276
 
277
- mock(@git).sync_gitless_project.with_any_args.times(1) { "somewhere_over_the_rainbow" }
277
+ mock(@git).sync_embedded_project.with_any_args.times(1) { "somewhere_over_the_rainbow" }
278
278
 
279
279
  # stub launchy
280
280
  mock(Launchy).open(illustrate_url) {Thread.new {}}
@@ -456,14 +456,14 @@ STDERR
456
456
  end
457
457
  end
458
458
 
459
- it "runs a job for a gitless project" do
460
- with_gitless_project do |p|
459
+ it "runs a job for an embedded project" do
460
+ with_embedded_project do |p|
461
461
  # stub api requests
462
462
  job_id = "c571a8c7f76a4fd4a67c103d753e2dd5"
463
463
  job_url = "http://127.0.0.1:5000/jobs/job_detail?job_id=c571a8c7f76a4fd4a67c103d753e2dd5"
464
464
  cluster_size = 5
465
465
 
466
- mock(@git).sync_gitless_project.with_any_args.times(1) { "somewhere_over_the_rainbow" }
466
+ mock(@git).sync_embedded_project.with_any_args.times(1) { "somewhere_over_the_rainbow" }
467
467
 
468
468
  mock(Mortar::Auth.api).post_job_new_cluster("myproject", "my_script", is_a(String), cluster_size,
469
469
  :parameters => match_array([{"name" => "FIRST_PARAM", "value" => "FOO"}, {"name" => "SECOND_PARAM", "value" => "BAR"}]),
@@ -143,7 +143,7 @@ NOTE: You'll need to change to the new directory to use your project:
143
143
  STDOUT
144
144
  end
145
145
 
146
- it "generates and registers a gitless project" do
146
+ it "generates and registers an embedded project" do
147
147
  mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
148
148
  project_id = "1234abcd1234abcd1234"
149
149
  project_name = "some_new_project"
@@ -152,10 +152,10 @@ STDOUT
152
152
  mock(Mortar::Auth.api).get_project(project_id).returns(Excon::Response.new(:body => {"status" => Mortar::API::Projects::STATUS_ACTIVE,
153
153
  "git_url" => project_git_url})).ordered
154
154
 
155
- # test that sync_gitless_project is called. the method itself is tested in git_spec.
156
- mock(@git).sync_gitless_project.with_any_args.times(1) { true }
155
+ # test that sync_embedded_project is called. the method itself is tested in git_spec.
156
+ mock(@git).sync_embedded_project.with_any_args.times(1) { true }
157
157
 
158
- stderr, stdout = execute("projects:create #{project_name} --withoutgit", nil, @git)
158
+ stderr, stdout = execute("projects:create #{project_name} --embedded", nil, @git)
159
159
  Dir.pwd.end_with?("some_new_project").should be_true
160
160
  File.exists?(".mortar-project-remote").should be_true
161
161
  File.exists?("macros").should be_true
@@ -202,7 +202,7 @@ STDERR
202
202
  stderr, stdout = execute("projects:register some_new_project")
203
203
  stderr.should == <<-STDERR
204
204
  ! No git repository found in the current directory.
205
- ! To register a project that is not its own git repository, use the --withoutgit option.
205
+ ! To register a project that is not its own git repository, use the --embedded option.
206
206
  ! If you do want this project to be its own git repository, please initialize git in this directory, and then rerun the register command.
207
207
  ! To initialize your project in git, use:
208
208
  !
@@ -280,7 +280,7 @@ Sending request to register project: some_new_project... done\n\n\r\e[0KStatus:
280
280
  STDOUT
281
281
  end
282
282
 
283
- it "registers a gitless project" do
283
+ it "registers an embedded project" do
284
284
  mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
285
285
  project_id = "1234abcd1234abcd1234"
286
286
  project_name = "some_new_project"
@@ -296,10 +296,10 @@ STDOUT
296
296
  mock(obj).validate_project_structure.returns(true)
297
297
  end
298
298
 
299
- # test that sync_gitless_project is called. the method itself is tested in git_spec.
300
- mock(@git).sync_gitless_project.with_any_args.times(1) { true }
299
+ # test that sync_embedded_project is called. the method itself is tested in git_spec.
300
+ mock(@git).sync_embedded_project.with_any_args.times(1) { true }
301
301
 
302
- stderr, stdout = execute("projects:register some_new_project --withoutgit --polling_interval 0.05", nil, @git)
302
+ stderr, stdout = execute("projects:register some_new_project --embedded --polling_interval 0.05", nil, @git)
303
303
  end
304
304
 
305
305
  end
@@ -129,8 +129,8 @@ STDERR
129
129
  end
130
130
  end
131
131
 
132
- it "requests and reports a validate for a gitless project" do
133
- with_gitless_project do |p|
132
+ it "requests and reports a validate for an embedded project" do
133
+ with_embedded_project do |p|
134
134
  # stub api requests
135
135
  validate_id = "c571a8c7f76a4fd4a67c103d753e2dd5"
136
136
  parameters = ["name"=>"key", "value"=>"value" ]
@@ -141,7 +141,7 @@ STDERR
141
141
  mock(Mortar::Auth.api).get_validate(validate_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Validate::STATUS_PROGRESS, "status_description" => "Starting"})).ordered
142
142
  mock(Mortar::Auth.api).get_validate(validate_id).returns(Excon::Response.new(:body => {"status_code" => Mortar::API::Validate::STATUS_SUCCESS, "status_description" => "Success"})).ordered
143
143
 
144
- mock(@git).sync_gitless_project.with_any_args.times(1) { "somewhere_over_the_rainbow" }
144
+ mock(@git).sync_embedded_project.with_any_args.times(1) { "somewhere_over_the_rainbow" }
145
145
 
146
146
  write_file(File.join(p.pigscripts_path, "my_script.pig"))
147
147
  stderr, stdout = execute("validate my_script --polling_interval 0.05 -p key=value", p, @git)
@@ -304,10 +304,10 @@ STASH
304
304
 
305
305
  # we manually create and destroy "mirror_dir" instead of using FakeFS
306
306
  # because FakeFS doesn't clean up properly when you use Dir.chdir inside of it
307
- context "snapshot with gitless project" do
307
+ context "snapshot with embedded project" do
308
308
 
309
309
  it "creates a mirror directory for the project when one does not already exist" do
310
- with_gitless_project do |p|
310
+ with_embedded_project do |p|
311
311
  mirror_dir = File.join(Dir.tmpdir, "mortar", "test-git-mirror")
312
312
  mock(@git).mortar_mirrors_dir.any_times { mirror_dir }
313
313
 
@@ -316,7 +316,7 @@ STASH
316
316
  mock(@git).push_with_retry.with_any_args.times(2) { true }
317
317
  mock(@git).is_clean_working_directory? { false }
318
318
 
319
- @git.sync_gitless_project(p, "master")
319
+ @git.sync_embedded_project(p, "master")
320
320
 
321
321
  File.directory?(mirror_dir).should be_true
322
322
  FileUtils.rm_rf(mirror_dir)
@@ -324,7 +324,7 @@ STASH
324
324
  end
325
325
 
326
326
  it "syncs files to the project mirror" do
327
- with_gitless_project do |p|
327
+ with_embedded_project do |p|
328
328
  mirror_dir = File.join(Dir.tmpdir, "mortar", "test-git-mirror")
329
329
  mock(@git).mortar_mirrors_dir.any_times { mirror_dir }
330
330
 
@@ -337,7 +337,7 @@ STASH
337
337
  mock(@git).push_with_retry.with_any_args.times(1) { true }
338
338
  mock(@git).is_clean_working_directory? { false }
339
339
 
340
- @git.sync_gitless_project(p, "bob-the-builder-base")
340
+ @git.sync_embedded_project(p, "bob-the-builder-base")
341
341
 
342
342
  File.exists?("#{project_mirror_dir}/pigscripts/calydonian_boar.pig").should be_true
343
343
  FileUtils.rm_rf(mirror_dir)
@@ -345,7 +345,7 @@ STASH
345
345
  end
346
346
 
347
347
  it "syncs deleted files to the project mirror" do
348
- with_gitless_project do |p|
348
+ with_embedded_project do |p|
349
349
  mirror_dir = File.join(Dir.tmpdir, "mortar", "test-git-mirror")
350
350
  mock(@git).mortar_mirrors_dir.any_times { mirror_dir }
351
351
 
@@ -359,7 +359,7 @@ STASH
359
359
  mock(@git).push_with_retry.with_any_args.times(1) { true }
360
360
  mock(@git).is_clean_working_directory? { false }
361
361
 
362
- @git.sync_gitless_project(p, "bob-the-builder-base")
362
+ @git.sync_embedded_project(p, "bob-the-builder-base")
363
363
 
364
364
  File.exists?("#{project_mirror_dir}/pigscripts/calydonian_boar.pig").should be_false
365
365
  FileUtils.rm_rf(mirror_dir)
data/spec/spec_helper.rb CHANGED
@@ -208,7 +208,7 @@ def with_git_initialized_project(&block)
208
208
  with_blank_project(&commit_proc)
209
209
  end
210
210
 
211
- def with_gitless_project(&block)
211
+ def with_embedded_project(&block)
212
212
  with_blank_project do |project|
213
213
  File.open(File.join(project.root_path, ".mortar-project-remote"), "w") do |f|
214
214
  f.puts "git@github.com:mortarcode-dev/4dbbd83cae8d5bf8a4000000_#{project.name}.git"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mortar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mortar-api-ruby
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  version: '0'
271
271
  requirements: []
272
272
  rubyforge_project:
273
- rubygems_version: 1.8.25
273
+ rubygems_version: 1.8.23
274
274
  signing_key:
275
275
  specification_version: 3
276
276
  summary: Client library and CLI to interact with the Mortar service.