git_mirror 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +29 -0
  2. data/bin/git-mirror +14 -0
  3. data/lib/git_mirror.rb +45 -0
  4. metadata +86 -0
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # GitMirror
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'git_mirror'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install git_mirror
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/bin/git-mirror ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push File.expand_path("../lib", File.dirname(__FILE__))
4
+ require 'git_mirror'
5
+
6
+ instance = GitMirror.new
7
+
8
+ update_all = ARGV == ['update']
9
+
10
+ if update_all
11
+ instance.update_all
12
+ else
13
+ instance.update(ARGV[0])
14
+ end
data/lib/git_mirror.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'pathname'
2
+
3
+ class GitMirror
4
+ def initialize
5
+ @root = Pathname.new(ENV['GIT_MIRROR_ROOT'] || '/var/git-mirror')
6
+ end
7
+
8
+ def prepare_root
9
+ @root.mkpath
10
+ end
11
+
12
+ def update(repo_url)
13
+ mirror(repo_url) unless has_mirror?(repo_url)
14
+ update_local(local_path_for(repo_url))
15
+ end
16
+
17
+ def mirror(repo_url)
18
+ return if has_mirror?(repo_url)
19
+ execute "git clone --mirror --quiet #{repo_url} #{local_path_for(repo_url)}"
20
+ end
21
+
22
+ def has_mirror?(repo_url)
23
+ local_path_for(repo_url).directory?
24
+ end
25
+
26
+ def local_path_for(repo_url)
27
+ @root + repo_url.split(/github.com./, 2).last
28
+ end
29
+
30
+ def update_all
31
+ Pathname.glob(@root + '**/HEAD').each do |head|
32
+ update_local(head.parent)
33
+ end
34
+ end
35
+
36
+ def update_local(path)
37
+ execute "git fetch --prune --quiet #{path}"
38
+ end
39
+
40
+ def execute(command)
41
+ prepare_root
42
+ puts command
43
+ system(command)
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_mirror
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mick Staugaard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: utility for mirroring github repositories
47
+ email: mick@zendesk.com
48
+ executables:
49
+ - git-mirror
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/git_mirror.rb
54
+ - bin/git-mirror
55
+ - README.md
56
+ homepage: ''
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ segments:
69
+ - 0
70
+ hash: 3188072254581163088
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ segments:
78
+ - 0
79
+ hash: 3188072254581163088
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.25
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: utility for mirroring github repositories
86
+ test_files: []