gitdocs 0.5.0 → 0.6.0

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 (65) hide show
  1. checksums.yaml +6 -14
  2. data/.codeclimate.yml +26 -0
  3. data/.rubocop.yml +8 -2
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG +13 -0
  6. data/Gemfile +1 -1
  7. data/README.md +7 -6
  8. data/Rakefile +31 -5
  9. data/bin/gitdocs +1 -0
  10. data/config.ru +6 -4
  11. data/gitdocs.gemspec +22 -19
  12. data/lib/gitdocs.rb +54 -16
  13. data/lib/gitdocs/browser_app.rb +34 -41
  14. data/lib/gitdocs/cli.rb +41 -32
  15. data/lib/gitdocs/configuration.rb +40 -101
  16. data/lib/gitdocs/git_notifier.rb +111 -0
  17. data/lib/gitdocs/initializer.rb +83 -0
  18. data/lib/gitdocs/manager.rb +90 -60
  19. data/lib/gitdocs/migration/004_add_index_for_path.rb +1 -1
  20. data/lib/gitdocs/notifier.rb +70 -104
  21. data/lib/gitdocs/rendering_helper.rb +3 -0
  22. data/lib/gitdocs/repository.rb +324 -307
  23. data/lib/gitdocs/repository/committer.rb +77 -0
  24. data/lib/gitdocs/repository/path.rb +157 -140
  25. data/lib/gitdocs/search.rb +40 -25
  26. data/lib/gitdocs/settings_app.rb +5 -3
  27. data/lib/gitdocs/share.rb +64 -0
  28. data/lib/gitdocs/synchronizer.rb +40 -0
  29. data/lib/gitdocs/version.rb +1 -1
  30. data/lib/gitdocs/views/_header.haml +2 -2
  31. data/lib/gitdocs/views/dir.haml +3 -3
  32. data/lib/gitdocs/views/edit.haml +1 -1
  33. data/lib/gitdocs/views/file.haml +1 -1
  34. data/lib/gitdocs/views/home.haml +3 -3
  35. data/lib/gitdocs/views/layout.haml +13 -13
  36. data/lib/gitdocs/views/revisions.haml +3 -3
  37. data/lib/gitdocs/views/search.haml +1 -1
  38. data/lib/gitdocs/views/settings.haml +6 -6
  39. data/test/integration/cli/full_sync_test.rb +83 -0
  40. data/test/integration/cli/share_management_test.rb +29 -0
  41. data/test/integration/cli/status_test.rb +14 -0
  42. data/test/integration/test_helper.rb +185 -151
  43. data/test/integration/{browse_test.rb → web/browse_test.rb} +11 -29
  44. data/test/integration/web/share_management_test.rb +46 -0
  45. data/test/support/git_factory.rb +276 -0
  46. data/test/unit/browser_app_test.rb +346 -0
  47. data/test/unit/configuration_test.rb +8 -70
  48. data/test/unit/git_notifier_test.rb +116 -0
  49. data/test/unit/gitdocs_test.rb +90 -0
  50. data/test/unit/manager_test.rb +36 -0
  51. data/test/unit/notifier_test.rb +60 -124
  52. data/test/unit/repository_committer_test.rb +111 -0
  53. data/test/unit/repository_path_test.rb +92 -76
  54. data/test/unit/repository_test.rb +243 -356
  55. data/test/unit/search_test.rb +15 -0
  56. data/test/unit/settings_app_test.rb +80 -0
  57. data/test/unit/share_test.rb +97 -0
  58. data/test/unit/test_helper.rb +17 -3
  59. metadata +114 -108
  60. data/lib/gitdocs/runner.rb +0 -108
  61. data/lib/gitdocs/server.rb +0 -62
  62. data/test/integration/full_sync_test.rb +0 -66
  63. data/test/integration/share_management_test.rb +0 -95
  64. data/test/integration/status_test.rb +0 -21
  65. data/test/unit/runner_test.rb +0 -122
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDc4ZmI3MTc1YjRjZjE4ZmNmNDFmNjgwMDEzY2YzZTkwY2Q5MWI4Yw==
5
- data.tar.gz: !binary |-
6
- YmRjMzViNzc0MzgwMDVkMDgxOGNmMDI3MDZmYjhlMTU3OGUxMDg2ZQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MjMzNzJlNGY3YmMzMWY2YWY2ZTE1ZjBjYTJmZDYwMWZmM2NjMTYyOTM0YzUw
10
- ODkwZmFmY2NkYmVkZTI3MjYxNmZhNjUwZDliYjJmODAzOGY2YTc3M2UwZjRk
11
- MTZiNGYwNmVmMjU5ZDkyM2U1MjcwODdlZmQ1ODJhODJjZjA4ODQ=
12
- data.tar.gz: !binary |-
13
- MWM2Yjk4ZGE1ODIzMTg4YTEyYTg1YTNhZTc1MWI1NWFlMTczMWFlMjg5Y2Jh
14
- NmRhYTAzYWNmMzI4MTZhNTdjN2QwMzA3MzZhMTI5ZDRmMGFhZWE3YTdhMWVk
15
- ZTAwODA3OWZkMDdkMDEwZThlZDQyM2ZjZDMzMzA1ZjJiNDZhOTg=
2
+ SHA1:
3
+ metadata.gz: 459edb301fffc2948f4ae59ed114492d628c4885
4
+ data.tar.gz: 619553936453338fc95f54ce9efad4a98383dba9
5
+ SHA512:
6
+ metadata.gz: 879a1f9488c61a47713a9a645cfc76b4fff279baf6b443056a66650439866950b810b2196c252f54651cee2c0e5cdc28559d62460fb42a5e129660bcfa5dccde
7
+ data.tar.gz: 98681003763be98fcafd06bd95dfcfd6d08f2cc2ddc14b1d5842fd19a6d46eeaee4df6e55507c771845e842cdceb917caac32e1acd5f2c331de4751024b44112
@@ -0,0 +1,26 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+ golint:
5
+ enabled: true
6
+ eslint:
7
+ enabled: true
8
+ csslint:
9
+ enabled: true
10
+ duplication:
11
+ enabled: true
12
+ config:
13
+ languages:
14
+ - ruby
15
+ - javascript
16
+ ratings:
17
+ paths:
18
+ - app/**
19
+ - lib/**
20
+ - "**.rb"
21
+ - "**.go"
22
+ exclude_paths:
23
+ - lib/gitdocs/public/js/ace/**/*
24
+ - "lib/gitdocs/public/js/bootstrap-alerts.js"
25
+ - "lib/gitdocs/public/js/jquery.js"
26
+ - "lib/gitdocs/public/js/jquery.tablesorter.js"
@@ -1,8 +1,6 @@
1
1
  Documentation:
