gitdocs 0.5.0.pre5 → 0.5.0.pre6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzYxMWM5MTg3ZWYzMzllZDNhY2NiNDdlNTA2NmNmMWEyNTVjMzFkNQ==
4
+ ZGUwYWI0Y2RjMTNjZGU4YzMzMzkxMTcxOTQ3OGQ2YWY0ZGNmZjg3MA==
5
5
  data.tar.gz: !binary |-
6
- Njc0MTAxYjFlODI1ZjE5NjdmZGE0YmNmODc2MmJkMDc4NWQ5MzY5Ng==
6
+ MjZhNjUxNGM4Yjc2Nzk1NWRkYjJiNjNlNzYyNTA3NGEzNjFkMTcyNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDFkODRiMDJjMGU3MWNkZGY4NjdhZWQ4OTM3N2EyNjRiNjM5MjAwYmQ5NWQ1
10
- MTBlZTA5NGFkNWU1ODM2MWJhYmY1NWI0NDg3ZmVhMGI1YTBjODY0MTE1YjQ4
11
- Njc1YjIyN2ZjMjAyN2M3YjZiNWM1OGE2ZDViMmZjOTgxZjkwMTY=
9
+ NWY0NTMyOTQ1NGJhMTg5OTY3OWNhMGE4MzFhYjJjNzA1N2Y4YTgzMWIwMTE4
10
+ NDZkMWIzMzFlYzNhYzc5MjAyMmQ3NGJiMzY3ZDliMzhkMTE5ZWQxNjE3MTk3
11
+ Y2E4YTIzZTU2ODg3N2Y5YjRmNDFiNzM1MzZhMzczN2E4Yzk0ODI=
12
12
  data.tar.gz: !binary |-
13
- NzRjMzZmZDRhZjUzZDAyODNhMzRjNjFmNGRjZmViZmM5OTk1MzkzMWZmYzA2
14
- ODMxMmNiY2U0NTVkOGEwODIyM2UxZTJkMTZiN2I2MWE0YzZkMjNjOTM4Mjkx
15
- YjUzMzNjMTIzZmUzMzIzZGQ1ZDRkYjQ5OTQxODNiNzE0NTgyNzQ=
13
+ ODFiYjQ4ZmI3NWVlNzU5ZWY5NDQ3Mzk4OGRhMGNmMWQ5ZDBjNGNmYjcyYzM2
14
+ N2RhMzZlZDExYzYyOTMyZWE4OWVkYTA1N2Y1NDRiMmFjYTM4YmM3N2QzZWUw
15
+ OTRlZWZkOGJlMDg1MGQ4NGY4OThjOGRhN2Q1MjI5NzAyODcyZjA=
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.5.0.pre6 (May 24th 2014)
2
+
3
+ * Remove the load_browser_on_startup config option (@acant)
4
+ * Stop the addition of extra conflict markers (@acant)
5
+ * Separate the commit and push methods in repository (@acant)
6
+
1
7
  0.5.0.pre5 (May 14th 2014)
2
8
 
3
9
  * Cleanup behavior on empty commits
