gitpusher 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -4
- data/bin/gitpusher +5 -0
- data/gitpusher.gemspec +0 -1
- data/lib/gitpusher/context.rb +1 -1
- data/lib/gitpusher/runner.rb +47 -34
- data/lib/gitpusher/service/factory.rb +1 -1
- data/lib/gitpusher/version.rb +1 -1
- metadata +9 -40
data/README.md
CHANGED
@@ -6,7 +6,7 @@ gitpusher is a command line tool for replicating git repositories from one servi
|
|
6
6
|
$ gitpusher -c default.yml
|
7
7
|
```
|
8
8
|
|
9
|
-
default.
|
9
|
+
default.yml is like this.
|
10
10
|
|
11
11
|
```
|
12
12
|
:base_dir: /var/repos
|
@@ -16,7 +16,7 @@ default.yaml is like this.
|
|
16
16
|
:type: bitbucket
|
17
17
|
```
|
18
18
|
|
19
|
-
With this settings,
|
19
|
+
With this settings, all of your repositories on GitHub will be replicated to Bitbucket.
|
20
20
|
(User name and password of each service are asked when you run the command first.)
|
21
21
|
|
22
22
|
If you would like to replicate GitHub organization's repos instead of your own repos, settings are like this.
|
@@ -25,9 +25,24 @@ If you would like to replicate GitHub organization's repos instead of your own r
|
|
25
25
|
:base_dir: /var/repos
|
26
26
|
:src:
|
27
27
|
:type: github
|
28
|
-
:organization:
|
28
|
+
:organization: github_organization_name
|
29
29
|
:dest:
|
30
30
|
:type: bitbucket
|
31
31
|
```
|
32
32
|
|
33
|
-
Now this tool
|
33
|
+
Now this tool supports only replicating from GitHub to Bitbucket.
|
34
|
+
|
35
|
+
## Parallel processing
|
36
|
+
|
37
|
+
You will spend a lot of time when you have many repositories.
|
38
|
+
Now, to save your time, gitpusher supports parallel processing.
|
39
|
+
|
40
|
+
You can specify the number of processes by `--process`, or `-p`, option.
|
41
|
+
|
42
|
+
If you do:
|
43
|
+
|
44
|
+
```
|
45
|
+
$ gitpusher -c default.yml --process 6
|
46
|
+
```
|
47
|
+
|
48
|
+
then 6 repositories are processed at a time.
|
data/bin/gitpusher
CHANGED
@@ -8,14 +8,19 @@ op = OptionParser.new do |opts|
|
|
8
8
|
opts.on('-c', '--config FILE') do |file|
|
9
9
|
options[:config] = file
|
10
10
|
end
|
11
|
+
opts.on('-p', '--process NUMBER', OptionParser::DecimalInteger) do |count|
|
12
|
+
options[:processes] = [1, count].max
|
13
|
+
end
|
11
14
|
end
|
12
15
|
|
13
16
|
op.parse!
|
14
17
|
|
15
18
|
options[:config] ||= 'config/default.yml'
|
19
|
+
options[:processes] ||= 1
|
16
20
|
|
17
21
|
context = GitPusher::Context.instance
|
18
22
|
context.home = File.join(File.dirname(__FILE__), '..')
|
23
|
+
context.processes = options[:processes]
|
19
24
|
|
20
25
|
GitPusher::Config.load(options)
|
21
26
|
|
data/gitpusher.gemspec
CHANGED
data/lib/gitpusher/context.rb
CHANGED
data/lib/gitpusher/runner.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'grit'
|
2
3
|
|
3
4
|
module GitPusher
|
@@ -9,56 +10,68 @@ module GitPusher
|
|
9
10
|
dest = GitPusher::Service::Factory.create(context.config[:dest])
|
10
11
|
|
11
12
|
base_dir = context.config[:base_dir]
|
12
|
-
src.repos
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
src_repos = src.repos
|
14
|
+
num_per_process = src_repos.length / context.processes
|
15
|
+
num_per_process += 1 unless src_repos.length % context.processes == 0
|
16
|
+
Dir.chdir(base_dir) do
|
17
|
+
src_repos.each_slice(num_per_process) do |repos|
|
18
|
+
fork do
|
19
|
+
repos.each do |src_repo|
|
20
|
+
mirror src_repo, dest, base_dir
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
24
|
+
end
|
22
25
|
|
23
|
-
|
26
|
+
Process.waitall
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
def self.mirror(src_repo, dest, base_dir)
|
30
|
+
repo_name = File.basename(src_repo.url).gsub(/.git$/, '')
|
31
|
+
repo_path = File.join(base_dir, repo_name)
|
32
|
+
puts "[#{Process.pid}][#{repo_name}]Cheking #{src_repo.url} ..."
|
33
|
+
unless File.exist?(repo_path)
|
34
|
+
p src_repo.url
|
35
|
+
`git clone #{src_repo.url}`
|
36
|
+
end
|
30
37
|
|
31
|
-
|
32
|
-
mirror_repo = dest.repo(repo_name) || dest.create_repo(repo_name)
|
33
|
-
local_repo.git.remote({}, 'add', 'mirror', mirror_repo.url)
|
34
|
-
end
|
38
|
+
local_repo = Grit::Repo.new(repo_path)
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
# local repo の git remote で mirror があるかどうかチェック
|
41
|
+
has_remote_mirror = false
|
42
|
+
local_repo.remote_list.each do |remote|
|
43
|
+
has_remote_mirror = true if remote === 'mirror'
|
44
|
+
end
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
unless has_remote_mirror
|
47
|
+
mirror_repo = dest.repo(repo_name) || dest.create_repo(repo_name)
|
48
|
+
local_repo.git.remote({}, 'add', 'mirror', mirror_repo.url)
|
49
|
+
end
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
|
51
|
+
local_repo.remotes.each do |remote|
|
52
|
+
next if remote.name == 'origin/HEAD'
|
53
|
+
next if remote.name =~ %r!mirror/.+!
|
54
|
+
branch = remote.name.gsub(%r!^origin/!, '')
|
55
|
+
|
56
|
+
matched = false
|
57
|
+
local_repo.branches.each do |x|
|
58
|
+
matched = true if x.name === branch
|
59
|
+
end
|
60
|
+
|
61
|
+
unless matched
|
62
|
+
local_repo.git.branch({}, branch, remote.name)
|
63
|
+
end
|
49
64
|
|
65
|
+
Dir.chdir(repo_path) do
|
50
66
|
# pull する
|
51
|
-
puts "Pulling #{branch} ..."
|
67
|
+
puts "[#{Process.pid}][#{repo_name}]Pulling #{branch} ..."
|
52
68
|
local_repo.git.pull({}, 'origin', branch)
|
53
69
|
|
54
70
|
# git push mirror #{branch} する
|
55
|
-
puts "Pushing #{branch} ..."
|
71
|
+
puts "[#{Process.pid}][#{repo_name}]Pushing #{branch} ..."
|
56
72
|
local_repo.git.push({ :timeout => 300 }, 'mirror', branch)
|
57
73
|
end
|
58
|
-
|
59
74
|
end
|
60
|
-
|
61
|
-
|
62
75
|
end
|
63
76
|
end
|
64
77
|
end
|
@@ -6,7 +6,7 @@ module GitPusher
|
|
6
6
|
when /github/i then GitPusher::Service::GitHub.new(config)
|
7
7
|
when /bitbucket/i then GitPusher::Service::BitBucket.new(config)
|
8
8
|
else
|
9
|
-
raise "unknown
|
9
|
+
raise "unknown service type : #{config[:type]}"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/gitpusher/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitpusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grit
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70129329850960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
24
|
+
version_requirements: *70129329850960
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: octokit
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70129329849640 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,15 +32,10 @@ dependencies:
|
|
37
32
|
version: '0'
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
35
|
+
version_requirements: *70129329849640
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: pit
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70129329848580 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ! '>='
|
@@ -53,28 +43,7 @@ dependencies:
|
|
53
43
|
version: '0'
|
54
44
|
type: :runtime
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: grit
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
46
|
+
version_requirements: *70129329848580
|
78
47
|
description:
|
79
48
|
email:
|
80
49
|
- gosukenator@gmail.com
|
@@ -125,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
94
|
version: '0'
|
126
95
|
requirements: []
|
127
96
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.8.
|
97
|
+
rubygems_version: 1.8.11
|
129
98
|
signing_key:
|
130
99
|
specification_version: 3
|
131
100
|
summary: A command line tool for replicating git repositories from one service to
|