Class: GitDuplicator::Repository
- Inherits:
-
Object
- Object
- GitDuplicator::Repository
- Defined in:
- lib/git_duplicator/repository/repository.rb
Overview
Basic Repostiroy
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
-
#working_directory ⇒ Object
Returns the value of attribute working_directory.
Instance Method Summary collapse
-
#bare_clone(path_to_repo) ⇒ Object
Bare clone the repository.
-
#initialize(name, url, working_directory = nil) ⇒ Repository
constructor
Initializer.
-
#mirror(mirrored_url) ⇒ Object
Mirror the repository.
-
#mirror_clone(path_to_repo) ⇒ Object
Mirror clone the repository.
-
#set_mirrored_remote(mirrored_url) ⇒ Object
Set the remote URL of the mirrored.
-
#update_mirrored ⇒ Object
Update a mirrored repository.
Constructor Details
#initialize(name, url, working_directory = nil) ⇒ Repository
Initializer
13 14 15 16 17 |
# File 'lib/git_duplicator/repository/repository.rb', line 13 def initialize(name, url, working_directory = nil) self.name = name self.url = url self.working_directory = working_directory end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/git_duplicator/repository/repository.rb', line 6 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/git_duplicator/repository/repository.rb', line 6 def url @url end |
#working_directory ⇒ Object
Returns the value of attribute working_directory.
7 8 9 |
# File 'lib/git_duplicator/repository/repository.rb', line 7 def working_directory @working_directory end |
Instance Method Details
#bare_clone(path_to_repo) ⇒ Object
Bare clone the repository
26 27 28 29 30 |
# File 'lib/git_duplicator/repository/repository.rb', line 26 def (path_to_repo) self.repo = Git.clone(url, name, bare: true, path: path_to_repo) rescue => exception raise RepositoryCloningError, exception. end |
#mirror(mirrored_url) ⇒ Object
Mirror the repository
44 45 46 47 48 49 |
# File 'lib/git_duplicator/repository/repository.rb', line 44 def mirror(mirrored_url) fail('No local repo defined. Set the "repo" attribute') unless repo repo.push(mirrored_url, '--mirror') rescue => exception raise RepositoryMirorringError, exception. end |
#mirror_clone(path_to_repo) ⇒ Object
Mirror clone the repository
34 35 36 37 38 39 40 |
# File 'lib/git_duplicator/repository/repository.rb', line 34 def mirror_clone(path_to_repo) path = File.join(path_to_repo, name) command('clone', '--mirror', url, path) self.repo = Git.(path) rescue => exception raise RepositoryCloningError, exception. end |
#set_mirrored_remote(mirrored_url) ⇒ Object
Set the remote URL of the mirrored
53 54 55 56 57 58 |
# File 'lib/git_duplicator/repository/repository.rb', line 53 def set_mirrored_remote(mirrored_url) fail('No local repo defined. Set the "repo" attribute') unless repo command('remote', 'set-url', '--push', 'origin', mirrored_url) rescue => exception raise RepositorySettingRemoteError, exception. end |
#update_mirrored ⇒ Object
Update a mirrored repository
61 62 63 64 65 66 67 |
# File 'lib/git_duplicator/repository/repository.rb', line 61 def update_mirrored fail('No local repo defined. Set the "repo" attribute') unless repo command('fetch', '-p', 'origin') command('push', '--mirror') rescue => exception raise RepositoryMirorredUpdatingError, exception. end |