Class: Capistrano::SCM::Git::WithSubmodules

Inherits:
Plugin
  • Object
show all
Defined in:
lib/capistrano/scm/git-with-submodules.rb

Instance Method Summary collapse

Instance Method Details

#define_tasksObject



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
40
41
42
43
44
45
46
47
48
49
# File 'lib/capistrano/scm/git-with-submodules.rb', line 9

def define_tasks
  namespace :git do
    namespace :submodules do

      desc "Adds configured submodules recursively to release"
      # It does so by connecting the bare repo and the work tree using environment variables
      # The reset creates a temporary index, but does not change the working directory
      # The temporary index is removed after everything is done
      task create_release: :'git:update' do
        temp_index_file_path = release_path.join("TEMP_INDEX_#{fetch(:release_timestamp)}")

        on release_roles :all do
          with fetch(:git_environmental_variables).merge(
              'GIT_DIR' => repo_path.to_s,
              'GIT_WORK_TREE' => release_path.to_s,
              'GIT_INDEX_FILE' => temp_index_file_path.to_s
          ) do
            within release_path do
              verbose = Rake.application.options.trace ? 'v' : ''
              quiet = Rake.application.options.trace ? '' : '--quiet'

              execute :git, :reset, '--mixed', quiet, fetch(:branch), '--'
              update_submodule = proc do
                execute :git, :submodule, 'update',
                        '--init', '--checkout', '--recursive', quiet
              end
              begin
                update_submodule.call
              rescue SSHKit::Command::Failed
                execute :git, :submodule, 'sync', '--recursive', quiet
                update_submodule.call
              end
              execute :find, release_path, "-name '.git'", "|",  "xargs -I {} rm -rf#{verbose} '{}'"
              execute :rm, "-f#{verbose}", temp_index_file_path.to_s
            end if test :test, '-f', release_path.join('.gitmodules')
          end
        end
      end
    end
  end
end

#register_hooksObject



5
6
7
# File 'lib/capistrano/scm/git-with-submodules.rb', line 5

def register_hooks
  after 'git:create_release', 'git:submodules:create_release'
end