Class: BitbucketMigration::GitInterface
- Inherits:
-
Object
- Object
- BitbucketMigration::GitInterface
- Defined in:
- lib/bitbucket_migration/git_interface.rb
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#remotes ⇒ Object
readonly
Returns the value of attribute remotes.
-
#src_repo ⇒ Object
Returns the value of attribute src_repo.
-
#target_repo ⇒ Object
Returns the value of attribute target_repo.
Instance Method Summary collapse
-
#fetch_src_repo_all ⇒ Object
Fetches all related remote branches and tags for source repository.
-
#init_src_repo(workdir) ⇒ Object
Clones source repository to the temporary working directory.
-
#init_target_repo ⇒ Object
Add remote reference to target repository ( in bitbucket ).
-
#initialize(src_repo, target_repo) ⇒ GitInterface
constructor
A new instance of GitInterface.
-
#push_target_repo_all ⇒ Object
Push all related branches and tags to target repository.
Constructor Details
#initialize(src_repo, target_repo) ⇒ GitInterface
Returns a new instance of GitInterface.
21 22 23 24 25 |
# File 'lib/bitbucket_migration/git_interface.rb', line 21 def initialize(src_repo, target_repo) self.src_repo =src_repo self.target_repo =target_repo @remotes ||= {:default => 'origin', :bitbucket => 'bitbucket'}.freeze end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
5 6 7 |
# File 'lib/bitbucket_migration/git_interface.rb', line 5 def git @git end |
#remotes ⇒ Object (readonly)
Returns the value of attribute remotes.
5 6 7 |
# File 'lib/bitbucket_migration/git_interface.rb', line 5 def remotes @remotes end |
#src_repo ⇒ Object
Returns the value of attribute src_repo.
5 6 7 |
# File 'lib/bitbucket_migration/git_interface.rb', line 5 def src_repo @src_repo end |
#target_repo ⇒ Object
Returns the value of attribute target_repo.
5 6 7 |
# File 'lib/bitbucket_migration/git_interface.rb', line 5 def target_repo @target_repo end |
Instance Method Details
#fetch_src_repo_all ⇒ Object
Fetches all related remote branches and tags for source repository
42 43 44 45 46 47 |
# File 'lib/bitbucket_migration/git_interface.rb', line 42 def fetch_src_repo_all @git.fetch @git.branches.remote.each do |rb| @git.checkout(rb.name) if !rb.name.match('^HEAD') end end |
#init_src_repo(workdir) ⇒ Object
Clones source repository to the temporary working directory
28 29 30 31 32 33 34 |
# File 'lib/bitbucket_migration/git_interface.rb', line 28 def init_src_repo(workdir) if (workdir == nil or workdir.size == 0) raise ArgumentError.new("Unable to continue without working directory") else @git = Git.clone(@src_repo.url, @src_repo.name, :path => workdir) end end |
#init_target_repo ⇒ Object
Add remote reference to target repository ( in bitbucket )
37 38 39 |
# File 'lib/bitbucket_migration/git_interface.rb', line 37 def init_target_repo @git.add_remote(@remotes[:bitbucket], @target_repo.ssh_href) end |
#push_target_repo_all ⇒ Object
Push all related branches and tags to target repository
50 51 52 53 54 |
# File 'lib/bitbucket_migration/git_interface.rb', line 50 def push_target_repo_all @git.branches.local.each do |lb| @git.push(@remotes[:bitbucket], lb.name, {:tags => true}) end end |