Class: GitMirror
- Inherits:
-
Object
- Object
- GitMirror
- Defined in:
- lib/git_mirror.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #execute(command) ⇒ Object
- #has_mirror?(repo_url) ⇒ Boolean
-
#initialize(root = ENV['GIT_MIRROR_ROOT'] || '/var/git_mirror') ⇒ GitMirror
constructor
A new instance of GitMirror.
- #local_path_for(repo_url) ⇒ Object
- #mirror(repo_url) ⇒ Object
- #prepare_root ⇒ Object
- #update(repo_url) ⇒ Object
- #update_all ⇒ Object
- #update_local(path) ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/git_mirror.rb', line 5 def root @root end |
Instance Method Details
#execute(command) ⇒ Object
45 46 47 48 49 |
# File 'lib/git_mirror.rb', line 45 def execute(command) prepare_root puts command system(command) end |
#has_mirror?(repo_url) ⇒ Boolean
25 26 27 |
# File 'lib/git_mirror.rb', line 25 def has_mirror?(repo_url) local_path_for(repo_url).directory? end |
#local_path_for(repo_url) ⇒ Object
29 30 31 |
# File 'lib/git_mirror.rb', line 29 def local_path_for(repo_url) root + repo_url.split(/github.com./, 2).last end |
#mirror(repo_url) ⇒ Object
20 21 22 23 |
# File 'lib/git_mirror.rb', line 20 def mirror(repo_url) return if has_mirror?(repo_url) execute "git clone --mirror --quiet #{repo_url} #{local_path_for(repo_url)}" end |
#prepare_root ⇒ Object
11 12 13 |
# File 'lib/git_mirror.rb', line 11 def prepare_root root.mkpath end |
#update(repo_url) ⇒ Object
15 16 17 18 |
# File 'lib/git_mirror.rb', line 15 def update(repo_url) mirror(repo_url) unless has_mirror?(repo_url) update_local(local_path_for(repo_url)) end |
#update_all ⇒ Object
33 34 35 36 37 |
# File 'lib/git_mirror.rb', line 33 def update_all Pathname.glob(root + '**/HEAD').each do |head| update_local(head.parent) end end |
#update_local(path) ⇒ Object
39 40 41 42 43 |
# File 'lib/git_mirror.rb', line 39 def update_local(path) FileUtils.cd(path) do execute "git fetch --prune --quiet" end end |