Class: Braid::Commands::Remove

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

Instance Method Summary collapse

Methods inherited from Braid::Command

#config, msg, #msg, run, #verbose?

Methods included from Operations::VersionControl

#git, #git_cache, #git_svn, #gitclone, #svn

Instance Method Details

#run(path, 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
# File 'lib/braid/commands/remove.rb', line 4

def run(path, options = {})
  mirror = config.get!(path)

  bail_on_local_changes!

  with_reset_on_error do
    msg "Removing mirror from '#{mirror.path}'."

    if mirror.type == "git-clone"
      gitclone.remove_gitignore(mirror.path)
      FileUtils.rm_rf(mirror.path)
      config.remove(mirror)
      add_config_file
      commit_message = "Removed clone repository '#{mirror.path}'"
    else
      git.rm_r(mirror.path)

      config.remove(mirror)
      add_config_file

      if options[:keep]
        msg "Not removing remote '#{mirror.remote}'" if verbose?
      elsif git.remote_url(mirror.remote)
        msg "Removed remote '#{mirror.path}'" if verbose?
        git.remote_rm mirror.remote
      else
        msg "Remote '#{mirror.remote}' not found, nothing to cleanup" if verbose?
      end
      commit_message = "Removed mirror '#{mirror.path}'"
    end

    git.commit(commit_message)
    msg commit_message
  end
end