Class: Dotty::RepositoryActions

Inherits:
Thor
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/dotty/repository_actions.rb

Constant Summary collapse

USER_HOME =
Thor::Util.user_home

Instance Method Summary collapse

Methods included from Helpers

#error, #remove_symlink

Instance Method Details

#bootstrap(repo) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dotty/repository_actions.rb', line 37

def bootstrap(repo)
  say_status "bootstrap", repo.name, :blue
  with_padding do
    # Create symlinks defined in dotty-symlinks.yml
    repo.symlinks.each do |source, destination_filename|
      create_link File.join(USER_HOME, destination_filename), File.join(repo.local_path, source)
    end

    # Execute repository's bootstrap task
    thor_file_path = File.join(repo.local_path, 'dotty-repository.thor')
    if File.exist? thor_file_path
      inside repo.local_path do
        run "thor dotty_repository:bootstrap"
      end
    end
  end
end

#checkout(repo) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/dotty/repository_actions.rb', line 27

def checkout(repo)
  say_status "add repo", "#{repo.name} => #{repo.url}", :blue
  FileUtils.mkdir_p repo.local_path
  run "git clone #{repo.url} #{repo.local_path}"
  inside repo.local_path do
    run "git submodule update --init"
  end
end

#create(repo) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/dotty/repository_actions.rb', line 9

def create(repo)
  say_status "create repo", "#{repo.name} [#{repo.url}]", :blue
  FileUtils.mkdir_p repo.local_path
  run "git init #{repo.local_path}"
  inside repo.local_path do
    run "git remote add origin #{repo.url}"
  end
end

#destroy(repo) ⇒ Object



19
20
21
22
23
24
# File 'lib/dotty/repository_actions.rb', line 19

def destroy(repo)
  say_status "remove repo", repo.name, :blue
  implode repo
  say_status "remove", repo.local_path
  FileUtils.rm_rf repo.local_path
end

#implode(repo) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dotty/repository_actions.rb', line 56

def implode(repo)
  say_status "implode", repo.name, :blue

  # Remove symlinks defined in dotty-symlinks.yml
  repo.symlinks.each do |source, destination_filename|
    destination_path = File.join(USER_HOME, destination_filename)
    remove_symlink destination_path
  end

  # Execute repository's implode task
  thor_file_path = File.join(repo.local_path, 'dotty-repository.thor')
  if File.exist? thor_file_path
    inside repo.local_path do
      run "thor dotty_repository:implode"
    end
  end
end

#update(repo) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/dotty/repository_actions.rb', line 75

def update(repo)
  say_status "update", repo.name, :blue

  inside repo.local_path do
    run "git fetch && git pull && git submodule update --init"
  end
end

#update_submodules(repo) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dotty/repository_actions.rb', line 88

def update_submodules(repo)
  say_status "update submodules", repo.name, :blue
  inside repo.local_path do
    cmd = []
    cmd << "git submodule update --init"
    cmd << "git submodule foreach git pull origin master"
    if options[:commit]
      changes = run('git status -s', :capture => true)
      if options[:ignoredirty] or [nil, ""].include?(changes)
        cmd << "git commit -am '#{options[:commit_message]}'"
      else
        raise Dotty::Error, "Repository '#{repo.name}' is not in a clean state - cannot commit updated submodules"
      end
      options[:push] && cmd << "git push"
    end
    run cmd.join(" && ")
  end
end