2
2
  Enabled: false
3
3
 
4
- ClassAndModuleChildren:
5
- Enabled: false
6
4
 
7
5
  # Splitting method arguments across multiple lines can result in the containing
8
6
  # method looking long, but not actually increasing the complexity at all.
@@ -11,3 +9,11 @@ MethodLength:
11
9
 
12
10
  EachWithObject:
13
11
  Enabled: false
12
+
13
+ LineLength:
14
+ Exclude:
15
+ - 'Rakefile'
16
+ - 'gitdocs.gemspec'
17
+
18
+ SignalException:
19
+ EnforcedStyle: semantic
@@ -2,7 +2,15 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.2.4
6
+ - 2.1.8
7
+ - 2.3.0
5
8
  - ruby-head
6
9
  matrix:
7
10
  allow_failures:
11
+ - rvm: 1.9.3
8
12
  - rvm: ruby-head
13
+ sudo: false
14
+ addons:
15
+ code_climate:
16
+ repo_token: "18995229639977d370a4adf13644223c53baa31b9c7fc302a7ce263aa5bc6dbf"
data/CHANGELOG CHANGED
@@ -1,3 +1,16 @@
1
+ 0.6.0
2
+ * convert notification to use the Notiffany gem (@acant)
3
+ * upgrade rugged gem (@acant)
4
+ * fix missing dependency for the 'gitdocs open' command (@acant)
5
+ * convert to use Celluloid and the listen gem, and remove the old guard and
6
+ event-machine dependencies (@acant)
7
+
8
+ 0.6.0.pre1
9
+ * upgrade gems redcarpet, poltergeist (@acant)
10
+ * add 'rake debug' task for development and debugging (@acant)
11
+ * add a --verbose flag for starting gitdocs with more logging (@acant)
12
+ * change the -D flag to --foreground for running gitdocs in the foreground (acant)
13
+
1
14
  0.5.0 (May 2nd 2015)
2
15
  * upgrade gems activerecord, minitest, haml-lint, redcarpet (@acant)
