Class: VCSToolkit::Utils::Sync
- Inherits:
-
Object
- Object
- VCSToolkit::Utils::Sync
- Defined in:
- lib/vcs_toolkit/utils/sync.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source_store, source_label_name, destination_store, destination_label_name) ⇒ Sync
constructor
A new instance of Sync.
-
#sync ⇒ Object
Syncs source history starting at ‘source_label` to `destination_store` starting at `destination_label`.
Constructor Details
#initialize(source_store, source_label_name, destination_store, destination_label_name) ⇒ Sync
Returns a new instance of Sync.
9 10 11 12 13 14 |
# File 'lib/vcs_toolkit/utils/sync.rb', line 9 def initialize(source_store, source_label_name, destination_store, destination_label_name) @source_store = source_store @source_label = source_store.fetch source_label_name @destination_store = destination_store @destination_label = destination_store.fetch destination_label_name end |
Class Method Details
.sync(*args) ⇒ Object
5 6 7 |
# File 'lib/vcs_toolkit/utils/sync.rb', line 5 def self.sync(*args) new(*args).sync end |
Instance Method Details
#sync ⇒ Object
Syncs source history starting at ‘source_label` to `destination_store` starting at `destination_label`.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vcs_toolkit/utils/sync.rb', line 20 def sync raise 'Nothing to sync' if @source_label.reference_id.nil? destination_commit_id = @destination_label.reference_id raise DivergedHistoriesError unless destination_commit_id.nil? or @source_store.key? destination_commit_id source_commit = @source_store.fetch @source_label.reference_id commits_to_push = source_commit.history_diff(@source_store) do |commit| # Do not follow parent references for commits # that are already on the remote. @destination_store.key? commit.id end commits_to_push.each do |commit| transfer_commit commit end # Now that every object is transferred change the destination label @destination_label.reference_id = source_commit.id @destination_store.store @destination_label.id, @destination_label end |