dtk-common 0.5.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +16 -0
- data/LICENSE +674 -0
- data/README.md +36 -0
- data/dtk-common.gemspec +23 -0
- data/lib/common_patch.rb +16 -0
- data/lib/dsl/directory_parser/git.rb +39 -0
- data/lib/dsl/directory_parser/linux.rb +21 -0
- data/lib/dsl/directory_parser.rb +77 -0
- data/lib/dsl/file_parser/file_types/assembly/v2/assembly.rb +53 -0
- data/lib/dsl/file_parser/file_types/component_module_refs/v1/component_module_refs.rb +57 -0
- data/lib/dsl/file_parser.rb +228 -0
- data/lib/dsl.rb +23 -0
- data/lib/dtk-common/version.rb +3 -0
- data/lib/dtk_common.rb +36 -0
- data/lib/dynamic_loader.rb +28 -0
- data/lib/git_repo/adapters/rugged/blob.rb +14 -0
- data/lib/git_repo/adapters/rugged/commit.rb +14 -0
- data/lib/git_repo/adapters/rugged/common.rb +34 -0
- data/lib/git_repo/adapters/rugged/tree.rb +40 -0
- data/lib/git_repo/adapters/rugged.rb +45 -0
- data/lib/git_repo.rb +93 -0
- data/lib/gitolite/configuration.rb +35 -0
- data/lib/gitolite/errors.rb +5 -0
- data/lib/gitolite/grit/adapter.rb +101 -0
- data/lib/gitolite/grit/file_access.rb +51 -0
- data/lib/gitolite/init.rb +16 -0
- data/lib/gitolite/manager.rb +158 -0
- data/lib/gitolite/repo.rb +171 -0
- data/lib/gitolite/user_group.rb +98 -0
- data/lib/gitolite/utils.rb +59 -0
- data/lib/grit_adapter/file_access/diff.rb +82 -0
- data/lib/grit_adapter/file_access/status.rb +25 -0
- data/lib/grit_adapter/file_access.rb +296 -0
- data/lib/grit_adapter/object_access.rb +39 -0
- data/lib/grit_adapter.rb +212 -0
- data/lib/module_version.rb +12 -0
- data/lib/require_first.rb +18 -0
- data/rich_tests/README.md +1 -0
- data/rich_tests/dsl_test1.rb +14 -0
- data/rich_tests/dsl_test2.rb +10 -0
- data/rich_tests/dsl_test3.rb +17 -0
- data/rich_tests/dsl_test4.rb +25 -0
- data/rich_tests/fixtures/dsl_test1/sm-dtk-bootstrap/global_module_refs.json +2 -0
- data/rich_tests/fixtures/dsl_test1/sm-dtk-dtk/global_module_refs.json +7 -0
- data/rich_tests/fixtures/dsl_test1/sm-dtk-test_dtk/global_module_refs.json +8 -0
- data/rich_tests/fixtures/dsl_test1/sm-dtk-test_postgres/global_module_refs.json +7 -0
- data/rich_tests/fixtures/dsl_test1/sm-dtk-test_service/global_module_refs.json +5 -0
- data/rich_tests/fixtures/dsl_test1/sm-dtk-testv1/global_module_refs.json +14 -0
- data/rich_tests/fixtures/dsl_test1/sm-rich-app/global_module_refs.json +5 -0
- data/rich_tests/fixtures/dsl_test1/sm-rich-hdp/global_module_refs.json +3 -0
- data/rich_tests/fixtures/dsl_test1/sm-rich-test_dtk/global_module_refs.json +5 -0
- data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/message_bus/assembly.json +23 -0
- data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/repo_manager/assembly.json +26 -0
- data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/server-nginx/assembly.json +64 -0
- data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/server-on-one-node/assembly.json +47 -0
- data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/assemblies/t4/assembly.json +20 -0
- data/rich_tests/fixtures/dsl_test2/sm-dtk-dtk/global_module_refs.json +7 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/HEAD +1 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/config +4 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/description +1 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/applypatch-msg.sample +15 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/commit-msg.sample +24 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/post-update.sample +8 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/pre-applypatch.sample +14 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/pre-commit.sample +50 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/pre-rebase.sample +169 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/prepare-commit-msg.sample +36 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/hooks/update.sample +128 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/info/exclude +6 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/0a/5b6255a87c9e56d91557398aee730a2b3de745 +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/15/e78d7675db51c3f9e2cf154a350d82b12abc72 +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/18/7c41cd47b9c295da0cee128c888c95cf2bba1c +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/2a/17fb5b22b8108790435eb215ffe9d06829b841 +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/2e/8c9f8472cb0e9e2421e8b5c86ad981b728cdcf +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/3b/4646ef81ef99c0c7aa62c0a97e774761c7de54 +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/5c/498a06b1ef830203e4e04c1043c9d846a18a98 +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/72/b3afc0c009e42faa235784f29f43e336bceebd +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/78/2987dc58fb1f3bea00452b8727957115b51d6f +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/9b/7c5e8096a3a871c76ad179bc29c33ac5390683 +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/a5/b61c6608349cd87f3d53a13abc2d2f51772082 +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/b4/1fb4f136d54fc9277ff16d58d9361a03a91b23 +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/be/81c8c44a92dde5139fdd302d75eec027032c8b +0 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/objects/c3/88fbdcfe33840280aa119df6d01a782fdbdd60 +1 -0
- data/rich_tests/fixtures/dsl_test4/sm-dtk-dtk.git/refs/heads/master +1 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/HEAD +1 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/config +4 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/description +1 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/applypatch-msg.sample +15 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/commit-msg.sample +24 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/post-update.sample +8 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/pre-applypatch.sample +14 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/pre-commit.sample +50 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/pre-rebase.sample +169 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/prepare-commit-msg.sample +36 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/hooks/update.sample +128 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/info/exclude +6 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/01/7d2a92efdefb513c266496c836112112c84b54 +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/0c/6675dac950c9f2038c899a0026c60bc71b1986 +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/12/7d8deca9a49974f887c594fc79804a2490c3c5 +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/21/c65148298b7366019013c31ddc9e6c62770277 +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/22/2c738a4abaebbd9ea3b6634fac902ae74479c4 +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/25/560ef0476ffda4abf20b660955aac645b6ee2f +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/4a/e421568785273757fe479236de426b80d1b658 +2 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/60/465cb06c0cde161eff264d4c2a0535fc1e8bb2 +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/63/7f0347d31dad180d6fc7f6720c187b05a8754c +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/6c/54ab6443f1a24669a99f2ce1b43863be2e9fda +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/82/c75b6fa64b746bd7f9cd7afe3c1e5bd53c430c +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/86/ec2616845245b9c9355f768a1727bcdfb643ac +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/93/ee8545d8f9681db9800cb11ec8aa72a8df8bd1 +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/bc/65ddb77fef699933dfe16b79c769f7a9cc0afd +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/d4/b1ee93110d823c5161f8cb954a6cf2e41345c1 +2 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 +0 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/refs/heads/branch1 +1 -0
- data/rich_tests/fixtures/rugged_test1/repo1.git/refs/heads/master +1 -0
- data/rich_tests/rugged_test1.rb +16 -0
- data/test.rb +13 -0
- metadata +205 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module DtkCommon
|
2
|
+
class GitRepo::Adapter::Rugged
|
3
|
+
class Branch
|
4
|
+
attr_reader :rugged_repo,:branch
|
5
|
+
def initialize(rugged_repo,branch)
|
6
|
+
@rugged_repo = rugged_repo
|
7
|
+
@branch = branch
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module CommonMixin
|
12
|
+
private
|
13
|
+
def branch()
|
14
|
+
@repo_branch.branch()
|
15
|
+
end
|
16
|
+
def rugged_repo()
|
17
|
+
@repo_branch.rugged_repo()
|
18
|
+
end
|
19
|
+
|
20
|
+
def lookup(sha)
|
21
|
+
rugged_repo().lookup(sha)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Obj
|
26
|
+
include CommonMixin
|
27
|
+
|
28
|
+
def initialize(repo_branch)
|
29
|
+
@repo_branch = repo_branch
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module DtkCommon
|
2
|
+
class GitRepo::Adapter::Rugged
|
3
|
+
class Tree < Obj
|
4
|
+
def initialize(repo_branch,rugged_tree)
|
5
|
+
super(repo_branch)
|
6
|
+
@rugged_tree = rugged_tree
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_file_content(path)
|
10
|
+
if blob = get_blob(path)
|
11
|
+
blob.content
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_files()
|
16
|
+
ret = Array.new
|
17
|
+
@rugged_tree.walk_blobs do |root,entry|
|
18
|
+
ret << "#{root}#{entry[:name]}"
|
19
|
+
end
|
20
|
+
ret
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def get_blob(path)
|
25
|
+
ret = nil
|
26
|
+
dir = ""; file_part = path
|
27
|
+
if path =~ /(.+\/)([^\/]+$)/
|
28
|
+
dir = $1; file_part = $2
|
29
|
+
end
|
30
|
+
@rugged_tree.walk_blobs do |root,entry|
|
31
|
+
if root == dir and entry[:name] == file_part
|
32
|
+
return Blob.new(@repo_branch,entry)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
ret
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../../git_repo.rb',File.dirname(__FILE__))
|
2
|
+
require 'rugged'
|
3
|
+
module DtkCommon
|
4
|
+
class GitRepo; class Adapter
|
5
|
+
class Rugged
|
6
|
+
require File.expand_path('rugged/common',File.dirname(__FILE__))
|
7
|
+
require File.expand_path('rugged/commit',File.dirname(__FILE__))
|
8
|
+
require File.expand_path('rugged/tree',File.dirname(__FILE__))
|
9
|
+
require File.expand_path('rugged/blob',File.dirname(__FILE__))
|
10
|
+
include CommonMixin
|
11
|
+
|
12
|
+
def initialize(repo_path,branch=nil)
|
13
|
+
if branch.nil?
|
14
|
+
raise Error.new("Not implemented yet creating Rugged adapter w/o a branch")
|
15
|
+
end
|
16
|
+
@repo_branch = Branch.new(::Rugged::Repository.new(repo_path),branch)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_file_content(path)
|
20
|
+
get_tree().get_file_content(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def list_files()
|
24
|
+
get_tree().list_files()
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def get_tree()
|
29
|
+
get_commit().tree()
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_commit()
|
33
|
+
if rugged_ref = rugged_repo().refs.find {|ref|ref.name == "refs/heads/#{branch}"}
|
34
|
+
Commit.new(@repo_branch,lookup(rugged_ref.target))
|
35
|
+
else
|
36
|
+
raise ErrorUsage.new("Branch (#{branch} not found in repo (#{pp_repo()})")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def pp_repo()
|
41
|
+
rugged_repo().path()
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end; end
|
45
|
+
end
|
data/lib/git_repo.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path('common_patch',File.dirname(__FILE__))
|
2
|
+
require File.expand_path('dynamic_loader',File.dirname(__FILE__))
|
3
|
+
#TODO: this will eventually replace the grit_adapter classes
|
4
|
+
module DtkCommon
|
5
|
+
class GitRepo
|
6
|
+
class Adapter
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(repo_path)
|
10
|
+
@repo_path = repo_path
|
11
|
+
@adapters = Hash.new
|
12
|
+
end
|
13
|
+
|
14
|
+
class Branch < self
|
15
|
+
def initialize(repo_path,branch='master')
|
16
|
+
super(repo_path)
|
17
|
+
@branch = branch
|
18
|
+
end
|
19
|
+
private
|
20
|
+
def adapter_initialize_args()
|
21
|
+
[@repo_path,@branch]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(method_name,*args,&block)
|
26
|
+
if adapter_name = self.class.find_adapter_name(method_name)
|
27
|
+
|
28
|
+
adapter = (@adapters[adapter_name] ||= Hash.new)[branch_index()] ||= self.class.load_and_return_adapter_class(adapter_name).new(*adapter_initialize_args())
|
29
|
+
execution_wrapper do
|
30
|
+
adapter.send(method_name,*args,&block)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def respond_to?(method_name)
|
38
|
+
super(method_name) or self.class.find_adapter_name(method_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.implements_method?(method_name)
|
42
|
+
!!find_adapter_name(method_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def adapter_initialize_args()
|
47
|
+
[@repo_path]
|
48
|
+
end
|
49
|
+
|
50
|
+
def branch_index()
|
51
|
+
@branch||"---NONE"
|
52
|
+
end
|
53
|
+
|
54
|
+
def execution_wrapper(&block)
|
55
|
+
begin
|
56
|
+
yield
|
57
|
+
rescue => e
|
58
|
+
Log.error(([e.to_s]+e.backtrace).join("\n"))
|
59
|
+
error = (e.kind_of?(::DtkCommon::Error) ? e : ::DtkCommon::Error.new(e.to_s))
|
60
|
+
raise error
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.load_and_return_adapter_class(adapter_name)
|
65
|
+
(@adapter_classes ||= Hash.new)[adapter_name] ||= DynmamicLoader.load_and_return_adapter_class(:git_repo,adapter_name,:base_class => Adapter)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.find_adapter_name(method_name)
|
69
|
+
@adapter_names ||= Hash.new
|
70
|
+
return @adapter_names[method_name] if @adapter_names.has_key?(method_name)
|
71
|
+
ret = Array(AdaptersForMethods[method_name]||[]).find do |adapter_name|
|
72
|
+
condition = AdapterConditions[adapter_name]
|
73
|
+
condition.nil? or condition.call()
|
74
|
+
end
|
75
|
+
@adapter_names[method_name] = ret
|
76
|
+
end
|
77
|
+
|
78
|
+
#for each hash value form is scalar or array of adapters to try in order
|
79
|
+
AdaptersForMethods = {
|
80
|
+
:get_file_content => :rugged,
|
81
|
+
:list_files => :rugged
|
82
|
+
}
|
83
|
+
|
84
|
+
AdapterConditions = {
|
85
|
+
# TODO: too restrictive; wil delete
|
86
|
+
# :rugged => proc{!::Gem::Specification::find_all_by_name('rugged',::Gem::Requirement.new(NailedRuggedVersion)).empty?}
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Gitolite
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_reader :repositories_path, :user_group_path, :keydir_path, :home_dir
|
5
|
+
|
6
|
+
def initialize(
|
7
|
+
repo_path_ = 'conf/repo-configs',
|
8
|
+
user_group_path_ = 'conf/group-defs',
|
9
|
+
keydir_path_ = 'keydir',
|
10
|
+
home_dir_ = nil
|
11
|
+
)
|
12
|
+
|
13
|
+
@repositories_path = repo_path_
|
14
|
+
@user_group_path = user_group_path_
|
15
|
+
@keydir_path = keydir_path_
|
16
|
+
@home_dir = home_dir_
|
17
|
+
end
|
18
|
+
|
19
|
+
def user_key_path(username)
|
20
|
+
"#{@keydir_path}/#{username}.pub"
|
21
|
+
end
|
22
|
+
|
23
|
+
def user_group_path(group_name)
|
24
|
+
"#{@user_group_path}/#{group_name}.conf"
|
25
|
+
end
|
26
|
+
|
27
|
+
def repo_path(repo_name)
|
28
|
+
"#{@repositories_path}/#{repo_name}.conf"
|
29
|
+
end
|
30
|
+
|
31
|
+
def bare_repo_path(repo_name)
|
32
|
+
"#{@home_dir}/repositories/#{repo_name}.git"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'grit'
|
2
|
+
|
3
|
+
module Gitolite
|
4
|
+
module Git
|
5
|
+
class Adapter
|
6
|
+
|
7
|
+
DEFAULT_BRANCH = 'master'
|
8
|
+
|
9
|
+
def initialize(repo_dir,branch='master')
|
10
|
+
@repo_dir = repo_dir
|
11
|
+
@branch = branch
|
12
|
+
@grit_repo = nil
|
13
|
+
begin
|
14
|
+
@grit_repo = ::Grit::Repo.new(repo_dir)
|
15
|
+
rescue ::Grit::NoSuchPathError
|
16
|
+
repo_name = repo_dir.split("/").last.gsub("\.git","")
|
17
|
+
#TODO: change to usage error
|
18
|
+
raise Error::NotFound, "Repo (#{repo_name}) - path '#{repo_dir}' does not exist"
|
19
|
+
rescue => e
|
20
|
+
raise e
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def branches()
|
25
|
+
@grit_repo.branches.map{|h|h.name}
|
26
|
+
end
|
27
|
+
|
28
|
+
def ls_r(depth=nil,opts={})
|
29
|
+
tree_contents = tree.contents
|
30
|
+
ls_r_aux(depth,tree_contents,opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
def path_exists?(path)
|
34
|
+
not (tree/path).nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def file_content(path)
|
38
|
+
tree_or_blob = tree/path
|
39
|
+
tree_or_blob && tree_or_blob.kind_of?(::Grit::Blob) && tree_or_blob.data
|
40
|
+
end
|
41
|
+
|
42
|
+
def push()
|
43
|
+
Git_command__push_mutex.synchronize do
|
44
|
+
git_command(:push,"origin", "#{@branch}:refs/heads/#{@branch}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def push_to_mirror_repo(mirror_repo)
|
49
|
+
git_command(:push,"--mirror",mirror_repo)
|
50
|
+
end
|
51
|
+
|
52
|
+
Git_command__push_mutex = Mutex.new
|
53
|
+
|
54
|
+
def pull()
|
55
|
+
git_command(:pull,"origin",@branch)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def tree()
|
60
|
+
@grit_repo.tree(@branch)
|
61
|
+
end
|
62
|
+
|
63
|
+
def ls_r_aux(depth,tree_contents,opts={})
|
64
|
+
ret = Array.new
|
65
|
+
return ret if tree_contents.empty?
|
66
|
+
if depth == 1
|
67
|
+
ret = tree_contents.map do |tc|
|
68
|
+
if opts[:file_only]
|
69
|
+
tc.kind_of?(::Grit::Blob) && tc.name
|
70
|
+
elsif opts[:directory_only]
|
71
|
+
tc.kind_of?(::Grit::Tree) && tc.name
|
72
|
+
else
|
73
|
+
tc.name
|
74
|
+
end
|
75
|
+
end.compact
|
76
|
+
return ret
|
77
|
+
end
|
78
|
+
|
79
|
+
tree_contents.each do |tc|
|
80
|
+
if tc.kind_of?(::Grit::Blob)
|
81
|
+
unless opts[:directory_only]
|
82
|
+
ret << tc.name
|
83
|
+
end
|
84
|
+
else
|
85
|
+
dir_name = tc.name
|
86
|
+
ret += ls_r_aux(depth && depth-1,tc.contents).map{|r|"#{dir_name}/#{r}"}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
ret
|
90
|
+
end
|
91
|
+
|
92
|
+
def git_command(cmd,*args)
|
93
|
+
@grit_repo.git.send(cmd, cmd_opts(),*args)
|
94
|
+
end
|
95
|
+
def cmd_opts()
|
96
|
+
{:raise => true, :timeout => 60}
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Gitolite
|
2
|
+
module Git
|
3
|
+
class FileAccess < Adapter
|
4
|
+
|
5
|
+
def add_file(file_rel_path,content)
|
6
|
+
content ||= String.new
|
7
|
+
file_path = qualified_path(file_rel_path)
|
8
|
+
chdir_and_checkout do
|
9
|
+
File.open(file_path,"w"){|f|f << content}
|
10
|
+
git_command(:add,file_path)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def remove_file(file_rel_path)
|
15
|
+
file_path = qualified_path(file_rel_path)
|
16
|
+
chdir_and_checkout do
|
17
|
+
if File.file?(file_path)
|
18
|
+
git_command(:rm,file_path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def commit(commit_msg)
|
24
|
+
#TODO is chdir_and_checkout needed
|
25
|
+
chdir_and_checkout do
|
26
|
+
@grit_repo.commit_index(commit_msg)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def qualified_path(file_rel_path)
|
33
|
+
"#{@repo_dir}/#{file_rel_path}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def chdir_and_checkout(branch=nil,&block)
|
37
|
+
branch ||= @branch
|
38
|
+
Dir.chdir(@repo_dir) do
|
39
|
+
current_head = @grit_repo.head.name
|
40
|
+
git_command(:checkout,branch) unless current_head == branch
|
41
|
+
return unless block
|
42
|
+
yield
|
43
|
+
unless current_head == branch
|
44
|
+
git_command(:checkout,current_head)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# use to require all needed files needed for running dtk-common gitolite lib
|
2
|
+
require 'grit'; require 'erubis'
|
3
|
+
|
4
|
+
Grit.debug = true
|
5
|
+
|
6
|
+
|
7
|
+
require File.expand_path('manager.rb', File.dirname(__FILE__))
|
8
|
+
require File.expand_path('configuration.rb', File.dirname(__FILE__))
|
9
|
+
require File.expand_path('errors.rb', File.dirname(__FILE__))
|
10
|
+
|
11
|
+
require File.expand_path('grit/adapter.rb', File.dirname(__FILE__))
|
12
|
+
require File.expand_path('grit/file_access.rb', File.dirname(__FILE__))
|
13
|
+
|
14
|
+
require File.expand_path('utils.rb', File.dirname(__FILE__))
|
15
|
+
require File.expand_path('repo.rb', File.dirname(__FILE__))
|
16
|
+
require File.expand_path('user_group.rb', File.dirname(__FILE__))
|
@@ -0,0 +1,158 @@
|
|
1
|
+
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Gitolite
|
5
|
+
class Manager
|
6
|
+
|
7
|
+
attr_accessor :repos, :user_groups, :configuration, :logger, :commit_messages
|
8
|
+
attr_reader :gitolite_path
|
9
|
+
|
10
|
+
def initialize(gitolite_path, override_configuration = nil)
|
11
|
+
@repos, @user_groups, @commit_messages = [], [], []
|
12
|
+
@gitolite_path = gitolite_path
|
13
|
+
@configuration = override_configuration || Configuration.new
|
14
|
+
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
15
|
+
end
|
16
|
+
|
17
|
+
def open_repo(repo_name)
|
18
|
+
repo_conf = Repo.new(repo_name, @configuration, @logger, @gitolite_path)
|
19
|
+
@repos << repo_conf
|
20
|
+
repo_conf
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_repo(repo_name)
|
24
|
+
file_path = @configuration.repo_path(repo_name)
|
25
|
+
remove_file(file_path, "Deleting repo (#{repo_name}) from gitolite.")
|
26
|
+
|
27
|
+
bare_repo_path = @configuration.bare_repo_path(repo_name)
|
28
|
+
if File.directory?(bare_repo_path)
|
29
|
+
FileUtils.rm_rf bare_repo_path
|
30
|
+
end
|
31
|
+
repo_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def open_group(group_name)
|
35
|
+
group_conf = UserGroup.new(group_name, @logger, @gitolite_path)
|
36
|
+
@user_groups << group_conf
|
37
|
+
group_conf
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_user(username, rsa_pub_key, opts={})
|
41
|
+
key_path = @configuration.user_key_path(username)
|
42
|
+
|
43
|
+
if users_public_keys().include?(key_path)
|
44
|
+
raise ::Gitolite::Duplicate, "Trying to create a user (#{username}) that exists already on gitolite server"
|
45
|
+
end
|
46
|
+
|
47
|
+
add_commit_file(key_path,rsa_pub_key, "Added RSA public key for user '#{username}'")
|
48
|
+
|
49
|
+
key_path
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_user(username)
|
53
|
+
key_path = @configuration.user_key_path(username)
|
54
|
+
|
55
|
+
unless users_public_keys().include?(key_path)
|
56
|
+
raise ::Gitolite::NotFound, "User (#{username}) not found on gitolite server"
|
57
|
+
end
|
58
|
+
|
59
|
+
remove_file(key_path, "Removing RSA public key for user '#{username}'")
|
60
|
+
username
|
61
|
+
end
|
62
|
+
|
63
|
+
def remove_user_group(group_name)
|
64
|
+
group_path = @configuration.user_group_path(group_name)
|
65
|
+
|
66
|
+
unless user_group_list.include?(group_path)
|
67
|
+
raise ::Gitolite::NotFound, "User group (#{group_name}) not found on gitolite server"
|
68
|
+
end
|
69
|
+
|
70
|
+
remove_file(key_path, "Removing user group (#{group_name})")
|
71
|
+
group_name
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete_user_group(group_name)
|
75
|
+
path = @configuration.user_group_path(group_name)
|
76
|
+
remove_file(path, "Remove user group (#{group_name}) from gitolite.")
|
77
|
+
group_name
|
78
|
+
end
|
79
|
+
|
80
|
+
def list_repos()
|
81
|
+
repo_names = repo_names_list()
|
82
|
+
repo_names.map { |repo_name| { :repo_name => repo_name, :type => Repo.get_repo_type(repo_name) }}
|
83
|
+
end
|
84
|
+
|
85
|
+
def push()
|
86
|
+
changed_repos = @repos.select { |repo| repo.any_changes? }
|
87
|
+
changed_groups = @user_groups.select { |ug| ug.any_changes? }
|
88
|
+
|
89
|
+
unless (@commit_messages.empty? && changed_repos.empty? && changed_groups.empty?)
|
90
|
+
changed_repos.each { |repo| repo.commit_changes }
|
91
|
+
changed_groups.each { |ug| ug.commit_changes }
|
92
|
+
|
93
|
+
gitolite_admin_repo().push()
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def gitolite_admin_repo()
|
100
|
+
@gitolite_admin ||= Git::FileAccess.new(@gitolite_path)
|
101
|
+
end
|
102
|
+
|
103
|
+
def users_public_keys()
|
104
|
+
base_path = @configuration.keydir_path
|
105
|
+
list_files_in_path(base_path)
|
106
|
+
end
|
107
|
+
|
108
|
+
def user_group_list()
|
109
|
+
base_path = @configuration.user_group_path
|
110
|
+
list_files_in_path(base_path)
|
111
|
+
end
|
112
|
+
|
113
|
+
def repo_names_list()
|
114
|
+
base_path = @configuration.repo_path
|
115
|
+
repo_file_list = list_files_in_path(base_path)
|
116
|
+
repo_file_list.collect { |r_file_name| extract_file_name(r_file_name, base_path, :conf) }
|
117
|
+
end
|
118
|
+
|
119
|
+
def add_commit_file(file, content, commit_msg)
|
120
|
+
gitolite_admin_repo().add_file(file, content)
|
121
|
+
gitolite_admin_repo().commit(commit_msg)
|
122
|
+
@commit_messages << commit_msg
|
123
|
+
end
|
124
|
+
|
125
|
+
def remove_file(file_path, commit_msg)
|
126
|
+
gitolite_admin_repo().remove_file(file_path)
|
127
|
+
gitolite_admin_repo().commit(commit_msg)
|
128
|
+
@commit_messages << commit_msg
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
class << self
|
133
|
+
|
134
|
+
def repo_name_from_file_name(file_name, repo_file_path)
|
135
|
+
if file_name =~ Regexp.new("^#{repo_file_path}/(.+)\.conf")
|
136
|
+
$1
|
137
|
+
else
|
138
|
+
raise Error.new("File name not properly formed for repo config file name (#{file_name})")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def extract_file_name(full_path_name, file_path, file_extension)
|
144
|
+
if file_name =~ Regexp.new("^#{full_path_name}/(.+)\.#{file_extension}")
|
145
|
+
$1
|
146
|
+
else
|
147
|
+
raise ::Gitolite::ParseError.new("File name not properly formed (#{full_path_name}), expected match based on '#{file_path}/*.#{file_extension}'")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def list_files_in_path(path)
|
152
|
+
paths = gitolite_admin_repo.ls_r(path.split("/").size + 1, :files_only => true)
|
153
|
+
match_regexp = Regexp.new("^#{path}")
|
154
|
+
paths.select{ |p| p =~ match_regexp }
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
end
|