grack 0.1.0.pre2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 871dc948470e8c1dfc7615bfe4579915c4596204
4
- data.tar.gz: 8adad4b912101741254af438d7e626e1f78780e5
3
+ metadata.gz: d654736655d180b4cb314efc2e4ff7bd90a8c6f6
4
+ data.tar.gz: d4568e2683c496fdfcccf1acda3f7cb2f2e01b2b
5
5
  SHA512:
6
- metadata.gz: 4eda2933722fe14e321b970d622fd2caea9f7d3ceab6f68c07244ee203adaea0f9f06806e613322bd5174cc3e659a1ef827387c1c64f55d359fc9c4f49df86c5
7
- data.tar.gz: 067b85e420b42ba33164c67fcef5687bac03a07aaa53a1ae90893da10dfea7a5952ad7d8944d156b6785d0a0b8b1c7b21f4c0cdf0974272d45a9bd0454544b44
6
+ metadata.gz: ef0f1eaf267bf0ba8ad19a93e296120be2042e4c808653fd04902b9ecc8803633083dee405b510e32f708cf585963045d24901c68a3af2e2a28d21b8d5fb1bc8
7
+ data.tar.gz: 60cc1821166972428122d8d0600fb550a56ed83fcb1c8b952116eb3b8d2dfef00da75241ad5fddd09ce883a69eedd9575b628ba8d1914617105b9e8d12111a48
data/NEWS.md CHANGED
@@ -5,6 +5,11 @@ detailed information is available in the rest of the documentation.
5
5
 
6
6
  **NOTE:** Date stamps in the following entries are in YYYY/MM/DD format.
7
7
 
8
+ ## v0.1.0 (2016/04/30)
9
+
10
+ * Removed compatibility layer for version 0.0.x. Please use the configuration parameters specified in the README and update your adapters.
11
+ * Fix tests for git > 2.7
12
+
8
13
  ## v0.1.0.pre2
9
14
 
