Class: GitDuplicator::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/git_duplicator/repository/repository.rb

Overview

Basic Repostiroy

Direct Known Subclasses

ServiceRepository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url) ⇒ Repository

Initializer

Parameters:

  • name (String)

    name of the repository

  • url (String)

    URL of the repository



12
13
14
15
# File 'lib/git_duplicator/repository/repository.rb', line 12

def initialize(name, url)
  self.name = name
  self.url = url
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/git_duplicator/repository/repository.rb', line 6

def name
  @name
end

#repoObject

Returns the value of attribute repo.



7
8
9
# File 'lib/git_duplicator/repository/repository.rb', line 7

def repo
  @repo
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/git_duplicator/repository/repository.rb', line 6

def url
  @url
end

Instance Method Details

#bare_clone(path_to_repo) ⇒ Object

Bare clone the repository

Parameters:

  • path_to_repo (String)

    path to clone the repository to



26
27
28
29
30
# File 'lib/git_duplicator/repository/repository.rb', line 26

def bare_clone(path_to_repo)
  self.repo = Git.clone(url, name, bare: true, path: path_to_repo)
rescue => exception
  raise RepositoryCloningError, exception.message
end

#mirror(destination_url) ⇒ Object

Mirror the repository

Parameters:

  • destination_url (String)

    URL of destination repository



34
35
36
37
38
39
# File 'lib/git_duplicator/repository/repository.rb', line 34

def mirror(destination_url)
  fail('No local repo defined. Set the "repo" attribute') unless repo
  repo.push(destination_url, '--mirror')
rescue => exception
  raise RepositoryMirorringError, exception.message
end