3
16
  * convert web interface to use Sinatra instead of renee (@acant)
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in gitdocs.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Gitdocs
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/gitdocs.png)](http://badge.fury.io/rb/gitdocs)
4
- [![Code Climate](https://codeclimate.com/github/bazaarlabs/gitdocs.png)](https://codeclimate.com/github/bazaarlabs/gitdocs)
3
+ [![Gem Version](https://badge.fury.io/rb/gitdocs.svg)](http://badge.fury.io/rb/gitdocs)
4
+ [![Code Climate](https://codeclimate.com/github/nesquena/gitdocs.svg)](https://codeclimate.com/github/nesquena/gitdocs)
5
5
  [![Build Status](https://travis-ci.org/nesquena/gitdocs.svg?branch=master)](https://travis-ci.org/nesquena/gitdocs)
6
- [![Inline docs](http://inch-ci.org/github/nesquena/gitdocs.png?branch=master)](http://inch-ci.org/github/nesquena/gitdocs)
6
+ [![Inline docs](http://inch-ci.org/github/nesquena/gitdocs.svg?branch=master)](http://inch-ci.org/github/nesquena/gitdocs)
7
7
  [![Dependency Status](https://gemnasium.com/nesquena/gitdocs.svg)](https://gemnasium.com/nesquena/gitdocs)
8
- [![Coverage Status](https://coveralls.io/repos/nesquena/gitdocs/badge.png?branch=master)](https://coveralls.io/r/nesquena/gitdocs)
8
+ [![Test Coverage](https://codeclimate.com/github/nesquena/gitdocs/badges/coverage.svg)](https://codeclimate.com/github/nesquena/gitdocs/coverage)
9
9
 
10
10
  Open-source dropbox alternative powered by git. Collaborate on files and tasks without any extra hassle.
11
11
  gitdocs will automatically keep everyone's repos in sync by pushing and pulling changes.
@@ -75,10 +75,10 @@ You need to start gitdocs in order for the monitoring to work:
75
75
  gitdocs start
76
76
  ```
77
77
 
78
- If the start command fails, you can check the logs in `~/.gitdocs/log` or run again with the debug flag:
78
+ If the start command fails, you can check the logs in `~/.gitdocs/log` or run again in the foreground and increase logging to more easily see what is going wrong:
79
79
 
80
80
  ```
81
- gitdocs start -D
81
+ gitdocs start --foreground --verbose
82
82
  ```
83
83
 
84
84
  Once gitdocs has been started and is monitoring the correct directories, simply start editing or adding files to your
@@ -207,5 +207,6 @@ but provide the features that makes Dropbox great. If you are interested in othe
207
207
  tool, not open source or publicly defined protocol
208
208
  * [StrongSync](https://secure.expandrive.com/strongsync) Dropbox clone utility,
209
209
  proprietary
210
+ * [pullbox](https://github.com/prashanthellina/pullbox) Dropbox clone with git and Python
210
211
 
211
212
  If any other open-source dropbox alternatives are available, we would love to hear about them so let us know!
data/Rakefile CHANGED
@@ -1,9 +1,15 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
  require 'jslint/tasks'
4
+ require 'haml_lint/rake_task'
5
+ require 'rubocop/rake_task'
4
6
 
5
7
  JSLint.config_path = '.jslint.yml'
6
8
 
9
+ HamlLint::RakeTask.new
10
+
11
+ RuboCop::RakeTask.new
12
+
7
13
  namespace :test do
8
14
  # Separate the unit and integration tests when running the entire suite.
9
15
  Rake::TestTask.new(:unit) do |t|
@@ -12,11 +18,22 @@ namespace :test do
12
18
  t.verbose = true
13
19
  end
14
20
 
15
- Rake::TestTask.new(integration: :unit) do |t|
16
- t.libs.push('lib')
17
- t.test_files = FileList[File.expand_path('../test/integration/**/*_test.rb', __FILE__)]
18
- t.verbose = true
21
+ namespace :integration do
22
+ Rake::TestTask.new(cli: 'test:unit') do |t|
23
+ t.libs.push('lib')
24
+ t.test_files = FileList[File.expand_path('../test/integration/cli/**/*_test.rb', __FILE__)]
25
+ t.verbose = true
26
+ end
27
+
28
+ Rake::TestTask.new(web: :cli) do |t|
29
+ t.libs.push('lib')
30
+ t.test_files = FileList[File.expand_path('../test/integration/web/**/*_test.rb', __FILE__)]
31
+ t.verbose = true
32
+ end
19
33
  end
34
+
35
+ desc 'Run all integration tests'
36
+ task integration: 'integration:web'
20
37
  end
21
38
 
22
39
  # Keep a default test task for manually running any test
@@ -44,4 +61,13 @@ namespace :server do
44
61
  end
45
62
  end
46
63
 
47
- task default: 'test:integration'
64
+ desc 'Run the daemon in debugging mode'
65
+ task :debug do
66
+ exec('bin/gitdocs start --foreground --verbose --port 9999')
67
+ end
68
+
69
+ if ENV['TRAVIS']
70
+ task default: 'test:integration:cli'
71
+ else
72
+ task default: 'test:integration'
73
+ end
@@ -2,4 +2,5 @@
2
2
 
3
3
  require 'gitdocs'
4
4
 
5
+ Gitdocs::Initializer.initialize_all
5
6
  Gitdocs::Cli.start(ARGV)
data/config.ru CHANGED
@@ -5,17 +5,19 @@ require './lib/gitdocs/browser_app'
5
5
  require './lib/gitdocs/repository'
6
6
  require './lib/gitdocs/configuration'
7
7
 
8
+ # rubocop:disable AlignParameters
8
9
  use Rack::Static,
9
10
  urls: %w(/css /js /img /doc),
10
11
  root: './lib/gitdocs/public'
11
12
  use Rack::MethodOverride
12
13
 
13
- config_root = './tmp/web'
14
- FileUtils.mkdir_p(config_root)
15
- Gitdocs::SettingsApp.set :manager, Gitdocs::Manager.new(config_root, true)
14
+ Gitdocs::Initializer.root_dirname = './tmp/web'
15
+ Gitdocs::Initializer.initialize_database
16
+
16
17
  Gitdocs::SettingsApp.set :logging, true
17
18
  map('/settings') { run Gitdocs::SettingsApp }
18
19
 
19
- Gitdocs::BrowserApp.set :repositories, Gitdocs::Configuration.new(config_root).shares.map { |x| Gitdocs::Repository.new(x) }
20
+ repositories = Gitdocs::Share.all.map { |x| Gitdocs::Repository.new(x) }
21
+ Gitdocs::BrowserApp.set :repositories, repositories
20
22
  Gitdocs::BrowserApp.set :logging, true
21
23
  map('/') { run Gitdocs::BrowserApp }
@@ -22,36 +22,39 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.required_ruby_version = '>= 1.9'
24
24
 
25
- s.add_dependency 'joshbuddy-guard', '~> 0.10.0'
26
- s.add_dependency 'thin', '~> 1.6.2'
25
+ # FIXME: celluloid v0.17 is not compatible with reel-rack/reel. It can only
26
+ # be upgraded once that is resolved.
27
+ s.add_dependency 'celluloid', '~> 0.16.0'
28
+ s.add_dependency 'reel-rack', '~> 0.2.2'
29
+ # FIXME: listen cannot be upgraded until we drop support for Ruby <v2.1
30
+ s.add_dependency 'listen', '~> 3.0.5'
31
+
27
32
  s.add_dependency 'sinatra', '~> 1.4.5'
28
- s.add_dependency 'redcarpet', '~> 3.2.2'
29
- s.add_dependency 'thor', '~> 0.14.6'
33
+ s.add_dependency 'redcarpet', '~> 3.3.0'
34
+ s.add_dependency 'thor', '~> 0.19.1'
30
35
  s.add_dependency 'coderay', '~> 1.1.0'
31
- s.add_dependency 'dante', '~> 0.1.2'
36
+ s.add_dependency 'dante', '~> 0.2.0'
32
37
  s.add_dependency 'growl', '~> 1.0.3'
33
38
  s.add_dependency 'haml', '~> 4.0.5'
34
39
  s.add_dependency 'sqlite3', '~> 1.3.4'
35
40
  s.add_dependency 'activerecord', '~> 4.2.0'
36
41
  s.add_dependency 'grit', '~> 2.5.0'
37
- s.add_dependency 'shell_tools', '~> 0.1.0'
38
42
  s.add_dependency 'mimetype-fu', '~> 0.1.2'
39
- s.add_dependency 'eventmachine', '>= 1.0.3'
40
43
  s.add_dependency 'launchy', '~> 2.4.2'
41
- s.add_dependency 'rugged', '~> 0.19.0'
44
+ s.add_dependency 'rugged', '~> 0.24.0'
42
45
  s.add_dependency 'table_print', '~> 1.5.1'
46
+ s.add_dependency 'notiffany', '~> 0.1.0'
43
47
 
44
- s.add_development_dependency 'minitest', '~> 5.5.0'
48
+ s.add_development_dependency 'minitest', '~> 5.9.0'
45
49
  s.add_development_dependency 'capybara_minitest_spec', '~> 1.0.2'
46
- s.add_development_dependency 'poltergeist', '~> 1.5.1'
47
- s.add_development_dependency 'rake'
48
- s.add_development_dependency 'mocha'
49
- s.add_development_dependency 'fakeweb'
50
- s.add_development_dependency 'metric_fu'
51
- s.add_development_dependency 'aruba'
52
- s.add_development_dependency 'rubocop'
53
- s.add_development_dependency 'haml-lint', '~> 0.10.0'
50
+ s.add_development_dependency 'shell_tools', '~> 0.1.0'
51
+ s.add_development_dependency 'poltergeist', '~> 1.7.0'
52
+ s.add_development_dependency 'rake', '~> 11.1.2'
53
+ s.add_development_dependency 'mocha', '~> 1.1.0'
54
+ s.add_development_dependency 'aruba', '~> 0.6.1'
55
+ s.add_development_dependency 'rubocop', '~> 0.40.0'
56
+ s.add_development_dependency 'haml_lint', '~> 0.17.1'
54
57
  s.add_development_dependency 'jslint_on_rails', '~> 1.1.1'
55
- s.add_development_dependency 'coveralls'
56
- s.add_development_dependency 'shotgun'
58
+ s.add_development_dependency 'shotgun', '~> 0.9.1'
59
+ s.add_development_dependency 'codeclimate-test-reporter'
57
60
  end
@@ -3,39 +3,77 @@
3
3
  require 'thread'
4
4
  require 'dante'
5
5
  require 'socket'
6
- require 'shell_tools'
7
- require 'guard'
8
6
  require 'grit'
9
7
  require 'rugged'
10
8
  require 'table_print'
9
+ require 'notiffany'
10
+ require 'launchy'
11
+ require 'celluloid'
12
+ require 'listen'
13
+ require 'reel/rack'
11
14
 
12
15
  require 'gitdocs/version'
16
+ require 'gitdocs/initializer'
17
+ require 'gitdocs/share'
13
18
  require 'gitdocs/configuration'
14
- require 'gitdocs/runner'
15
- require 'gitdocs/server'
16
19
  require 'gitdocs/cli'
17
20
  require 'gitdocs/manager'
21
+ require 'gitdocs/synchronizer'
18
22
  require 'gitdocs/notifier'
23
+ require 'gitdocs/git_notifier'
19
24
  require 'gitdocs/repository'
20
25
  require 'gitdocs/repository/path'
26
+ require 'gitdocs/repository/committer'
27
+ require 'gitdocs/settings_app'
28
+ require 'gitdocs/browser_app'
21
29
  require 'gitdocs/search'
22
30
 
23
31
  module Gitdocs
24
- DEBUG = ENV['DEBUG']
25
-
26
- # Gitdocs.start(:config_root => "...", :debug => true)
27
- def self.start(options = {}, &blk)
28
- options = { debug: DEBUG, config_root: nil }.merge(options)
29
- @manager.stop if @manager
30
- @manager = Manager.new(options[:config_root], options[:debug], &blk)
31
- @manager.start(options[:port])
32
+ # @return [String]
33
+ def self.log_path
34
+ File.expand_path('log', Initializer.root_dirname)
32
35
  end
33
36
 
34
- def self.restart
35
- @manager.restart
37
+ # @param [String] message
38
+ # @return [void]
39
+ def self.log_debug(message)
40
+ init_log
41
+ Celluloid.logger.debug(message)
36
42
  end
37
43
 
38
- def self.stop
39
- @manager.stop
44
+ # @param [String] message
45
+ # @return [void]
46
+ def self.log_info(message)
47
+ init_log
48
+ Celluloid.logger.info(message)
49
+ end
50
+
51
+ # @param [String] message
52
+ # @return [void]
53
+ def self.log_warn(message)
54
+ init_log
55
+ Celluloid.logger.warn(message)
56
+ end
57
+
58
+ # @param [String] message
59
+ # @return [void]
60
+ def self.log_error(message)
61
+ init_log
62
+ Celluloid.logger.error(message)
63
+ end
64
+
65
+ ##############################################################################
66
+
67
+ private_class_method
68
+
69
+ # @return [void]
70
+ def self.init_log
71
+ return if @initialized
72
+
73
+ # Initialize the logger
74
+ log_output = Initializer.foreground ? STDOUT : log_path
75
+ Celluloid.logger = Logger.new(log_output)
76
+ Celluloid.logger.level = Initializer.verbose ? Logger::DEBUG : Logger::INFO
77
+ @initialized = true
40
78
  end
41
79
  end
@@ -10,19 +10,33 @@ module Gitdocs
10
10
  class BrowserApp < Sinatra::Base
11
11
  set :haml, format: :html5
12
12
 
13
- helpers Gitdocs::RenderingHelper
13
+ helpers RenderingHelper
14
+
15
+ helpers do
16
+ # @return [Integer]
17
+ def id
18
+ @id ||= params[:id].to_i
19
+ end
20
+
21
+ # @return [Gitdocs::Repository::Path]
22
+ def repository
23
+ @repository ||= Repository.new(Share.find(id))
24
+ end
25
+
26
+ # @return [Gitdocs::Repository::Path]
27
+ def path
28
+ halt(404) unless repository
29
+ @path ||= Repository::Path.new(
30
+ repository, URI.decode(params[:splat].first)
31
+ )
32
+ end
33
+ end
14
34
 
15
35
  get('/') do
16
- if settings.repositories.size == 1
17
- redirect to('/0/')
36
+ if Share.all.count == 1
37
+ redirect to("/#{Share.first.id}/")
18
38
  else
19
- haml(
20
- :home,
21
- locals: {
22
- shares: settings.repositories,
23
- nav_state: 'home'
24
- }
25
- )
39
+ haml(:home, locals: { nav_state: 'home' })
26
40
  end
27
41
  end
28
42
 
@@ -30,31 +44,15 @@ module Gitdocs
30
44
  haml(
31
45
  :search,
32
46
  locals: {
33
- results: Gitdocs::Search.new(settings.repositories).search(params[:q]),
47
+ results: Search.search(params[:q]),
34
48
  nav_state: nil
35
49
  }
36
50
  )
37
51
  end
38
52
 
39
- helpers do
40
- # @return [Integer]
41
- def id
42
- @id ||= params[:id].to_i
43
- end
44
-
45
- # @return [Gitdocs::Repository::Path]
46
- def path
47
- halt(404) unless settings.repositories[id]
48
- @path ||= Gitdocs::Repository::Path.new(
49
- settings.repositories[id], URI.unescape(params[:splat].first)
50
- )
51
- end
52
- end
53
-
54
53
  get('/:id*') do
55
54
  default_locals = {
56
- idx: id,
57
- root: settings.repositories[id].root,
55
+ root: repository.root,
58
56
  nav_state: nil
59
57
  }
60
58
 
@@ -105,7 +103,7 @@ module Gitdocs
105
103
  redirect_path =
106
104
  if params[:file] # upload
107
105
  path.join(params[:file][:filename])
108
- FileUtils.mv(params[:file][:tempfile].path, path.absolute_path)
106
+ path.mv(params[:file][:tempfile].path)
109
107
  "/#{id}/#{path.relative_path}"
110
108
  elsif params[:filename] # add file/directory
111
109
  path.join(params[:filename])
@@ -125,26 +123,21 @@ module Gitdocs
125
123
  end
126
124
 
127
125
  put('/:id*') do
128
- redirect_path =
126
+ commit_message =
129
127
  if params[:revision] # revert
130
128
  path.revert(params[:revision])
131
- "/#{id}/#{path.relative_path}"
129
+ "Reverting '#{path.relative_path}' to #{params[:revision]}"
132
130
  elsif params[:data] && params[:message] # save
133
- path.write(params[:data], params[:message])
134
- "/#{id}/#{path.relative_path}"
135
- else
136
- # No valid inputs, do nothing and redirect.
137
- "/#{id}/#{path.relative_path}"
131
+ path.write(params[:data])
132
+ params[:message]
138
133
  end
139
- redirect to(redirect_path)
134
+ repository.write_commit_message(commit_message)
135
+ redirect to("/#{id}/#{path.relative_path}")
140
136
  end
141
137
 
142
138
  delete('/:id*') do
143
139
  path.remove
144
- parent = File.dirname(path.relative_path)
145
- parent = '' if parent == '/'
146
- parent = nil if parent == '.'
147
- redirect to("/#{id}#{parent}")
140
+ redirect to("/#{id}/#{path.relative_dirname}")
148
141
  end
149
142
  end
150
143
  end