Sha256: 802dd62588835104186fe39b0d3a63a8774a4e65e6e973240b55892f81ba4bba

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

module Braid
  module Commands
    class Add < Command
      def run(url, options = {})
        with_reset_on_error do
          mirror           = config.add_from_options(url, options)
          add_config_file

          mirror.branch = nil if options['revision']
          raise BraidError, 'Can not add mirror specifying both a revision and a tag' if options['revision'] && mirror.tag

          branch_message   = (mirror.branch.nil? || mirror.branch == 'master') ? '' : " branch '#{mirror.branch}'"
          tag_message      = mirror.tag.nil? ? '' : " tag '#{mirror.tag}'"
          revision_message = options['revision'] ? " at #{display_revision(mirror, options['revision'])}" : ''
          msg "Adding mirror of '#{mirror.url}'#{branch_message}#{tag_message}#{revision_message}."

          # these commands are explained in the subtree merge guide
          # http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html

          config.update(mirror)
          setup_remote(mirror)
          mirror.fetch

          new_revision    = validate_new_revision(mirror, options['revision'])
          target_revision = determine_target_revision(mirror, new_revision)

          git.read_tree_prefix_u(target_revision, mirror.path)

          mirror.revision = new_revision
          config.update(mirror)
          add_config_file

          git.commit("Add mirror '#{mirror.path}' at #{display_revision(mirror)}")
          msg "Added mirror at #{display_revision(mirror)}."

          clear_remote(mirror, options)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
braid-1.0.22 lib/braid/commands/add.rb
braid-1.0.21 lib/braid/commands/add.rb
braid-1.0.20 lib/braid/commands/add.rb
braid-1.0.19 lib/braid/commands/add.rb
braid-1.0.18 lib/braid/commands/add.rb