Sha256: b672095a50e1e45dc802dab372019d4fb89740c649e4b588d5fa1fa80ef91991

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

module Braid
  module Commands
    class Add < Command
      def run(url, options = {})
        bail_on_local_changes!

        with_reset_on_error do
          mirror = config.add_from_options(url, options)

          branch_message = (mirror.type == "svn" || mirror.branch == "master") ? "" : " branch '#{mirror.branch}'"
          revision_message = options["revision"] ? " at #{display_revision(mirror, options["revision"])}" : ""
          msg "Adding #{mirror.type} mirror of '#{mirror.url}'#{branch_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

          setup_remote(mirror)
          mirror.fetch

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

          unless mirror.squashed?
            git.merge_ours(target_revision)
          end
          git.read_tree_prefix(target_revision, mirror.path)

          mirror.revision = new_revision
          mirror.lock = new_revision if options["revision"]
          config.update(mirror)
          add_config_file

          commit_message = "Add mirror '#{mirror.path}/'#{revision_message}"
          git.commit(commit_message)
        end
      end

      private
        def setup_remote(mirror)
          Command.run(:setup, mirror.path)
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
evilchelu-braid-0.4.13 lib/braid/commands/add.rb
norbert-braid-0.4.13 lib/braid/commands/add.rb