Class: BitbucketMigration::GitInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbucket_migration/git_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#gitObject (readonly)

Returns the value of attribute git.



5
6
7
# File 'lib/bitbucket_migration/git_interface.rb', line 5

def git
  @git
end

#remotesObject (readonly)

Returns the value of attribute remotes.



5
6
7
# File 'lib/bitbucket_migration/git_interface.rb', line 5

def remotes
  @remotes
end

#src_repoObject

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_repoObject

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_allObject

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_repoObject

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_allObject

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