mortar 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -164,7 +164,7 @@ class Mortar::Command::Base
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)
167
+ git.sync_gitless_project(project, "master")
168
168
  end
169
169
 
170
170
  protected
@@ -400,13 +400,17 @@ protected
400
400
  def sync_code_with_cloud
401
401
  # returns git_ref
402
402
  if project.gitless_project?
403
- return git.sync_gitless_project(project)
403
+ return git.sync_gitless_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)
407
407
  end
408
408
  end
409
409
 
410
+ def embedded_project_user_branch
411
+ return Mortar::Auth.user_s3_safe + "-base"
412
+ end
413
+
410
414
  end
411
415
 
412
416
  module Mortar::Command
@@ -138,6 +138,9 @@ class Mortar::Command::Projects < Mortar::Command::Base
138
138
  # Adds a remote to your local git repository to the Mortar git repository. For example if a
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
+ #
142
+ # --withoutgit # make this a gitless project tied to the specified remote
143
+ #
141
144
  def set_remote
142
145
  project_name = shift_argument
143
146
 
@@ -145,13 +148,15 @@ class Mortar::Command::Projects < Mortar::Command::Base
145
148
  error("Usage: mortar projects:set_remote PROJECT\nMust specify PROJECT.")
146
149
  end
147
150
 
148
- unless git.has_dot_git?
149
- 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.")
150
- end
151
+ unless options[:withoutgit]
152
+ unless git.has_dot_git?
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
+ end
151
155
 
152
- if git.remotes(git_organization).include?("mortar")
153
- display("The remote has already been set for project: #{project_name}")
154
- return
156
+ if git.remotes(git_organization).include?("mortar")
157
+ display("The remote has already been set for project: #{project_name}")
158
+ return
159
+ end
155
160
  end
156
161
 
157
162
  projects = api.get_projects().body["projects"]
@@ -160,7 +165,15 @@ class Mortar::Command::Projects < Mortar::Command::Base
160
165
  error("No project named: #{project_name} exists. You can create this project using:\n\n mortar projects:create")
161
166
  end
162
167
 
163
- git.remote_add("mortar", project['git_url'])
168
+ if options[:withoutgit]
169
+ File.open(".mortar-project-remote", "w") do |f|
170
+ f.puts project["git_url"]
171
+ end
172
+ git.sync_gitless_project(project, embedded_project_user_branch)
173
+ else
174
+ git.remote_add("mortar", project["git_url"])
175
+ end
176
+
164
177
  display("Successfully added the mortar remote to the #{project_name} project")
165
178
 
166
179
  end
data/lib/mortar/git.rb CHANGED
@@ -242,21 +242,23 @@ module Mortar
242
242
  "/tmp/mortar-git-mirrors"
243
243
  end
244
244
 
245
- def sync_gitless_project(project)
245
+ def sync_gitless_project(project, branch)
246
246
  # the project is not a git repo, so we manage a mirror directory that is a git repo
247
+ # branch is which branch to sync to. this will be master if the cloud repo
248
+ # is being initialized, or a branch based on the user's name in any other circumstance
247
249
 
248
250
  project_dir = project.root_path
249
251
  mirror_dir = "#{mortar_mirrors_dir}/#{project.name}"
250
252
 
251
- ensure_gitless_project_mirror_exists(project_dir, mirror_dir)
252
- sync_gitless_project_with_mirror(project_dir, mirror_dir)
253
- git_ref = sync_gitless_project_mirror_with_cloud(project_dir, mirror_dir)
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)
254
256
 
255
257
  Dir.chdir(project_dir)
256
258
  return git_ref
257
259
  end
258
260
 
259
- def ensure_gitless_project_mirror_exists(project_dir, mirror_dir)
261
+ def ensure_gitless_project_mirror_exists(mirror_dir)
260
262
  # create and initialize mirror git repo if it doesn't already exist
261
263
  unless File.directory? mirror_dir
262
264
  unless File.directory? mortar_mirrors_dir
@@ -267,21 +269,35 @@ module Mortar
267
269
  remote_path = File.open(".mortar-project-remote").read.strip
268
270
  clone(remote_path, mirror_dir)
269
271
 
270
- # make an initial commit to master
272
+ # make an initial commit to the specified branch
271
273
  Dir.chdir(mirror_dir)
