git-lighttp 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +90 -0
- data/README.pt-BR.md +96 -0
- data/doc/releases/{v0.1.0.rdoc → v0.1.0.md} +4 -4
- data/doc/releases/{v0.2.0.rdoc → v0.2.0.md} +3 -5
- data/doc/releases/{v0.3.0.rdoc → v0.3.0.md} +3 -3
- data/doc/releases/v0.3.1.md +12 -0
- data/git-lighttp.gemspec +34 -21
- data/lib/git/lighttp.rb +100 -97
- data/lib/git/lighttp/extensions.rb +26 -30
- data/lib/git/lighttp/http_backend.rb +20 -20
- data/lib/git/lighttp/treeish.rb +2 -2
- data/lib/git/lighttp/version.rb +3 -3
- metadata +79 -71
- data/Gemfile +0 -11
- data/Makefile +0 -41
- data/README.pt-BR.rdoc +0 -81
- data/README.rdoc +0 -75
- data/Rakefile +0 -50
- data/test/all.rb +0 -12
- data/test/config_test.rb +0 -43
- data/test/fixtures/config.yml +0 -13
- data/test/fixtures/htgroup +0 -3
- data/test/fixtures/htpasswd +0 -4
- data/test/fixtures/mycode.git/HEAD +0 -1
- data/test/fixtures/mycode.git/config +0 -4
- data/test/fixtures/mycode.git/description +0 -1
- data/test/fixtures/mycode.git/hooks/applypatch-msg.sample +0 -15
- data/test/fixtures/mycode.git/hooks/commit-msg.sample +0 -24
- data/test/fixtures/mycode.git/hooks/post-commit.sample +0 -8
- data/test/fixtures/mycode.git/hooks/post-receive.sample +0 -15
- data/test/fixtures/mycode.git/hooks/post-update.sample +0 -8
- data/test/fixtures/mycode.git/hooks/pre-applypatch.sample +0 -14
- data/test/fixtures/mycode.git/hooks/pre-commit.sample +0 -46
- data/test/fixtures/mycode.git/hooks/pre-rebase.sample +0 -169
- data/test/fixtures/mycode.git/hooks/prepare-commit-msg.sample +0 -36
- data/test/fixtures/mycode.git/hooks/update.sample +0 -128
- data/test/fixtures/mycode.git/info/exclude +0 -6
- data/test/fixtures/mycode.git/info/refs +0 -3
- data/test/fixtures/mycode.git/objects/02/83eb96425444e17b97182e1ba9f216cc67c132 +0 -0
- data/test/fixtures/mycode.git/objects/03/9927042df267a1bc606fc4485b7a79b6a9e3cd +0 -1
- data/test/fixtures/mycode.git/objects/0d/eed0a56fa8f5f2a788d58b3ea235afd547b828 +0 -2
- data/test/fixtures/mycode.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
- data/test/fixtures/mycode.git/objects/5e/54a0767e0c380f3baab17938d68c7f464cf171 +0 -1
- data/test/fixtures/mycode.git/objects/63/9b96262e7e19ca2169575e797b234098b8a72e +0 -0
- data/test/fixtures/mycode.git/objects/71/6e9568eed27d5ee4378b3ecf6dd095a547bde9 +0 -1
- data/test/fixtures/mycode.git/objects/b6/f3f0fabeaaaaf2db22b8ef98f59115baec7ef9 +0 -0
- data/test/fixtures/mycode.git/objects/be/118435b9d908fd4a689cd8b0cc98059911a31a +0 -0
- data/test/fixtures/mycode.git/objects/db/aefcb5bde664671c73b99515c386dcbc7f22b6 +0 -0
- data/test/fixtures/mycode.git/objects/eb/669b878d2013ac70aa5dee75e6357ea81d16ea +0 -0
- data/test/fixtures/mycode.git/objects/ed/10cfcf72862e140c97fe899cba2a55f4cb4c20 +0 -0
- data/test/fixtures/mycode.git/objects/ed/1c3a255ab3fce056dc31cd82df9f61a4d9fa22 +0 -0
- data/test/fixtures/mycode.git/objects/info/alternates +0 -0
- data/test/fixtures/mycode.git/objects/info/http-alternates +0 -0
- data/test/fixtures/mycode.git/objects/info/packs +0 -2
- data/test/fixtures/mycode.git/objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.idx +0 -0
- data/test/fixtures/mycode.git/objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.pack +0 -0
- data/test/fixtures/mycode.git/packed-refs +0 -4
- data/test/fixtures/mycode.git/refs/heads/master +0 -1
- data/test/fixtures/mycode.git/refs/tags/v0.1.0 +0 -1
- data/test/helpers.rb +0 -53
- data/test/htgroup_test.rb +0 -29
- data/test/htpasswd_test.rb +0 -63
- data/test/http_backend_authentication_test.rb +0 -61
- data/test/http_backend_test.rb +0 -123
- data/test/project_handler_test.rb +0 -45
- data/test/treeish_test.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2163ddb50b5ced5e4bcb6fdc020f29751d53a63
|
4
|
+
data.tar.gz: a8023e7eb5264c37566ae375605adaba5a7f93db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f8e79c04657f04213d7063657a078e3a1b8be0e7c4ac0449620da5964cb4f2eb1b593c663ee7a104c105334dfc06b33ecf39aba2abedce05fde2a98089eb49b
|
7
|
+
data.tar.gz: af3321617dfd01fb433d9b82335cd7d0753409fb5a03ced2fcc04491fe7517f51233ab742be504600e027d174c6a14c392565369d59769fbef966edcd59f6feb
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2011-2016 Hallison Batista
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Git-Lighttp - Web light end smarty for Git
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/git-lighttp)
|
4
|
+
[](https://travis-ci.org/hallison/git-lighttp)
|
5
|
+
[](https://codeclimate.com/github/hallison/git-lighttp)
|
6
|
+
[](http://inch-ci.org/github/hallison/git-lighttp)
|
7
|
+
|
8
|
+
## DESCRIPTION
|
9
|
+
|
10
|
+
This project was inspired in the [Grack][1] Smart-HTTP server handler (written
|
11
|
+
by [Scott Chacon][2]) but developed using [Sinatra][3] and aims replace the
|
12
|
+
original `git-http-backend` including new features.
|
13
|
+
|
14
|
+
The main goal of the **Git-Lighttp** is implement the following useful features.
|
15
|
+
|
16
|
+
- Smart-HTTP, based on _git-http-backend_.
|
17
|
+
- Authentication flexible based on database or configuration file like `htpasswd`.
|
18
|
+
- Authorization flexible based on database or configuration file like `htgroup`.
|
19
|
+
- API to get information about repository (_Treeish_).
|
20
|
+
|
21
|
+
## SINOPSIS
|
22
|
+
|
23
|
+
Install the Git-Lighttp using [Rubygems][4].
|
24
|
+
|
25
|
+
$ gem install git-lighttp
|
26
|
+
|
27
|
+
Or checkout the project hosted on [Gitlab][5] or [Github][6].
|
28
|
+
|
29
|
+
$ git clone https://gitlab.com/hallison/git-lighttp.git
|
30
|
+
$ ...
|
31
|
+
$ cd git-lighttp
|
32
|
+
$ make install
|
33
|
+
|
34
|
+
Configure the Rackup file (`config.ru`) using the following instructions:
|
35
|
+
|
36
|
+
# config.ru
|
37
|
+
require "git/lighttp"
|
38
|
+
|
39
|
+
Git::Lighttp::HttpBackend.configure do |server|
|
40
|
+
server.project_root = "/home/git/repositories"
|
41
|
+
server.git_path = "/usr/bin/git"
|
42
|
+
server.get_any_file = true
|
43
|
+
server.upload_pack = true
|
44
|
+
server.receive_pack = false
|
45
|
+
server.authenticate = true
|
46
|
+
end
|
47
|
+
|
48
|
+
run Git::Lighttp::HttpBackend
|
49
|
+
|
50
|
+
And run:
|
51
|
+
|
52
|
+
$ rackup --port 9092 --daemonize
|
53
|
+
$ git clone http://localhost:9092/mycode.git
|
54
|
+
|
55
|
+
You can use the `.netrc` for improve your connection. Put this:
|
56
|
+
|
57
|
+
machine <host> login <username> password <password>
|
58
|
+
|
59
|
+
The Git-Lighttp is under development, so there are still many improvements to
|
60
|
+
be made. Please, help us to improve the project sending your feedback to
|
61
|
+
[issues][7] or sending email to [hallisonbatista@gmail.com][8].
|
62
|
+
|
63
|
+
Discuss in [Google Groups][9].
|
64
|
+
|
65
|
+
## AUTHORS
|
66
|
+
|
67
|
+
Written by Hallison Batista <hallisonbatista@gmail.com>.
|
68
|
+
|
69
|
+
## BUGS
|
70
|
+
|
71
|
+
If you find a bug, please report it at the Git-Lighttp project's
|
72
|
+
issues tracker on [Gitlab][5] or [Github][6].
|
73
|
+
|
74
|
+
## LICENSE
|
75
|
+
|
76
|
+
Git-Lighttp is Copyright (c) 2011-2016 Hallison Batista.
|
77
|
+
|
78
|
+
This is free software, and may be redistributed under the terms specified in
|
79
|
+
LICENSE.txt.
|
80
|
+
|
81
|
+
[1]: http://github.com/schacon/grack
|
82
|
+
[2]: http://github.com/schacon
|
83
|
+
[3]: http://www.sinatrarb.com
|
84
|
+
[4]: http://rubygems.org/gems/git-lighttp
|
85
|
+
[5]: http://gitlab.com/hallison/git-lighttp
|
86
|
+
[6]: http://github.com/hallison/git-lighttp
|
87
|
+
[7]: http://gitlab.com/hallison/git-lighttp/issues
|
88
|
+
[8]: mailto:hallisonbatista@gmail.com
|
89
|
+
[9]: http://groups.google.com/group/git-lighttp
|
90
|
+
|
data/README.pt-BR.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Git-Lighttp - Web mais leve e esperta para o Git
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/git-lighttp)
|
4
|
+
[](https://travis-ci.org/hallison/git-lighttp)
|
5
|
+
[](https://codeclimate.com/github/hallison/git-lighttp)
|
6
|
+
[](http://inch-ci.org/github/hallison/git-lighttp)
|
7
|
+
|
8
|
+
## DESCRIÇÃO
|
9
|
+
|
10
|
+
Este projeto foi inspirado no [Grack][1], um servidor de processos Smart-HTTP
|
11
|
+
(escrito por [Scott Chacon][2], mas projetado usando [Sinatra][3] e visa
|
12
|
+
substituir o `git-http-backend` original incluindo novas funcionalidades.
|
13
|
+
|
14
|
+
O objetivo principal do **Git-Lighttp** é implementar as seguintes
|
15
|
+
funcionalidades:
|
16
|
+
|
17
|
+
- Smart-HTTP, baseado no _git-http-backend_.
|
18
|
+
- Autenticação flexível baseado em banco de dados ou arquivo de configuração
|
19
|
+
como `htpasswd`.
|
20
|
+
- Autorização básica baseado em banco de dados ou arquivo de configuração
|
21
|
+
como o `htgroup`.
|
22
|
+
- API para obter informações sobre o repositório (_Treeish_).
|
23
|
+
|
24
|
+
## SINOPSE
|
25
|
+
|
26
|
+
Instale o Git-Lighttp usando [Rubygems][4].
|
27
|
+
|
28
|
+
$ gem install git-lighttp
|
29
|
+
|
30
|
+
Ou faça um _checkout_ do projeto hospedado no [Gitlab][5] ou no [Github][6].
|
31
|
+
|
32
|
+
$ git clone https://gitlab.com/hallison/git-lighttp.git
|
33
|
+
...
|
34
|
+
$ cd git-lighttp
|
35
|
+
$ make install
|
36
|
+
|
37
|
+
Configure o arquivo Rackup (+config.ru+) usando as seguintes instruções:
|
38
|
+
|
39
|
+
# config.ru
|
40
|
+
require "git/lighttp"
|
41
|
+
|
42
|
+
Git::Lighttp::HttpBackend.configure do |server|
|
43
|
+
server.project_root = "/home/git/repositories"
|
44
|
+
server.git_path = "/usr/bin/git"
|
45
|
+
server.get_any_file = true
|
46
|
+
server.upload_pack = true
|
47
|
+
server.receive_pack = false
|
48
|
+
server.authenticate = true
|
49
|
+
end
|
50
|
+
|
51
|
+
run Git::Lighttp::HttpBackend
|
52
|
+
|
53
|
+
E execute:
|
54
|
+
|
55
|
+
$ rackup --port 9092 --daemonize
|
56
|
+
$ git clone http://localhost:9092/mycode.git
|
57
|
+
|
58
|
+
Você poderá usar o arquivo `.netrc` para melhorar sua conexão. Coloque
|
59
|
+
isso:
|
60
|
+
|
61
|
+
machine <servidor> login <usuario> password <senha>
|
62
|
+
|
63
|
+
O Git-Lighttp está em desenvolvimento, então ainda há muitas melhorias a serem
|
64
|
+
feitas. Por favor, nos ajude a melhorar o projeto enviando seu comentário nos
|
65
|
+
[problemas][7] encontrados ou enviando um email para
|
66
|
+
[hallisonbatista@gmail.com][8].
|
67
|
+
|
68
|
+
Discuta no [Google Groups][9].
|
69
|
+
|
70
|
+
## AUTORES
|
71
|
+
|
72
|
+
Escrito por Hallison Batista <hallisonbatista@gmail.com>.
|
73
|
+
|
74
|
+
## ERROS
|
75
|
+
|
76
|
+
Se você encontrar um erro, por favor, informe no
|
77
|
+
gerenciador de erros do projeto
|
78
|
+
Git-Lighttp no [Gitlab][5] ou no [Github][6].
|
79
|
+
|
80
|
+
## LICENÇA
|
81
|
+
|
82
|
+
Git-Lighttp é Copyright (c) 2011-2016 Hallison Batista.
|
83
|
+
|
84
|
+
Este é um _software_ livre e pode ser redistribuído sob os termos
|
85
|
+
especificados em LICENSE.txt.
|
86
|
+
|
87
|
+
[1]: http://github.com/schacon/grack
|
88
|
+
[2]: http://github.com/schacon
|
89
|
+
[3]: http://www.sinatrarb.com
|
90
|
+
[4]: http://rubygems.org/gems/git-lighttp
|
91
|
+
[5]: http://gitlab.com/hallison/git-lighttp
|
92
|
+
[6]: http://github.com/hallison/git-lighttp
|
93
|
+
[7]: http://gitlab.com/hallison/git-lighttp/issues
|
94
|
+
[8]: mailto:hallisonbatista@gmail.com
|
95
|
+
[9]: http://groups.google.com/group/git-lighttp
|
96
|
+
|
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
Git-Lighttp v0.1.0
|
2
|
+
------------------
|
2
3
|
|
3
4
|
Implementation of the basic features:
|
4
5
|
|
5
6
|
- Smart-HTTP implementation.
|
6
|
-
- Authentication using
|
7
|
+
- Authentication using `htpasswd` features (only crypt algorithm).
|
7
8
|
- Basic configuration in Rackup file.
|
8
9
|
|
9
10
|
This is a beta version. For more informations about this release,
|
10
|
-
please visit <http://
|
11
|
-
|
11
|
+
please visit <http://gitlab.com/hallison/git-lighttp>.
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
Git-Lighttp v0.2.0
|
2
|
+
------------------
|
2
3
|
|
3
4
|
Implementation of viewer for browsing of source code:
|
4
5
|
|
@@ -18,7 +19,4 @@ Implementation of viewer for browsing of source code:
|
|
18
19
|
- Small improvements in helpers and tests.
|
19
20
|
|
20
21
|
This is a beta version. For more informations about this release,
|
21
|
-
please visit <http://
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
please visit <http://gitlab.com/hallison/git-lighttp>.
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
Git-Lighttp v0.3.0
|
2
|
+
------------------
|
2
3
|
|
3
4
|
Improvements and new features.
|
4
5
|
|
@@ -9,5 +10,4 @@ Improvements and new features.
|
|
9
10
|
- The project renamed from Git-Webby to Git-Lighttp.
|
10
11
|
|
11
12
|
This is a beta version. For more informations about this release,
|
12
|
-
please visit <http://
|
13
|
-
|
13
|
+
please visit <http://gitlab.com/hallison/git-lighttp>.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Git-Lighttp v0.3.1
|
2
|
+
------------------
|
3
|
+
|
4
|
+
Improvements.
|
5
|
+
|
6
|
+
- Documentation improved using Markdown.
|
7
|
+
- Code improved using Rubocop.
|
8
|
+
- Fixes in tests and configurations (Travis CI, Gitlab CI).
|
9
|
+
- Gemspec improved and cleaned.
|
10
|
+
|
11
|
+
This is a beta version. For more informations about this release,
|
12
|
+
please visit <http://gitlab.com/hallison/git-lighttp>.
|
data/git-lighttp.gemspec
CHANGED
@@ -1,25 +1,38 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift 'lib' unless $LOAD_PATH.include? 'lib'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
require 'git/lighttp/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |g|
|
6
|
+
g.platform = Gem::Platform::RUBY
|
7
|
+
g.name = 'git-lighttp'
|
8
|
+
g.summary = 'Git Web implementation of the Light (Smart) HTTP'
|
9
|
+
g.authors = ['Hallison Batista']
|
10
|
+
g.email = 'hallisonbatista@gmail.com'
|
11
|
+
g.homepage = 'https://gitlab.com/hallison/git-lighttp'
|
12
|
+
g.version = Git::Lighttp::VERSION
|
13
|
+
g.date = Git::Lighttp::RELEASE
|
14
|
+
g.licenses = ['MIT']
|
15
|
+
|
16
|
+
g.test_files = g.files.select do |path|
|
17
|
+
path =~ %r{^test/.*}
|
17
18
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
|
20
|
+
g.files = %x(git ls-files).split.reject do |out|
|
21
|
+
ignore = out =~ /([MR]ake|Gem)file/ || out =~ /^\./
|
22
|
+
ignore = ignore || out =~ %r{^doc/api} || out =~ %r{^test/.*}
|
23
|
+
ignore
|
22
24
|
end
|
23
|
-
|
24
|
-
|
25
|
+
g.description = <<-end
|
26
|
+
Git::Lighttp is a implementation of the several features:
|
27
|
+
- Smart HTTP which works like as git-http-backend.
|
28
|
+
- Show info pages about the projects.
|
29
|
+
end
|
30
|
+
g.add_dependency 'sinatra', '~> 1.4'
|
31
|
+
g.add_dependency 'json', '~> 1.8'
|
32
|
+
|
33
|
+
g.add_development_dependency 'minitest', '~> 5.8'
|
34
|
+
g.add_development_dependency 'minitest-rg', '~> 5.2'
|
35
|
+
g.add_development_dependency 'rack-test', '~> 0.6'
|
25
36
|
|
37
|
+
g.require_paths = ['lib']
|
38
|
+
end
|
data/lib/git/lighttp.rb
CHANGED
@@ -1,34 +1,32 @@
|
|
1
1
|
# Standard requirements
|
2
|
-
require
|
2
|
+
require 'yaml'
|
3
3
|
|
4
4
|
# 3rd part requirements
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require 'sinatra/base'
|
6
|
+
require 'json'
|
7
7
|
|
8
8
|
# Internal requirements
|
9
|
-
require
|
10
|
-
require
|
9
|
+
require 'git/lighttp/extensions'
|
10
|
+
require 'git/lighttp/version'
|
11
11
|
|
12
|
-
# See
|
12
|
+
# See *Git::Lighttp* for documentation.
|
13
13
|
module Git
|
14
|
-
|
15
|
-
# The main goal of the <b>Git::Lighttp</b> is implement the following useful
|
16
|
-
# features.
|
14
|
+
# Module wich implements the following features:
|
17
15
|
#
|
18
|
-
# - Smart-HTTP, based on
|
19
|
-
# - Authentication flexible based on database or configuration file like
|
16
|
+
# - Smart-HTTP, based on +git-http-backend+.
|
17
|
+
# - Authentication flexible based on database or configuration file like
|
18
|
+
# +.htpasswd+.
|
20
19
|
# - API to get information about repository.
|
21
20
|
#
|
22
|
-
# This class configure the needed variables used by application.
|
23
|
-
#
|
24
|
-
#
|
21
|
+
# This class configure the needed variables used by application.
|
22
|
+
#
|
25
23
|
# Basically, the +default+ attribute set the values that will be necessary
|
26
24
|
# by all applications.
|
27
25
|
#
|
28
|
-
# The HTTP-Backend application is configured by +http_backend+ attribute
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# page}[http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html]
|
26
|
+
# The HTTP-Backend application is configured by +http_backend+ attribute to
|
27
|
+
# set the Git RCP CLI. More details about this feature, see
|
28
|
+
# +git-http-backend+ {official
|
29
|
+
# page}[http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html].
|
32
30
|
#
|
33
31
|
# For tree view (JSON API) just use the attribute +treeish+.
|
34
32
|
#
|
@@ -36,36 +34,34 @@ module Git
|
|
36
34
|
# Default configuration. All attributes will be used by all modular
|
37
35
|
# applications.
|
38
36
|
#
|
39
|
-
# *project_root* ::
|
37
|
+
# *default.project_root* ::
|
40
38
|
# Sets the root directory where repositories have been
|
41
39
|
# placed.
|
42
|
-
# *git_path* ::
|
40
|
+
# *default.git_path* ::
|
43
41
|
# Path to the git command line.
|
44
42
|
#
|
45
43
|
# [*treeish*]
|
46
44
|
# Configuration for Treeish JSON API.
|
47
45
|
#
|
48
|
-
# *authenticate* ::
|
46
|
+
# *treeish.authenticate* ::
|
49
47
|
# Sets if the tree view server requires authentication.
|
50
48
|
#
|
51
49
|
# [*http_backend*]
|
52
50
|
# HTTP-Backend configuration.
|
53
51
|
#
|
54
|
-
# *authenticate* ::
|
52
|
+
# *http_backend.authenticate* ::
|
55
53
|
# Sets if authentication is required.
|
56
54
|
#
|
57
|
-
# *get_any_file* ::
|
55
|
+
# *http_backend.get_any_file* ::
|
58
56
|
# Like +http.getanyfile+.
|
59
57
|
#
|
60
|
-
# *upload_pack* ::
|
58
|
+
# *http_backend.upload_pack* ::
|
61
59
|
# Like +http.uploadpack+.
|
62
60
|
#
|
63
|
-
# *receive_pack* ::
|
61
|
+
# *http_backend.receive_pack* ::
|
64
62
|
# Like +http.receivepack+.
|
65
63
|
module Lighttp
|
66
|
-
|
67
64
|
class ProjectHandler #:nodoc:
|
68
|
-
|
69
65
|
# Path to git comamnd
|
70
66
|
attr_reader :path
|
71
67
|
|
@@ -73,14 +69,14 @@ module Git
|
|
73
69
|
|
74
70
|
attr_reader :repository
|
75
71
|
|
76
|
-
def initialize(project_root, path =
|
72
|
+
def initialize(project_root, path = '/usr/bin/git')
|
77
73
|
@repository = nil
|
78
74
|
@path = check_path(File.expand_path(path))
|
79
75
|
@project_root = check_path(File.expand_path(project_root))
|
80
76
|
end
|
81
77
|
|
82
78
|
def path_to(*args)
|
83
|
-
File.join(@repository || @project_root, *
|
79
|
+
File.join(@repository || @project_root, *args.compact.map(&:to_s))
|
84
80
|
end
|
85
81
|
|
86
82
|
def repository=(name)
|
@@ -88,11 +84,11 @@ module Git
|
|
88
84
|
end
|
89
85
|
|
90
86
|
def cli(command, *args)
|
91
|
-
|
87
|
+
"#{@path} #{args.unshift(command.to_s.tr('_', '-')).compact.join(' ')}"
|
92
88
|
end
|
93
89
|
|
94
90
|
def run(command, *args)
|
95
|
-
chdir{ %x
|
91
|
+
chdir { %x(#{cli command, *args}) }
|
96
92
|
end
|
97
93
|
|
98
94
|
def read_file(*file)
|
@@ -111,32 +107,42 @@ module Git
|
|
111
107
|
path_to(:objects, :info, :packs)
|
112
108
|
end
|
113
109
|
|
114
|
-
def tree(ref =
|
110
|
+
def tree(ref = 'HEAD', path = '')
|
115
111
|
list = run("ls-tree --abbrev=6 --full-tree --long #{ref}:#{path}")
|
116
112
|
if list
|
117
113
|
tree = []
|
118
|
-
|
114
|
+
pattern = /^
|
115
|
+
(?<ty>\d{3})
|
116
|
+
(?<pu>\d)
|
117
|
+
(?<pg>\d)
|
118
|
+
(?<po>\d)[ ]
|
119
|
+
(?<ot>\w.*?)[ ]
|
120
|
+
(?<oh>.{6})[ \t]{0,}
|
121
|
+
(?<sz>.*?)\t
|
122
|
+
(?<nm>.*?)\n
|
123
|
+
/mux
|
124
|
+
list.scan pattern do |ty, pu, pg, po, ot, oh, sz, nm|
|
119
125
|
object = {
|
120
|
-
:
|
121
|
-
:
|
122
|
-
:
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
126
|
+
ftype: ftype[ty],
|
127
|
+
fperm: "#{fperm[pu.to_i]}#{fperm[pg.to_i]}#{fperm[po.to_i]}",
|
128
|
+
otype: ot.to_sym,
|
129
|
+
ohash: oh,
|
130
|
+
fsize: fsize(sz, 2),
|
131
|
+
fname: nm
|
126
132
|
}
|
127
133
|
object[:objects] = nil if object[:otype] == :tree
|
128
134
|
tree << object
|
129
135
|
end
|
130
136
|
tree
|
131
137
|
else
|
132
|
-
|
138
|
+
false
|
133
139
|
end
|
134
140
|
end
|
135
141
|
|
136
142
|
private
|
137
143
|
|
138
144
|
def repository_path(name)
|
139
|
-
bare = name =~ /\w\.git/ ? name : %W
|
145
|
+
bare = name =~ /\w\.git/ ? name : %W(#{name} .git)
|
140
146
|
check_path(path_to(*bare))
|
141
147
|
end
|
142
148
|
|
@@ -149,29 +155,30 @@ module Git
|
|
149
155
|
end
|
150
156
|
|
151
157
|
def ftype
|
152
|
-
{
|
158
|
+
{ '120' => 'l', '100' => '-', '040' => 'd' }
|
153
159
|
end
|
154
160
|
|
155
161
|
def fperm
|
156
|
-
[
|
162
|
+
['---', '--x', '-w-', '-wx', 'r--', 'r-x', 'rw-', 'rwx']
|
157
163
|
end
|
158
164
|
|
159
165
|
def fsize(str, scale = 1)
|
160
|
-
units = [
|
166
|
+
units = [:b, :kb, :mb, :gb, :tb]
|
161
167
|
value = str.to_f
|
162
168
|
size = 0.0
|
163
169
|
units.each_index do |i|
|
164
170
|
size = value / 1024**i
|
165
|
-
return [
|
171
|
+
return [
|
172
|
+
format("%.#{scale}f", size).to_f,
|
173
|
+
units[i].to_s.upcase
|
174
|
+
] if size <= 10
|
166
175
|
end
|
167
176
|
end
|
168
|
-
|
169
177
|
end
|
170
178
|
|
171
179
|
class Htpasswd #:nodoc:
|
172
|
-
|
173
180
|
def initialize(file)
|
174
|
-
require
|
181
|
+
require 'webrick/httpauth/htpasswd'
|
175
182
|
@handler = WEBrick::HTTPAuth::Htpasswd.new(file)
|
176
183
|
yield self if block_given?
|
177
184
|
end
|
@@ -179,14 +186,14 @@ module Git
|
|
179
186
|
def find(username) #:yield: password, salt
|
180
187
|
password = @handler.get_passwd(nil, username, false)
|
181
188
|
if block_given?
|
182
|
-
yield password ? [password, password[0,2]] : [nil, nil]
|
189
|
+
yield password ? [password, password[0, 2]] : [nil, nil]
|
183
190
|
else
|
184
191
|
password
|
185
192
|
end
|
186
193
|
end
|
187
194
|
|
188
195
|
def authenticated?(username, password)
|
189
|
-
|
196
|
+
find username do |crypted, salt|
|
190
197
|
crypted && salt && crypted == password.crypt(salt)
|
191
198
|
end
|
192
199
|
end
|
@@ -215,14 +222,13 @@ module Git
|
|
215
222
|
private
|
216
223
|
|
217
224
|
def users
|
218
|
-
@handler.each{|username,
|
225
|
+
@handler.each { |username, _password| username }
|
219
226
|
end
|
220
227
|
end
|
221
228
|
|
222
229
|
class Htgroup #:nodoc:
|
223
|
-
|
224
230
|
def initialize(file)
|
225
|
-
require
|
231
|
+
require 'webrick/httpauth/htgroup'
|
226
232
|
WEBrick::HTTPAuth::Htgroup.class_eval do
|
227
233
|
attr_reader :group
|
228
234
|
end
|
@@ -235,15 +241,13 @@ module Git
|
|
235
241
|
end
|
236
242
|
|
237
243
|
def groups(username)
|
238
|
-
@handler.group.select do |
|
244
|
+
@handler.group.select do |_group, members|
|
239
245
|
members.include? username
|
240
246
|
end.keys
|
241
247
|
end
|
242
|
-
|
243
248
|
end
|
244
249
|
|
245
250
|
module GitHelpers #:nodoc:
|
246
|
-
|
247
251
|
def git
|
248
252
|
@git ||= ProjectHandler.new(settings.project_root, settings.git_path)
|
249
253
|
end
|
@@ -254,15 +258,13 @@ module Git
|
|
254
258
|
end
|
255
259
|
|
256
260
|
def content_type_for_git(name, *suffixes)
|
257
|
-
content_type("application/x-git-#{name}-#{suffixes.compact.join(
|
261
|
+
content_type("application/x-git-#{name}-#{suffixes.compact.join('-')}")
|
258
262
|
end
|
259
|
-
|
260
263
|
end
|
261
264
|
|
262
265
|
module AuthenticationHelpers #:nodoc:
|
263
|
-
|
264
266
|
def htpasswd
|
265
|
-
@htpasswd ||= Htpasswd.new(git.path_to(
|
267
|
+
@htpasswd ||= Htpasswd.new(git.path_to('htpasswd'))
|
266
268
|
end
|
267
269
|
|
268
270
|
def authentication
|
@@ -270,28 +272,28 @@ module Git
|
|
270
272
|
end
|
271
273
|
|
272
274
|
def authenticated?
|
273
|
-
request.env[
|
275
|
+
request.env['REMOTE_USER'] && request.env['git.lighttp.authenticated']
|
274
276
|
end
|
275
277
|
|
276
278
|
def authenticate(username, password)
|
277
|
-
checked = [
|
279
|
+
checked = [username, password] == authentication.credentials
|
278
280
|
validated = authentication.provided? && authentication.basic?
|
279
281
|
granted = htpasswd.authenticated? username, password
|
280
|
-
if checked
|
281
|
-
request.env[
|
282
|
-
request.env[
|
282
|
+
if checked && validated && granted
|
283
|
+
request.env['git.lighttp.authenticated'] = true
|
284
|
+
request.env['REMOTE_USER'] = authentication.username
|
283
285
|
else
|
284
|
-
|
286
|
+
false
|
285
287
|
end
|
286
288
|
end
|
287
289
|
|
288
|
-
def unauthorized!(realm = Git::Lighttp
|
289
|
-
headers
|
290
|
-
throw :halt, [
|
290
|
+
def unauthorized!(realm = Git::Lighttp.info)
|
291
|
+
headers 'WWW-Authenticate' => %(Basic realm="#{realm}")
|
292
|
+
throw :halt, [401, 'Authorization Required']
|
291
293
|
end
|
292
294
|
|
293
295
|
def bad_request!
|
294
|
-
throw :halt, [
|
296
|
+
throw :halt, [400, 'Bad Request']
|
295
297
|
end
|
296
298
|
|
297
299
|
def authenticate!
|
@@ -299,7 +301,7 @@ module Git
|
|
299
301
|
unauthorized! unless authentication.provided?
|
300
302
|
bad_request! unless authentication.basic?
|
301
303
|
unauthorized! unless authenticate(*authentication.credentials)
|
302
|
-
request.env[
|
304
|
+
request.env['REMOTE_USER'] = authentication.username
|
303
305
|
end
|
304
306
|
|
305
307
|
def access_granted?(username, password)
|
@@ -309,31 +311,37 @@ module Git
|
|
309
311
|
end # AuthenticationHelpers
|
310
312
|
|
311
313
|
# Servers
|
312
|
-
autoload :HttpBackend,
|
313
|
-
autoload :Treeish,
|
314
|
+
autoload :HttpBackend, 'git/lighttp/http_backend'
|
315
|
+
autoload :Treeish, 'git/lighttp/treeish'
|
314
316
|
|
315
317
|
class << self
|
316
318
|
|
319
|
+
DEFAULT_CONFIG = {
|
320
|
+
default: {
|
321
|
+
project_root: '/home/git',
|
322
|
+
git_path: '/usr/bin/git'
|
323
|
+
},
|
324
|
+
treeish: {
|
325
|
+
authenticate: false
|
326
|
+
},
|
327
|
+
http_backend: {
|
328
|
+
authenticate: true,
|
329
|
+
get_any_file: true,
|
330
|
+
upload_pack: true,
|
331
|
+
receive_pack: false
|
332
|
+
}
|
333
|
+
}.freeze
|
334
|
+
|
317
335
|
def config
|
318
|
-
@config ||=
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
:treeish => {
|
324
|
-
:authenticate => false
|
325
|
-
},
|
326
|
-
:http_backend => {
|
327
|
-
:authenticate => true,
|
328
|
-
:get_any_file => true,
|
329
|
-
:upload_pack => true,
|
330
|
-
:receive_pack => false
|
331
|
-
}
|
332
|
-
}.to_struct
|
336
|
+
@config ||= DEFAULT_CONFIG.to_struct
|
337
|
+
end
|
338
|
+
|
339
|
+
def config_reset!
|
340
|
+
@config = DEFAULT_CONFIG.to_struct
|
333
341
|
end
|
334
342
|
|
335
343
|
# Configure Git::Lighttp modules using keys. See Config for options.
|
336
|
-
def configure(
|
344
|
+
def configure(*) # :yield: config
|
337
345
|
yield config
|
338
346
|
config
|
339
347
|
end
|
@@ -345,21 +353,16 @@ module Git
|
|
345
353
|
end
|
346
354
|
end
|
347
355
|
config
|
348
|
-
rescue IndexError
|
349
|
-
abort
|
356
|
+
rescue IndexError
|
357
|
+
abort 'configuration option not found'
|
350
358
|
end
|
351
|
-
|
352
359
|
end
|
353
360
|
|
354
361
|
class Application < Sinatra::Base #:nodoc:
|
355
|
-
|
356
362
|
set :project_root, lambda { Git::Lighttp.config.default.project_root }
|
357
363
|
set :git_path, lambda { Git::Lighttp.config.default.git_path }
|
358
364
|
|
359
|
-
mime_type :json,
|
360
|
-
|
365
|
+
mime_type :json, 'application/json'
|
361
366
|
end
|
362
|
-
|
363
367
|
end
|
364
|
-
|
365
368
|
end
|