Class: Braid::Commands::Add

Inherits:
Braid::Command show all
Defined in:
lib/braid/commands/add.rb

Instance Method Summary collapse

Methods inherited from Braid::Command

#config, msg, run

Methods included from Operations::Git

#git_checkout, #git_commit, #git_fetch, #git_merge_base, #git_merge_ours, #git_merge_subtree, #git_read_tree, #git_remote_add, #git_reset_hard, #git_rev_parse, #git_rm_r, #local_changes?

Methods included from Operations::Helpers

#clean_svn_revision, #determine_target_commit, #display_revision, #extract_version, #find_git_revision, #validate_revision_option, #validate_svn_revision, #verify_version

Methods included from Operations::Mirror

#add_config_file, #check_merge_status, #create_work_branch, #fetch_remote, #find_remote, #get_current_branch, #get_work_head

Instance Method Details

#run(remote, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/braid/commands/add.rb', line 4

def run(remote, options = {})
  raise Braid::Git::LocalChangesPresent if invoke(:local_changes?)

  in_work_branch do
    mirror, params = config.add_from_options(remote, options)
    local_branch = get_local_branch_name(mirror, params)

    config.update(mirror, { "local_branch" => local_branch })
    params["local_branch"] = local_branch # TODO check

    msg "Adding #{params["type"]} mirror of '#{params["remote"]}'" + (params["type"] == "git" ? ", branch '#{params["branch"]}'" : "") + "."

    # 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)
    fetch_remote(params["type"], local_branch)

    validate_revision_option(params, options)
    target = determine_target_commit(params, options)

    msg "Merging code into '#{mirror}/'."

    unless params["squash"]
      invoke(:git_merge_ours, target)
    end
    invoke(:git_read_tree, target, mirror)

    config.update(mirror, { "revision" => options["revision"] })
    add_config_file

    revision_message = options["revision"] ? " at #{display_revision(params["type"], options["revision"])}" : ""
    commit_message = "Add mirror '#{mirror}/'#{revision_message}."
    invoke(:git_commit, commit_message)
  end
end