272
- File.open(".gitkeep", "w").close()
273
- git("add .")
274
- git("commit -m \"mortar development initial commit\"")
275
- git("remote add mortar #{remote_path}")
276
- push_with_retry("mortar", "master", "Setting up gitless Mortar project")
274
+ unless File.exists? ".gitkeep" # flag that signals that the repo has been initialized
275
+ # initialization is not necessary if this is not the first user to use it
276
+ File.open(".gitkeep", "w").close()
277
+ git("add .")
278
+ git("commit -m \"Setting up gitless Mortar project\"")
279
+ git("remote add mortar #{remote_path}")
280
+ push_with_retry("mortar", "master", "Setting up gitless Mortar project")
281
+ end
277
282
  end
278
283
  end
279
284
 
280
- def sync_gitless_project_with_mirror(project_dir, mirror_dir)
281
- # pull from master and overwrite everything
285
+ def sync_gitless_project_with_mirror(mirror_dir, project_dir, branch)
286
+ # pull from remote branch and overwrite everything, if it exists.
287
+ # if it doesn't exist, create it.
282
288
  Dir.chdir(mirror_dir)
289
+ git("reset --hard HEAD")
283
290
  git("fetch --all")
284
- git("reset --hard mortar/master")
291
+ begin
292
+ git("checkout #{branch}")
293
+ rescue Exception => e
294
+ err_msg = e.to_s
295
+ if err_msg.include?("error: pathspec") and err_msg.include?("did not match any file(s) known to git")
296
+ git("checkout -b #{branch}")
297
+ else
298
+ raise e
299
+ end
300
+ end
285
301
 
286
302
  # wipe mirror dir and copy project files into it
287
303
  # since we fetched mortar/master earlier, the git diff will now be b/tw master and the current state
@@ -290,7 +306,7 @@ module Mortar
290
306
  Dir.chdir(project_dir)
291
307
  FileUtils.cp_r(mortar_manifest_pathlist(false), mirror_dir)
292
308
 
293
- # update master
309
+ # update remote branch
294
310
  Dir.chdir(mirror_dir)
295
311
  unless is_clean_working_directory?
296
312
  git("add .")
@@ -299,17 +315,17 @@ module Mortar
299
315
  end
300
316
  end
301
317
 
302
- def sync_gitless_project_mirror_with_cloud(project_dir, mirror_dir)
318
+ def sync_gitless_project_mirror_with_cloud(mirror_dir, branch)
303
319
  # checkout snapshot branch.
304
- # it will permenantly keep the code in this state (as opposed to master, which will be updated)
320
+ # it will permenantly keep the code in this state (as opposed to the user's base branch, which will be updated)
305
321
  Dir.chdir(mirror_dir)
306
322
  snapshot_branch = "mortar-snapshot-#{Mortar::UUID.create_random.to_s}"
307
323
  git("checkout -b #{snapshot_branch}")
308
324
 
309
- # push everything (master updates and snapshot branch)
325
+ # push everything (use base branch updates and snapshot branch)
310
326
  git_ref = push_with_retry("mortar", snapshot_branch, "Sending code snapshot to Mortar", true)
311
327
 
312
- git("checkout master")
328
+ git("checkout #{branch}")
313
329
  return git_ref
314
330
  end
315
331
 
@@ -16,5 +16,5 @@
16
16
 
17
17
  module Mortar
18
18
  # see http://semver.org/
19
- VERSION = "0.8.2"
19
+ VERSION = "0.8.3"
20
20
  end
@@ -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)
319
+ @git.sync_gitless_project(p, "master")
320
320
 
321
321
  File.directory?(mirror_dir).should be_true
322
322
  FileUtils.rm_rf(mirror_dir)
@@ -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)
340
+ @git.sync_gitless_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)
@@ -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)
362
+ @git.sync_gitless_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)
metadata CHANGED
@@ -1,164 +1,167 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mortar
3
- version: !ruby/object:Gem::Version
4
- hash: 59
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 8
9
- - 2
10
- version: 0.8.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Mortar Data
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-05-30 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: mortar-api-ruby
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 1
29
- segments:
30
- - 0
31
- - 6
32
- - 3
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.6.3
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: netrc
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
40
25
  none: false
41
- requirements:
26
+ requirements:
42
27
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 5
45
- segments:
46
- - 0
47
- - 7
48
- version: "0.7"
28
+ - !ruby/object:Gem::Version
29
+ version: 0.6.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: netrc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.7'
49
38
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: launchy
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
55
41
  none: false