10
15
  * Minor change required for new version [rjgit adapter](https://github.com/grackorg/rjgit_grack) to work
data/README.md CHANGED
@@ -63,6 +63,31 @@ administrative area (`.git` directory). Additionally, any recent version of Git
63
63
  prevents pushes into non-bare repositories by default since pushing into the
64
64
  currently checked out branch can effectively "break" the checkout tree.
65
65
 
66
+ ## Synopsis
67
+
68
+ In `config.ru`:
69
+
70
+ ```ruby
71
+ require 'grack/app'
72
+ require 'grack/git_adapter'
73
+
74
+ config = {
75
+ :root => '/path/to/bare/repositories',
76
+ :allow_push => true,
77
+ :allow_pull => true,
78
+ :git_adapter_factory => ->{ Grack::GitAdapter.new }
79
+ }
80
+
81
+ run Grack::App.new(config)
82
+ ```
83
+
84
+ Then run:
85
+
86
+ ```sh
87
+ $ bundle exec rackup --host localhost --port 8080 config.ru
88
+ $ git clone http://localhost:8080/your-repository.git
89
+ ```
90
+
66
91
  ### Git Adapters
67
92
 
68
93
  Grack makes calls to the git binary through the GitAdapter abstraction class.
@@ -77,8 +102,7 @@ Grack::App.new(:git_adapter_factory => ->{ MyAdapter.new })
77
102
  Alternative adapters available:
78
103
  * [rjgit_grack](http://github.com/grackorg/rjgit_grack) lets Grack use the
79
104
  [RJGit](http://github.com/repotag/rjgit) gem to implement Smart HTTP in pure
80
- Jruby. (Currently requires use of backward compatibility support via
81
- Grack::CompatibleGitAdapter)
105
+ JRuby.
82
106
 
83
107
  ### Developing Adapters
84
108
 
@@ -106,34 +130,17 @@ implementation.
106
130
  * Limits push/pull access globally and per-repository.
107
131
  * Thread safe operation.
108
132
 
109
- ## Known Bugs/Limitations
133
+ ### Hooks
110
134
 
111
- * Will likely block fully evented web servers when using the stock Git adapter.
135
+ By default, grack doesn't support git hooks. This is because the default GitAdapter directly streams the requests to the `git-receive-pack` and `git-upload-pack` processes. However, alternative adapters may implement hooks.
112
136
 
113
- ## Synopsis
137
+ Adapters that support hooks:
114
138
 
115
- In `config.ru`:
139
+ * [rjgit_grack](http://github.com/grackorg/rjgit_grack)
116
140
 
117
- ```ruby
118
- require 'grack/app'
119
- require 'grack/git_adapter'
120
-
121
- config = {
122
- :root => '/path/to/bare/repositories',
123
- :allow_push => true,
124
- :allow_pull => true,
125
- :git_adapter_factory => ->{ Grack::GitAdapter.new }
126
- }
127
-
128
- run Grack::App.new(config)
129
- ```
130
-
131
- Then run:
141
+ ## Known Bugs/Limitations
132
142
 
133
- ```sh
134
- $ bundle exec rackup --host localhost --port 8080 config.ru
135
- $ git clone http://localhost:8080/your-repository.git
136
- ```
143
+ * Will likely block fully evented web servers when using the stock Git adapter.
137
144
 
138
145
  ## Runtime Requirements
139
146
 
@@ -181,7 +188,7 @@ documentation.
181
188
  Thanks to all contributors. Without your help this project would not exist.
182
189
 
183
190
  * Scott Chacon :: schacon@gmail.com
184
- * Dawa Ometto :: dawa.ometto@phil.uu.nl
191
+ * Dawa Ometto :: d.ometto@gmail.com
185
192
  * Jeremy Bopp :: jeremy@bopp.net
186
193
 
187
194
  ## License
@@ -47,8 +47,6 @@ module Grack
47
47
  # @option opts [#call] :git_adapter_factory (->{ GitAdapter.new }) a
48
48
  # call-able object that creates Git adapter instances per request.
49
49
  def initialize(opts = {})
50
- opts = convert_old_opts(opts)
51
-
52
50
  @root = Pathname.new(opts.fetch(:root, '.')).expand_path
53
51
  @allow_push = opts.fetch(:allow_push, nil)
54
52
  @allow_pull = opts.fetch(:allow_pull, nil)
@@ -437,46 +435,5 @@ module Grack
437
435
  }
438
436
  end
439
437
 
440
- ##
441
- # Converts old configuration settings to current ones.
442
- #
443
- # @param [Hash] opts an options hash to convert.
444
- # @option opts [String] :project_root a directory path containing 1 or more
445
- # Git repositories.
446
- # @option opts [Boolean, nil] :receivepack determines whether or not to
447
- # allow pushes into the repositories. +nil+ means to defer to the
448
- # requested repository.
449
- # @option opts [Boolean, nil] :uploadpack determines whether or not to
450
- # allow fetches/pulls from the repositories. +nil+ means to defer to the
451
- # requested repository.
452
- # @option opts [#create] :adapter a class that provides an interface for
453
- # interacting with Git repositories.
454
- #
455
- # @return an options hash with current options set based on old ones.
456
- def convert_old_opts(opts)
457
- opts = opts.dup
458
-
459
- if opts.key?(:project_root) && ! opts.key?(:root)
460
- opts[:root] = opts.fetch(:project_root)
461
- end
462
- if opts.key?(:upload_pack) && ! opts.key?(:allow_pull)
463
- opts[:allow_pull] = opts.fetch(:upload_pack)
464
- end
465
- if opts.key?(:receive_pack) && ! opts.key?(:allow_push)
466
- opts[:allow_push] = opts.fetch(:receive_pack)
467
- end
468
- if opts.key?(:adapter) && ! opts.key?(:git_adapter_factory)
469
- adapter = opts.fetch(:adapter)
470
- opts[:git_adapter_factory] =
471
- if GitAdapter == adapter
472
- ->{ GitAdapter.new(opts.fetch(:git_path, 'git')) }
473
- else
474
- require 'grack/compatible_git_adapter'
475
- ->{ CompatibleGitAdapter.new(adapter.new) }
476
- end
477
- end
478
-
479
- opts
480
- end
481
438
  end
482
439
  end
@@ -406,64 +406,6 @@ class AppTest < Minitest::Test
406
406
  assert_equal 404, r.status
407
407
  end
408
408
 
409
- def test_config_project_root_used_when_root_not_set
410
- session = Rack::Test::Session.new(
411
- App.new(:project_root => repositories_root)
412
- )
413
-
414
- session.get "#{example_repo_urn}/info/refs"
415
- assert_equal 200, session.last_response.status
416
- end
417
-
418
- def test_config_project_root_ignored_when_root_is_set
419
- session = Rack::Test::Session.new(
420
- App.new(:project_root => 'unlikely/path', :root => repositories_root)
421
- )
422
-
423
- session.get "#{example_repo_urn}/info/refs"
424
- assert_equal 200, session.last_response.status
425
- end
426
-
427
- def test_config_upload_pack_used_when_allow_pull_not_set
428
- session = Rack::Test::Session.new(
429
- App.new(:root => repositories_root, :upload_pack => false)
430
- )
431
-
432
- session.get "#{example_repo_urn}/info/refs?service=git-upload-pack"
433
- assert_equal 403, session.last_response.status
434
- end
435
-
436
- def test_config_upload_pack_ignored_when_allow_pull_is_set
437
- session = Rack::Test::Session.new(
438
- App.new(
439
- :root => repositories_root, :upload_pack => true, :allow_pull => false
440
- )
441
- )
442
-
443
- session.get "#{example_repo_urn}/info/refs?service=git-upload-pack"
444
- assert_equal 403, session.last_response.status
445
- end
446
-
447
- def test_config_receive_pack_used_when_allow_push_not_set
448
- session = Rack::Test::Session.new(
449
- App.new(:root => repositories_root, :receive_pack => false)
450
- )
451
-
452
- session.get "#{example_repo_urn}/info/refs?service=git-receive-pack"
453
- assert_equal 403, session.last_response.status
454
- end
455
-
456
- def test_config_receive_pack_ignored_when_allow_push_is_set
457
- session = Rack::Test::Session.new(
458
- App.new(
459
- :root => repositories_root, :receive_pack => true, :allow_push => false
460
- )
461
- )
462
-
463
- session.get "#{example_repo_urn}/info/refs?service=git-receive-pack"
464
- assert_equal 403, session.last_response.status
465
- end
466
-
467
409
  def test_config_adapter_with_GitAdapter
468
410
  session = Rack::Test::Session.new(
469
411
  App.new(:root => repositories_root, :adapter => GitAdapter)
@@ -476,16 +418,26 @@ class AppTest < Minitest::Test
476
418
 
477
419
  def test_config_adapter_with_custom_adapter
478
420
  git_adapter = mock('git_adapter')
421
+ git_adapter.
422
+ expects(:exist?).
423
+ returns(true)
424
+ git_adapter.
425
+ expects(:repository_path=).
426
+ returns(true)
479
427
  git_adapter.
480
428
  expects(:update_server_info).
481
- with("#{repositories_root}#{example_repo_urn}")
429
+ returns(true)
430
+ git_adapter.
431
+ expects(:file).
432
+ with('info/refs').
433
+ returns(FileStreamer.new(Tempfile.new('foo')))
482
434
  git_adapter_class = mock('git_adapter_class')
483
435
  git_adapter_class.expects(:new).with.returns(git_adapter)
484
436
  session = Rack::Test::Session.new(
485
437
  App.new(
486
438
  :root => repositories_root,
487
439
  :allow_pull => true,
488
- :adapter => git_adapter_class
440
+ :git_adapter_factory => -> { git_adapter_class.new }
489
441
  )
490
442
  )
491
443
 
@@ -12,7 +12,7 @@ require 'grack/git_adapter'
12
12
  class GitAdapterTest < Minitest::Test
13
13
  include Grack
14
14
 
15
- GIT_RECEIVE_RESPONSE = %r{\A001b# service=receive-pack\n0000[0-9a-f]{4}cb067e06bdf6e34d4abebf6cf2de85d65a52c65e refs/heads/master\000\s*report-status delete-refs side-band-64k quiet ofs-delta.*\n0000\z}
15
+ GIT_RECEIVE_RESPONSE = %r{\A001b# service=receive-pack\n0000[0-9a-f]{4}cb067e06bdf6e34d4abebf6cf2de85d65a52c65e refs/heads/master\000\s*report-status delete-refs side-band-64k quiet (atomic )?ofs-delta.*\n0000\z}
16
16
 
17
17
  def git_config_set(name, value)
18
18
  system(git_path, 'config', '--local', name, value, :chdir => example_repo)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-09-22 00:00:00.000000000 Z
13
+ date: 2016-04-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -210,7 +210,7 @@ description: |
210
210
  Adapter.
211
211
  email:
212
212
  - schacon@gmail.com
213
- - dawa.ometto@phil.uu.nl
213
+ - d.ometto@gmail.com
214
214
  - jeremy@bopp.net
215
215
  executables: []
216
216
  extensions: []
@@ -225,12 +225,10 @@ files:
225
225
  - lib/git_adapter.rb
226
226
  - lib/grack.rb
227
227
  - lib/grack/app.rb
228
- - lib/grack/compatible_git_adapter.rb
229
228
  - lib/grack/file_streamer.rb
230
229
  - lib/grack/git_adapter.rb
231
230
  - lib/grack/io_streamer.rb
232
231
  - tests/app_test.rb
233
- - tests/compatible_git_adapter_test.rb
234
232
  - tests/example/_git/COMMIT_EDITMSG
235
233
  - tests/example/_git/HEAD
236
234
  - tests/example/_git/config
@@ -276,9 +274,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
276
274
  version: '0'
277
275
  required_rubygems_version: !ruby/object:Gem::Requirement
278
276
  requirements:
279
- - - '>'
277
+ - - '>='
280
278
  - !ruby/object:Gem::Version
281
- version: 1.3.1
279
+ version: '0'
282
280
  requirements: []
283
281
  rubyforge_project:
284
282
  rubygems_version: 2.2.2
@@ -288,7 +286,6 @@ summary: This project aims to replace the builtin git-http-backend CGI handler d
288
286
  with C Git with a Rack application.
289
287
  test_files:
290
288
  - tests/app_test.rb
291
- - tests/compatible_git_adapter_test.rb
292
289
  - tests/example/_git/COMMIT_EDITMSG
293
290
  - tests/example/_git/HEAD
294
291
  - tests/example/_git/config
@@ -1,99 +0,0 @@
1
- require 'pathname'
2
-
3
- require 'grack/file_streamer'
4
-
5
- module Grack
6
- ##
7
- # @deprecated Upgrade to a Git adapter implementation that implements the new
8
- # interface.
9
- #
10
- # A Git adapter adapter (yes an adapter for an adapter) that allows old-style
11
- # Git adapter classes to be used.
12
- class CompatibleGitAdapter
13
- ##
14
- # Creates a new instance of this adapter.
15
- #
16
- # @param [GitAdapter-like] adapter an old-style Git adapter instance to
17
- # wrap.
18
- def initialize(adapter)
19
- @adapter = adapter
20
- end
21
-
22
- ##
23
- # The path to the repository on which to operate.
24
- attr_reader :repository_path
25
-
26
- ##
27
- # Sets the path to the repository on which to operate.
28
- def repository_path=(path)
29
- @repository_path = Pathname.new(path)
30
- end
31
-
32
- ##
33
- # @return [Boolean] +true+ if the repository exists; otherwise, +false+.
34
- def exist?
35
- repository_path.exist?
36
- end
37
-
38
- ##
39
- # Process the pack file exchange protocol.
40
- #
41
- # @param [String] pack_type the type of pack exchange to perform.
42
- # @param [#read] io_in a readable, IO-like object providing client input
43
- # data.
44
- # @param [#write] io_out a writable, IO-like object sending output data to
45
- # the client.
46
- # @param [Hash] opts options to pass to the Git adapter's #handle_pack
47
- # method.
48
- # @option opts [Boolean] :advertise_refs (false)
49
- def handle_pack(pack_type, io_in, io_out, opts = {})
50
- msg = ''
51
- msg = io_in.read unless opts[:advertise_refs]
52
-
53
- @adapter.send(
54
- pack_type.sub(/^git-/, '').gsub('-', '_').to_sym,
55
- repository_path.to_s,
56
- opts.merge(:msg => msg)
57
- ) do |result|
58
- while chunk = result.read(8192) do
59
- io_out.write(chunk)
60
- end
61
- end
62
- end
63
-
64
- ##
65
- # Returns an object suitable for use as a Rack response body to provide the
66
- # content of a file at _path_.
67
- #
68
- # @param [Pathname] path the path to a file within the repository.
69
- #
70
- # @return [FileStreamer] a Rack response body that can stream the file
71
- # content at _path_.
72
- # @return [nil] if _path_ does not exist.
73
- def file(path)
74
- full_path = @repository_path + path
75
- return nil unless full_path.exist?
76
- FileStreamer.new(full_path)
77
- end
78
-
79
- ##
80
- # Triggers generation of data necessary to service Git Basic HTTP clients.
81
- #
82
- # @return [void]
83
- def update_server_info
84
- @adapter.update_server_info(repository_path.to_s)
85
- end
86
-
87
- ##
88
- # @return [Boolean] +true+ if pushes should be allowed; otherwise; +false+.
89
- def allow_push?
90
- @adapter.get_config_setting('receivepack') == 'true'
91
- end
92
-
93
- ##
94
- # @return [Boolean] +true+ if pulls should be allowed; otherwise; +false+.
95
- def allow_pull?
96
- @adapter.get_config_setting('uploadpack') != 'false'
97
- end
98
- end
99
- end
@@ -1,137 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- require 'minitest/autorun'
4
- require 'minitest/unit'
5
- require 'mocha/setup'
6
- require 'pathname'
7
- require 'stringio'
8
-
9
- require 'grack/compatible_git_adapter'
10
-
11
- class CompatibleGitAdapterTest < Minitest::Test
12
- include Grack
13
-
14
- def test_receive_pack
15
- mock_adapter = mock('git_adapter')
16
- mock_adapter.
17
- expects(:receive_pack).
18
- with('repo/path', :advertise_refs => true, :msg => '').
19
- yields(StringIO.new('results'))
20
- test_git = CompatibleGitAdapter.new(mock_adapter)
21
- test_git.repository_path = Pathname.new('repo/path')
22
-
23
- output = StringIO.new
24
- test_git.handle_pack(
25
- 'receive-pack', StringIO.new, output, :advertise_refs => true
26
- )
27
-
28
- assert_match 'results', output.string
29
- end
30
-
31
- def test_upload_pack
32
- mock_adapter = mock('git_adapter')
33
- mock_adapter.
34
- expects(:upload_pack).
35
- with('repo/path', :msg => 'input').
36
- yields(StringIO.new('results'))
37
- test_git = CompatibleGitAdapter.new(mock_adapter)
38
- test_git.repository_path = Pathname.new('repo/path')
39
-
40
- output = StringIO.new
41
- test_git.handle_pack('upload-pack', StringIO.new('input'), output)
42
-
43
- assert_match 'results', output.string
44
- end
45
-
46
- def test_update_server_info
47
- mock_adapter = mock('git_adapter')
48
- mock_adapter.expects(:update_server_info).with('repo/path').returns(nil)
49
- test_git = CompatibleGitAdapter.new(mock_adapter)
50
- test_git.repository_path = Pathname.new('repo/path')
51
-
52
- test_git.update_server_info
53
- end
54
-
55
- def test_exist
56
- test_git = CompatibleGitAdapter.new(nil)
57
- test_git.repository_path = Dir.pwd
58
- assert test_git.exist?
59
- test_git.repository_path = 'a/highly/unlikely/path/to/a/repository'
60
- assert ! test_git.exist?
61
- end
62
-
63
- def test_file
64
- init_example_repository
65
- test_git = CompatibleGitAdapter.new(nil)
66
- test_git.repository_path = example_repo
67
-
68
- assert_nil test_git.file('a/highly/unlikely/path/to/a/file')
69
-
70
- object_path = 'objects/31/d73eb4914a8ddb6cb0e4adf250777161118f90'
71
- file_path = File.join(example_repo, object_path)
72
- git_file = test_git.file(object_path)
73
-
74
- assert_equal file_path, git_file.to_path.to_s
75
- assert_equal File.mtime(file_path), git_file.mtime
76
- ensure
77
- remove_example_repository
78
- end
79
-
80
- def test_allow_push_with_true_setting
81
- mock_adapter = mock('git_adapter')
82
- mock_adapter.
83
- expects(:get_config_setting).
84
- with('receivepack').
85
- returns('true')
86
- test_git = CompatibleGitAdapter.new(mock_adapter)
87
-
88
- assert test_git.allow_push?, 'Expected allow_push? to return true'
89
- end
90
-
91
- def test_allow_push_with_false_setting
92
- mock_adapter = mock('git_adapter')
93
- mock_adapter.
94
- expects(:get_config_setting).
95
- with('receivepack').
96
- returns('false')
97
- test_git = CompatibleGitAdapter.new(mock_adapter)
98
-
99
- assert ! test_git.allow_push?, 'Expected allow_push? to return false'
100
- end
101
-
102
- def test_allow_push_with_no_setting
103
- mock_adapter = mock('git_adapter')
104
- mock_adapter.expects(:get_config_setting).with('receivepack').returns('')
105
- test_git = CompatibleGitAdapter.new(mock_adapter)
106
-
107
- assert ! test_git.allow_push?, 'Expected allow_push? to return false'
108
- end
109
-
110
- def test_allow_pull_with_true_setting
111
- mock_adapter = mock('git_adapter')
112
- mock_adapter.expects(:get_config_setting).with('uploadpack').returns('true')
113
- test_git = CompatibleGitAdapter.new(mock_adapter)
114
-
115
- assert test_git.allow_pull?, 'Expected allow_pull? to return true'
116
- end
117
-
118
- def test_allow_pull_with_false_setting
119
- mock_adapter = mock('git_adapter')
120
- mock_adapter.
121
- expects(:get_config_setting).
122
- with('uploadpack').
123
- returns('false')
124
- test_git = CompatibleGitAdapter.new(mock_adapter)
125
-
126
- assert ! test_git.allow_pull?, 'Expected allow_pull? to return false'
127
- end
128
-
129
- def test_allow_pull_with_no_setting
130
- mock_adapter = mock('git_adapter')
131
- mock_adapter.expects(:get_config_setting).with('uploadpack').returns('')
132
- test_git = CompatibleGitAdapter.new(mock_adapter)
133
-
134
- assert test_git.allow_pull?, 'Expected allow_pull? to return true'
135
- end
136
-
137
- end