data/README.md CHANGED
@@ -197,7 +197,7 @@ but provide the features that makes Dropbox great. If you are interested in othe
197
197
  * [git-sync](http://tychoish.com/essay/git-sync/) manual git syncing tool,
198
198
  which also use XMPP notifications
199
199
  * [git-annex-assistant](http://git-annex.branchable.com/design/assistant/)
200
- directory sync tool based on [git-annex](http://git-annex.branchable.com/). (written in Haskel)
200
+ directory sync tool based on [git-annex](http://git-annex.branchable.com/). (written in Haskell)
201
201
  * [BitTorrent Sync](http://www.bittorrent.com/sync) BitTorrent based syncing
202
202
  tool, not open source or publicly defined protocol
203
203
  * [StrongSync](https://secure.expandrive.com/strongsync) Dropbox clone utility,
@@ -21,7 +21,7 @@ module Gitdocs
21
21
  end
22
22
 
23
23
  class Config < ActiveRecord::Base
24
- attr_accessible :load_browser_on_startup, :start_web_frontend, :web_frontend_port
24
+ attr_accessible :start_web_frontend, :web_frontend_port
25
25
  end
26
26
 
27
27
  def add_path(path, opts = nil)
@@ -172,39 +172,46 @@ class Gitdocs::Repository
172
172
  @rugged.index.reload
173
173
  return e.err unless @rugged.index.conflicts?
174
174
 
175
- conflicted_paths = @rugged.index.map do |index_entry|
176
- filename, extension = index_entry[:path].scan(/(.*?)(|\.[^\.]+)$/).first
177
-
178
- author = ' original' if index_entry[:stage] == 1
179
- short_oid = index_entry[:oid][0..6]
180
- new_filename = "#{filename} (#{short_oid}#{author})#{extension}"
181
- File.open(File.join(root, new_filename), 'wb') do |f|
182
- f.write(Rugged::Blob.lookup(@rugged, index_entry[:oid]).content)
175
+ # Collect all the index entries by their paths.
176
+ index_path_entries = Hash.new { |h, k| h[k] = Array.new }
177
+ @rugged.index.map do |index_entry|
178
+ index_path_entries[index_entry[:path]].push(index_entry)
179
+ end
180
+
181
+ # Filter to only the conflicted entries.
182
+ conflicted_path_entries = index_path_entries.delete_if { |_k, v| v.length == 1 }
183
+
184
+ conflicted_path_entries.each_pair do |path, index_entries|
185
+ # Write out the different versions of the conflicted file.
186
+ index_entries.each do |index_entry|
187
+ filename, extension = index_entry[:path].scan(/(.*?)(|\.[^\.]+)$/).first
188
+ author = ' original' if index_entry[:stage] == 1
189
+ short_oid = index_entry[:oid][0..6]
190
+ new_filename = "#{filename} (#{short_oid}#{author})#{extension}"
191
+ File.open(File.join(root, new_filename), 'wb') do |f|
192
+ f.write(Rugged::Blob.lookup(@rugged, index_entry[:oid]).content)
193
+ end
183
194
  end
184
195
 
185
- index_entry[:path]
196
+ # And remove the original.
197
+ FileUtils.remove(File.join(root, path), force: true)
186
198
  end
187
199
 
188
- conflicted_paths.uniq!
189
- conflicted_paths.each { |path| FileUtils.remove(File.join(root, path), force: true) }
190
-
191
- # NOTE: leave the commit until the next push
200
+ # NOTE: Let commit be handled by the next regular commit.
192
201
 
193
- conflicted_paths
202
+ conflicted_path_entries.keys
194
203
  end
195
204
 
196
- # Commit and push the repository
205
+ # Commit the working directory
206
+ #
207
+ # @param [String] message
197
208
  #
198
209
  # @return [nil] if the repository is invalid
199
- # @return [:no_remote] if the remote is not yet set
200
- # @return [:nothing] if there was nothing to do
201
- # @return [String] if there is an error return the message
202
- # @return [:ok] if commited and pushed without errors or conflicts
203
- def push(last_synced_oid, message='Auto-commit from gitdocs')
210
+ # @return [Boolean] whether a commit was made or not
211
+ def commit(message)
204
212
  return nil unless valid?
205
- return :no_remote unless has_remote?
206
213
 
207
- #add and commit
214
+ # Mark any empty directories so they will be committed
208
215
  Find.find(root).each do |path|
209
216
  Find.prune if File.basename(path) == '.git'
210
217
  if File.directory?(path) && Dir.entries(path).count == 2
@@ -228,16 +235,30 @@ class Gitdocs::Repository
228
235
  end
229
236
  @rugged.index.write
230
237
  @grit.commit_index(message)
238
+ true
239
+ else
240
+ false
231
241
  end
242
+ end
243
+
244
+ # Push the repository
245
+ #
246
+ # @return [nil] if the repository is invalid
247
+ # @return [:no_remote] if the remote is not yet set
248
+ # @return [:nothing] if there was nothing to do
249
+ # @return [String] if there is an error return the message
250
+ # @return [:ok] if committed and pushed without errors or conflicts
251
+ def push
252
+ return nil unless valid?
253
+ return :no_remote unless has_remote?
232
254
 
233
255
  return :nothing if current_oid.nil?
234
256
 
235
- if last_synced_oid.nil? || remote_branch.nil? || remote_branch.tip.oid != current_oid
257
+ if remote_branch.nil? || remote_branch.tip.oid != current_oid
236
258
  begin
237
259
  @grit.git.push({ raise: true }, @remote_name, @branch_name)
238
260
  :ok
239
261
  rescue Grit::Git::CommandFailed => e
240
- return :nothing if last_synced_oid.nil?
241
262
  return :conflict if e.err[/\[rejected\]/]
242
263
  e.err # return the output on error
243
264
  end
@@ -102,7 +102,8 @@ module Gitdocs
102
102
  message = 'Auto-commit from gitdocs'
103
103
  end
104
104
 
105
- result = @repository.push(@last_synced_revision, message)
105
+ @repository.commit(message)
106
+ result = @repository.push
106
107
 
107
108
  return if result.nil? || result == :no_remote || result == :nothing
108
109
  level, title, message = case result
@@ -1,3 +1,3 @@
1
1
  module Gitdocs
2
- VERSION = '0.5.0.pre5'
2
+ VERSION = '0.5.0.pre6'
3
3
  end
@@ -8,11 +8,6 @@
8
8
  %dt Web Frontend Port
9
9
  %dd
10
10
  %input{:type =>'input', :name=>"config[web_frontend_port]", :value => conf.global.web_frontend_port }
11
- %p
12
- %input{:type =>'hidden', :value => '0', :name=>"config[load_browser_on_startup]"}
13
- %input{:type =>'checkbox', :value => '1', :name=>"config[load_browser_on_startup]", :checked => conf.global.load_browser_on_startup ? 'checked' : nil}
14
- %span Open browser on startup?
15
-
16
11
  %h2 Shares
17
12
  - conf.shares.each_with_index do |share, idx|
18
13
  %div{:id => "share-#{idx}", :class => "share #{idx % 2 == 0 ? 'even' : 'odd'}"}
@@ -9,7 +9,6 @@ describe 'fully synchronizing repositories' do
9
9
  configuration.shares.each do |share|
10
10
  share.update_attributes(polling_interval: 0.1, notification: false)
11
11
  end
12
- configuration.global.update_attributes(load_browser_on_startup: false)
13
12
 
14
13
  start_cmd = 'gitdocs start --debug --pid=gitdocs.pid --port 7777'
15
14
  run(start_cmd, 15)
@@ -276,6 +276,31 @@ describe Gitdocs::Repository do
276
276
  it { subject ; local_file_content('file1 (7bfce5c)').must_equal 'dead' }
277
277
  end
278
278
 
279
+ describe 'when there is a conflict, with additional files' do
280
+ before do
281
+ bare_commit(
282
+ remote_repo,
283
+ 'file1', 'dead',
284
+ 'second commit',
285
+ 'author@example.com', 'A U Thor'
286
+ )
287
+ bare_commit(
288
+ remote_repo,
289
+ 'file2', 'foo',
290
+ 'second commit',
291
+ 'author@example.com', 'A U Thor'
292
+ )
293
+ write_and_commit('file1', 'beef', 'conflict commit', author1)
294
+ end
295
+
296
+ it { subject.must_equal ['file1'] }
297
+ it { subject ; commit_count(local_repo).must_equal 2 }
298
+ it { subject ; local_file_count.must_equal 3 }
299
+ it { subject ; local_file_content('file1 (f6ea049 original)').must_equal 'foobar' }
300
+ it { subject ; local_file_content('file1 (18ed963)').must_equal 'beef' }
301
+ it { subject ; local_file_content('file2').must_equal 'foo' }
302
+ end
303
+
279
304
  describe 'when there is a non-conflicted local commit' do
280
305
  before { write_and_commit('file1', 'beef', 'conflict commit', author1) }
281
306
  it { subject.must_equal :ok }
@@ -298,8 +323,8 @@ describe Gitdocs::Repository do
298
323
  end
299
324
  end
300
325
 
301
- describe '#push' do
302
- subject { repository.push(last_oid, 'message') }
326
+ describe '#commit' do
327
+ subject { repository.commit('message') }
303
328
 
304
329
  let(:path_or_share) { stub(
305
330
  path: local_repo_path,
@@ -308,244 +333,129 @@ describe Gitdocs::Repository do
308
333
  ) }
309
334
 
310
335
  describe 'when invalid' do
311
- let(:last_oid) { nil }
312
336
  let(:path_or_share) { 'tmp/unit/missing' }
313
337
  it { subject.must_be_nil }
314
338
  end
315
339
 
316
- describe 'when no remote' do
317
- let(:last_oid) { nil }
318
- it { subject.must_equal :no_remote }
319
- end
320
-
321
- describe 'remote exists with no commits' do
322
- before { create_local_repo_with_remote }
323
-
324
- describe 'last sync is nil' do
325
- let(:last_oid) { nil }
326
-
327
- describe 'and there is an error on push' do
328
- # Simulate an error occurring during the push
329
- before do
330
- Grit::Git.any_instance.stubs(:push).raises(
331
- Grit::Git::CommandFailed.new('', 1, '')
332
- )
333
- end
334
- it { subject.must_equal :nothing }
335
- it { subject ; commit_count(local_repo).must_equal 0 }
336
- end
340
+ describe 'no previous commits' do
341
+ describe 'nothing to commit' do
342
+ it { subject.must_equal false }
343
+ end
337
344
 
338
- describe 'and there is a conflicted file to push' do
339
- before do
340
- bare_commit(remote_repo, 'file1', 'dead', 'commit', 'A U Thor', 'author@example.com')
341
- write('file1', 'beef')
342
- end
343
- it { subject ; commit_count(local_repo).must_equal 1 }
344
- it { subject ; commit_count(remote_repo).must_equal 1 }
345
- it { subject.must_equal :nothing }
345
+ describe 'changes to commit' do
346
+ before do
347
+ write('file1', 'foobar')
348
+ mkdir('directory')
346
349
  end
350
+ it { subject.must_equal true }
351
+ it { subject ; local_file_exist?('directory/.gitignore').must_equal true }
352
+ it { subject ; commit_count(local_repo).must_equal 1 }
353
+ it { subject ; head_commit(local_repo).message.must_equal "message\n" }
354
+ it { subject ; local_repo_clean?.must_equal true }
355
+ end
356
+ end
347
357
 
348
- describe 'and there are empty directories to push' do
349
- before do
350
- mkdir('directory')
351
- mkdir('.hidden_empty')
352
- end
353
- it { subject.must_equal :ok }
354
- it { subject ; commit_count(local_repo).must_equal 1 }
355
- it { subject ; commit_count(remote_repo).must_equal 1 }
356
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
357
- it { subject ; head_tree_files(remote_repo).count.must_equal 2 }
358
- it { subject ; head_tree_files(remote_repo).must_include 'directory' }
359
- it { subject ; head_tree_files(remote_repo).must_include '.hidden_empty' }
360
- it { subject ; Dir.glob("#{local_repo_path}/**/.gitignore", File::FNM_DOTMATCH).count.must_equal 2 }
361
- end
358
+ describe 'previous commits' do
359
+ before do
360
+ write_and_commit('file1', 'foobar', 'initial commit', author1)
361
+ write_and_commit('file2', 'deadbeef', 'second commit', author1)
362
+ end
362
363
 
363
- describe 'and there is a directory with a hidden file' do
364
- before do
365
- mkdir('directory')
366
- write('directory/.hidden', '')
367
- end
368
- it { subject.must_equal :ok }
369
- it { subject ; local_file_exist?('directory', '.gitignore').must_equal false }
370
- it { subject ; commit_count(local_repo).must_equal 1 }
371
- it { subject ; commit_count(remote_repo).must_equal 1 }
372
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
373
- it { subject ; head_tree_files(remote_repo).count.must_equal 1 }
374
- it { subject ; head_tree_files(remote_repo).must_include 'directory' }
375
- end
364
+ describe 'nothing to commit' do
365
+ it { subject.must_equal false }
366
+ end
376
367
 
377
- describe 'and there is a new file to push' do
378
- before { write('file2', 'foobar') }
379
- it { subject.must_equal :ok }
380
- it { subject ; commit_count(local_repo).must_equal 1 }
381
- it { subject ; commit_count(remote_repo).must_equal 1 }
382
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
383
- it { subject ; head_tree_files(remote_repo).count.must_equal 1 }
384
- it { subject ; head_tree_files(remote_repo).must_include 'file2' }
368
+ describe 'changes to commit' do
369
+ before do
370
+ write('file1', 'foobar')
371
+ FileUtils.rm_rf(File.join(local_repo_path, 'file2'))
372
+ write('file3', 'foobar')
373
+ mkdir('directory')
385
374
  end
375
+ it { subject.must_equal true }
376
+ it { subject ; local_file_exist?('directory/.gitignore').must_equal true }
377
+ it { subject ; commit_count(local_repo).must_equal 3 }
378
+ it { subject ; head_commit(local_repo).message.must_equal "message\n" }
379
+ it { subject ; local_repo_clean?.must_equal true }
386
380
  end
381
+ end
382
+ end
387
383
 
388
- describe 'last sync is not nil' do
389
- let(:last_oid) { 'oid' }
384
+ describe '#push' do
385
+ subject { repository.push }
390
386
 
391
- describe 'and this is an error on the push' do
392
- before do
393
- write('file2', 'foobar')
387
+ let(:path_or_share) { stub(
388
+ path: local_repo_path,
389
+ remote_name: 'origin',
390
+ branch_name: 'master'
391
+ ) }
394
392
 
395
- # Simulate an error occurring during the push
396
- Grit::Git.any_instance.stubs(:push).raises(
397
- Grit::Git::CommandFailed.new('', 1, 'error message')
398
- )
399
- end
400
- it { subject.must_equal 'error message' }
401
- end
393
+ describe 'when invalid' do
394
+ let(:path_or_share) { 'tmp/unit/missing' }
395
+ it { subject.must_be_nil }
396
+ end
402
397
 
403
- describe 'and this is nothing to push' do
404
- it { subject.must_equal :nothing }
405
- it { subject ; commit_count(local_repo).must_equal 0 }
406
- end
398
+ describe 'when no remote' do
399
+ it { subject.must_equal :no_remote }
400
+ end
407
401
 
408
- describe 'and there is a conflicted commit to push' do
409
- before do
410
- bare_commit(remote_repo, 'file1', 'dead', 'commit', 'A U Thor', 'author@example.com')
411
- write('file1', 'beef')
412
- end
413
- it { subject ; commit_count(local_repo).must_equal 1 }
414
- it { subject ; commit_count(remote_repo).must_equal 1 }
415
- it { subject.must_equal :conflict }
416
- end
402
+ describe 'remote exists with no commits' do
403
+ before { create_local_repo_with_remote }
417
404
 
418
- describe 'and there is a commit to push' do
419
- before { write('file2', 'foobar') }
420
- it { subject.must_equal :ok }
421
- it { subject ; commit_count(local_repo).must_equal 1 }
422
- it { subject ; commit_count(remote_repo).must_equal 1 }
423
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
424
- it { subject ; head_tree_files(remote_repo).count.must_equal 1 }
425
- it { subject ; head_tree_files(remote_repo).must_include 'file2' }
426
- end
405
+ describe 'and no local commits' do
406
+ it { subject.must_equal :nothing }
407
+ it { subject ; commit_count(remote_repo).must_equal 0 }
427
408
  end
428
- end
429
409
 
430
- describe 'remote exists' do
431
- before { create_local_repo_with_remote_with_commit }
432
-
433
- describe 'last sync is nil' do
434
- let(:last_oid) { nil }
410
+ describe 'and a local commit' do
411
+ before { write_and_commit('file2', 'foobar', 'commit', author1) }
435
412
 
436
- describe 'and there is an error on push' do
413
+ describe 'and the push fails' do
437
414
  # Simulate an error occurring during the push
438
415
  before do
439
- Grit::Git.any_instance.stubs(:push).raises(
440
- Grit::Git::CommandFailed.new('', 1, '')
441
- )
442
- end
443
- it { subject.must_equal :nothing }
444
- it { subject ; commit_count(local_repo).must_equal 1 }
445
- end
446
-
447
- describe 'and there is a conflicted file to push' do
448
- before do
449
- bare_commit(remote_repo, 'file1', 'dead', 'commit', 'A U Thor', 'author@example.com')
450
- write('file1', 'beef')
451
- end
452
- it { subject ; commit_count(local_repo).must_equal 2 }
453
- it { subject ; commit_count(remote_repo).must_equal 2 }
454
- it { subject.must_equal :nothing }
455
- end
456
-
457
- describe 'and there are empty directories to push' do
458
- before do
459
- mkdir('directory')
460
- mkdir('.hidden_empty')
416
+ Grit::Git.any_instance.stubs(:push)
417
+ .raises(Grit::Git::CommandFailed.new('', 1, 'error message'))
461
418
  end
462
- it { subject.must_equal :ok }
463
- it { subject ; commit_count(local_repo).must_equal 2 }
464
- it { subject ; commit_count(remote_repo).must_equal 2 }
465
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
466
- it { subject ; head_tree_files(remote_repo).count.must_equal 3 }
467
- it { subject ; head_tree_files(remote_repo).must_include 'file1' }
468
- it { subject ; head_tree_files(remote_repo).must_include 'directory' }
469
- it { subject ; head_tree_files(remote_repo).must_include '.hidden_empty' }
470
- it { subject ; Dir.glob("#{local_repo_path}/**/.gitignore", File::FNM_DOTMATCH).count.must_equal 2 }
419
+ it { subject.must_equal 'error message' }
471
420
  end
472
421
 
473
- describe 'and there is a directory with a hidden file' do
474
- before do
475
- mkdir('directory')
476
- write('directory/.hidden', '')
477
- end
422
+ describe 'and the push succeeds' do
478
423
  it { subject.must_equal :ok }
479
- it { subject ; local_file_exist?('directory', '.gitignore').must_equal false }
480
- it { subject ; commit_count(local_repo).must_equal 2 }
481
- it { subject ; commit_count(remote_repo).must_equal 2 }
482
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
483
- it { subject ; head_tree_files(remote_repo).count.must_equal 2 }
484
- it { subject ; head_tree_files(remote_repo).must_include 'file1' }
485
- it { subject ; head_tree_files(remote_repo).must_include 'directory' }
424
+ it { subject ; commit_count(remote_repo).must_equal 1 }
486
425
  end
426
+ end
427
+ end
487
428
 
488
- describe 'and there is an existing file update to push' do
489
- before { write('file1', 'deadbeef') }
490
- it { subject.must_equal :ok }
491
- it { subject ; commit_count(local_repo).must_equal 2 }
492
- it { subject ; commit_count(remote_repo).must_equal 2 }
493
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
494
- it { subject ; head_tree_files(remote_repo).count.must_equal 1 }
495
- it { subject ; head_tree_files(remote_repo).must_include 'file1' }
496
- end
429
+ describe 'remote exists with commits' do
430
+ before { create_local_repo_with_remote_with_commit }
497
431
 
498
- describe 'and there is a new file to push' do
499
- before { write('file2', 'foobar') }
500
- it { subject.must_equal :ok }
501
- it { subject ; commit_count(local_repo).must_equal 2 }
502
- it { subject ; commit_count(remote_repo).must_equal 2 }
503
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
504
- it { subject ; head_tree_files(remote_repo).count.must_equal 2 }
505
- it { subject ; head_tree_files(remote_repo).must_include 'file1' }
506
- it { subject ; head_tree_files(remote_repo).must_include 'file2' }
507
- end
432
+ describe 'and no local commits' do
433
+ it { subject.must_equal :nothing }
434
+ it { subject ; commit_count(remote_repo).must_equal 1 }
508
435
  end
509
436
 
510
- describe 'last sync is not nil' do
511
- let(:last_oid) { 'oid' }
437
+ describe 'and a local commit' do
438
+ before { write_and_commit('file2', 'foobar', 'commit', author1) }
512
439
 
513
- describe 'and this is an error on the push' do
440
+ describe 'and the push fails' do
441
+ # Simulate an error occurring during the push
514
442
  before do
515
- write('file2', 'foobar')
516
-
517
- # Simulate an error occurring during the push
518
- Grit::Git.any_instance.stubs(:push).raises(
519
- Grit::Git::CommandFailed.new('', 1, 'error message')
520
- )
443
+ Grit::Git.any_instance.stubs(:push)
444
+ .raises(Grit::Git::CommandFailed.new('', 1, 'error message'))
521
445
  end
522
446
  it { subject.must_equal 'error message' }
523
447
  end
524
448
 
525
- describe 'and this is nothing to push' do
526
- it { subject.must_equal :nothing }
527
- it { subject ; commit_count(local_repo).must_equal 1 }
528
- end
449
+ describe 'and the push conflicts' do
450
+ before { bare_commit(remote_repo, 'file2', 'dead', 'commit', 'A U Thor', 'author@example.com') }
529
451
 
530
- describe 'and there is a conflicted commit to push' do
531
- before do
532
- bare_commit(remote_repo, 'file1', 'dead', 'commit', 'A U Thor', 'author@example.com')
533
- write('file1', 'beef')
534
- end
535
- it { subject ; commit_count(local_repo).must_equal 2 }
536
452
  it { subject ; commit_count(remote_repo).must_equal 2 }
537
453
  it { subject.must_equal :conflict }
538
454
  end
539
455
 
540
- describe 'and there is a commit to push' do
541
- before { write('file2', 'foobar') }
456
+ describe 'and the push succeeds' do
542
457
  it { subject.must_equal :ok }
543
- it { subject ; commit_count(local_repo).must_equal 2 }
544
458
  it { subject ; commit_count(remote_repo).must_equal 2 }
545
- it { subject ; head_commit(remote_repo).message.must_equal "message\n" }
546
- it { subject ; head_tree_files(remote_repo).count.must_equal 2 }
547
- it { subject ; head_tree_files(remote_repo).must_include 'file1' }
548
- it { subject ; head_tree_files(remote_repo).must_include 'file2' }
549
459
  end
550
460
  end
551
461
  end
@@ -766,18 +676,20 @@ describe Gitdocs::Repository do
766
676
 
767
677
  # NOTE: This method is ignoring hidden files.
768
678
  def local_file_count
769
- files = Dir.chdir(local_repo_path) do
770
- Dir.glob('*')
771
- end
679
+ files = Dir.chdir(local_repo_path) { Dir.glob('*') }
772
680
  files.count
773
681
  end
774
682
 
683
+ def local_repo_clean?
684
+ local_repo.diff_workdir(local_repo.head.target, include_untracked: true).deltas.empty?
685
+ end
686
+
775
687
  def local_file_exist?(*path_elements)
776
688
  File.exist?(File.join(local_repo_path, *path_elements))
777
689
  end
778
690
 
779
691
  def local_file_content(*path_elements)
780
- local_file_exist?(*path_elements).must_equal true
692
+ return nil unless local_file_exist?
781
693
  File.read(File.join(local_repo_path, *path_elements))
782
694
  end
783
695
  end
data/test/runner_test.rb CHANGED
@@ -63,7 +63,13 @@ describe 'gitdocs runner' do
63
63
  describe '#push_changes' do
64
64
  subject { runner.push_changes }
65
65
 
66
- before { repository.expects(:push).returns(push_result) }
66
+ before do
67
+ repository.expects(:commit)
68
+ .with('Auto-commit from gitdocs')
69
+ .returns(push_result)
70
+ repository.expects(:push)
71
+ .returns(push_result)
72
+ end
67
73
 
68
74
  describe 'when invalid' do
69
75
  let(:push_result) { nil }
@@ -98,12 +104,15 @@ describe 'gitdocs runner' do
98
104
  it { subject.must_equal nil }
99
105
  end
100
106
 
101
- describe 'when merge is ok' do
107
+ describe 'when push is ok' do
102
108
  let(:push_result) { :ok }
103
109
  before do
104
110
  runner.instance_variable_set(:@last_synced_revision, :oid)
105
- repository.stubs(:current_oid).returns(:next_oid)
106
- repository.stubs(:author_count).with(:oid).returns('Alice' => 1, 'Bob' => 2)
111
+ repository.stubs(:current_oid)
112
+ .returns(:next_oid)
113
+ repository.stubs(:author_count)
114
+ .with(:oid)
115
+ .returns('Alice' => 1, 'Bob' => 2)
107
116
  notifier.expects(:info)
108
117
  .with('Pushed 3 changes', "'root_path' has been pushed")
109
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitdocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.pre5
4
+ version: 0.5.0.pre6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Hull
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-15 00:00:00.000000000 Z
12
+ date: 2014-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: joshbuddy-guard