56
- requirements:
42
+ requirements:
57
43
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 1
60
- segments:
61
- - 2
62
- - 1
63
- version: "2.1"
44
+ - !ruby/object:Gem::Version
45
+ version: '0.7'
46
+ - !ruby/object:Gem::Dependency
47
+ name: launchy
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.1'
64
54
  type: :runtime
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: excon
68
55
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ - !ruby/object:Gem::Dependency
63
+ name: excon
64
+ requirement: !ruby/object:Gem::Requirement
70
65
  none: false
71
- requirements:
66
+ requirements:
72
67
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 21
75
- segments:
76
- - 0
77
- - 15
78
- version: "0.15"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.15'
79
70
  type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
- name: fakefs
83
71
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.15'
78
+ - !ruby/object:Gem::Dependency
79
+ name: fakefs
80
+ requirement: !ruby/object:Gem::Requirement
85
81
  none: false
86
- requirements:
82
+ requirements:
87
83
  - - ~>
88
- - !ruby/object:Gem::Version
89
- hash: 11
90
- segments:
91
- - 0
92
- - 4
93
- - 2
84
+ - !ruby/object:Gem::Version
94
85
  version: 0.4.2
95
86
  type: :development
96
- version_requirements: *id005
97
- - !ruby/object:Gem::Dependency
98
- name: gem-release
99
87
  prerelease: false
100
- requirement: &id006 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
101
89
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
- version: "0"
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.4.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: gem-release
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
109
102
  type: :development
110
- version_requirements: *id006
111
- - !ruby/object:Gem::Dependency
112
- name: rake
113
103
  prerelease: false
114
- requirement: &id007 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rake
112
+ requirement: !ruby/object:Gem::Requirement
115
113
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
123
118
  type: :development
124
- version_requirements: *id007
125
- - !ruby/object:Gem::Dependency
126
- name: rr
127
119
  prerelease: false
128
- requirement: &id008 !ruby/object:Gem::Requirement
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rr
128
+ requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- hash: 3
134
- segments:
135
- - 0
136
- version: "0"
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
137
134
  type: :development
138
- version_requirements: *id008
139
- - !ruby/object:Gem::Dependency
140
- name: rspec
141
135
  prerelease: false
142
- requirement: &id009 !ruby/object:Gem::Requirement
136
+ version_requirements: !ruby/object:Gem::Requirement
143
137
  none: false
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- hash: 3
148
- segments:
149
- - 0
150
- version: "0"
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rspec
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
151
150
  type: :development
152
- version_requirements: *id009
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
153
158
  description: Client library and command-line tool to interact with the Mortar service.
154
159
  email: support@mortardata.com
155
- executables:
160
+ executables:
156
161
  - mortar
157
162
  extensions: []
158
-
159
163
  extra_rdoc_files: []
160
-
161
- files:
164
+ files:
162
165
  - README.md
163
166
  - bin/mortar
164
167
  - css/illustrate.css
@@ -249,38 +252,26 @@ files:
249
252
  - spec/support/display_message_matcher.rb
250
253
  homepage: http://mortardata.com/
251
254
  licenses: []
252
-
253
255
  post_install_message:
254
256
  rdoc_options: []
255
-
256
- require_paths:
257
+ require_paths:
257
258
  - lib
258
- required_ruby_version: !ruby/object:Gem::Requirement
259
+ required_ruby_version: !ruby/object:Gem::Requirement
259
260
  none: false
260
- requirements:
261
- - - ">="
262
- - !ruby/object:Gem::Version
263
- hash: 57
264
- segments:
265
- - 1
266
- - 8
267
- - 7
261
+ requirements:
262
+ - - ! '>='
263
+ - !ruby/object:Gem::Version
268
264
  version: 1.8.7
269
- required_rubygems_version: !ruby/object:Gem::Requirement
265
+ required_rubygems_version: !ruby/object:Gem::Requirement
270
266
  none: false
271
- requirements:
272
- - - ">="
273
- - !ruby/object:Gem::Version
274
- hash: 3
275
- segments:
276
- - 0
277
- version: "0"
267
+ requirements:
268
+ - - ! '>='
269
+ - !ruby/object:Gem::Version
270
+ version: '0'
278
271
  requirements: []
279
-
280
272
  rubyforge_project:
281
- rubygems_version: 1.8.24
273
+ rubygems_version: 1.8.25
282
274
  signing_key:
283
275
  specification_version: 3
284
276
  summary: Client library and CLI to interact with the Mortar service.
285
277
  test_files: []
286
-