capistrano-scm-gitcopy 0.0.8 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +3 -0
 - data/capistrano-scm-gitcopy.gemspec +15 -12
 - data/lib/capistrano/gitcopy.rb +65 -0
 - data/lib/capistrano/tasks/gitcopy.rake +83 -29
 - data/spec/lib/capistrano/gitcopy_spec.rb +113 -0
 - data/spec/spec_helper.rb +16 -0
 - metadata +36 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 5d35e2b43b2d196cc35eccfa170dcd701aacdd4e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: defb71f2f16a188a6206029c613103586269aaca
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 8e1eb382e5054e69d52090b8ddc24651744f34a563c56c90e4ac314fe389d1b0a7e4ac71d08cdbf19318b51c344fa522438145d67987d9ed61682ac60f6aafd0
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: de3ebff42cbc833879194ebc1f8486335bdabc65d5fb30d5de6bff9e278953be0ad40c35028b2f39c485e21d938aaa69342cb52bf20e43d49cd4b7c98f4de524
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -25,6 +25,7 @@ Servers: 
     | 
|
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
            - mktemp
         
     | 
| 
       27 
27 
     | 
    
         
             
            - tar
         
     | 
| 
      
 28 
     | 
    
         
            +
            - ruby
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         
             
            Installation
         
     | 
| 
       30 
31 
     | 
    
         
             
            ============
         
     | 
| 
         @@ -37,6 +38,8 @@ Then switch the `:scm` option to `:gitcopy` in `config/deploy.rb`: 
     | 
|
| 
       37 
38 
     | 
    
         | 
| 
       38 
39 
     | 
    
         
             
                set :scm, :gitcopy
         
     | 
| 
       39 
40 
     | 
    
         | 
| 
      
 41 
     | 
    
         
            +
            Finally, DO NOT ADD `require 'capistrano/gitcopy'` to `Capfile` because `capistrano/setup` already loads the scm module with the :scm value you specified.
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
       40 
43 
     | 
    
         | 
| 
       41 
44 
     | 
    
         
             
            Usage
         
     | 
| 
       42 
45 
     | 
    
         
             
            ============
         
     | 
| 
         @@ -1,21 +1,24 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # -*- encoding: utf-8 -*-
         
     | 
| 
       2 
     | 
    
         
            -
            $:.push File.expand_path( 
     | 
| 
      
 2 
     | 
    
         
            +
            $:.push File.expand_path('../lib', __FILE__)
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       5 
     | 
    
         
            -
              s.name        =  
     | 
| 
       6 
     | 
    
         
            -
              s.version     =  
     | 
| 
       7 
     | 
    
         
            -
              s.licenses    = [ 
     | 
| 
       8 
     | 
    
         
            -
              s.authors     = [ 
     | 
| 
       9 
     | 
    
         
            -
              s.email       = [ 
     | 
| 
       10 
     | 
    
         
            -
              s.homepage    =  
     | 
| 
      
 5 
     | 
    
         
            +
              s.name        = 'capistrano-scm-gitcopy'
         
     | 
| 
      
 6 
     | 
    
         
            +
              s.version     = '0.1.2'
         
     | 
| 
      
 7 
     | 
    
         
            +
              s.licenses    = ['MIT']
         
     | 
| 
      
 8 
     | 
    
         
            +
              s.authors     = ['Jack Wu', 'Carl Douglas']
         
     | 
| 
      
 9 
     | 
    
         
            +
              s.email       = ['xuwupeng2000@gmail.com']
         
     | 
| 
      
 10 
     | 
    
         
            +
              s.homepage    = 'https://github.com/xuwupeng2000/capsitrano-scm-gitcopy.git'
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.summary     = %q{Gitcopy strategy for capistrano 3.x}
         
     | 
| 
       12 
12 
     | 
    
         
             
              s.description = %q{Gitcopy strategy for capistrano 3.x}
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              s.files         = `git ls-files`.split 
     | 
| 
       15 
     | 
    
         
            -
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split 
     | 
| 
       16 
     | 
    
         
            -
              s.executables   = `git ls-files -- bin/*`.split 
     | 
| 
       17 
     | 
    
         
            -
              s.require_paths = [ 
     | 
| 
      
 14 
     | 
    
         
            +
              s.files         = `git ls-files`.split
         
     | 
| 
      
 15 
     | 
    
         
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split
         
     | 
| 
      
 16 
     | 
    
         
            +
              s.executables   = `git ls-files -- bin/*`.split.map{ |f| File.basename(f) }
         
     | 
| 
      
 17 
     | 
    
         
            +
              s.require_paths = ['lib']
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
              # specify any dependencies here; for example:
         
     | 
| 
       20 
     | 
    
         
            -
              s.add_dependency  
     | 
| 
      
 20 
     | 
    
         
            +
              s.add_dependency 'capistrano', '~> 3.0'
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              s.add_development_dependency 'rspec', '~> 3.0.0'
         
     | 
| 
      
 23 
     | 
    
         
            +
              s.add_development_dependency 'mocha', '~> 1.1.0'
         
     | 
| 
       21 
24 
     | 
    
         
             
            end
         
     | 
    
        data/lib/capistrano/gitcopy.rb
    CHANGED
    
    | 
         @@ -1 +1,66 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            load File.expand_path('../tasks/gitcopy.rake', __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'capistrano/scm'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            set_if_empty :repo_path, -> { "/tmp/#{fetch(:application)}-repository" }
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class Capistrano::GitCopy < Capistrano::SCM
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              # execute git with argument in the context
         
     | 
| 
      
 10 
     | 
    
         
            +
              #
         
     | 
| 
      
 11 
     | 
    
         
            +
              def git(*args)
         
     | 
| 
      
 12 
     | 
    
         
            +
                args.unshift :git
         
     | 
| 
      
 13 
     | 
    
         
            +
                context.execute(*args)
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              module DefaultStrategy
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def test
         
     | 
| 
      
 19 
     | 
    
         
            +
                  test! " [ -f #{repo_path}/HEAD ] "
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def check
         
     | 
| 
      
 23 
     | 
    
         
            +
                  git :'ls-remote --heads', repo_url
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def clone
         
     | 
| 
      
 27 
     | 
    
         
            +
                  if (depth = fetch(:git_shallow_clone))
         
     | 
| 
      
 28 
     | 
    
         
            +
                    git :clone, '--verbose', '--mirror', '--depth', depth, '--no-single-branch', repo_url, repo_path
         
     | 
| 
      
 29 
     | 
    
         
            +
                  else
         
     | 
| 
      
 30 
     | 
    
         
            +
                    git :clone, '--verbose', '--mirror', repo_url, repo_path
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def update
         
     | 
| 
      
 35 
     | 
    
         
            +
                  # Note: Requires git version 1.9 or greater
         
     | 
| 
      
 36 
     | 
    
         
            +
                  if (depth = fetch(:git_shallow_clone))
         
     | 
| 
      
 37 
     | 
    
         
            +
                    git :fetch, '--depth', depth, 'origin', fetch(:branch)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  else
         
     | 
| 
      
 39 
     | 
    
         
            +
                    git :remote, :update
         
     | 
| 
      
 40 
     | 
    
         
            +
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                def fetch_revision
         
     | 
| 
      
 44 
     | 
    
         
            +
                  context.capture(:git, "rev-list --max-count=1 --abbrev-commit --abbrev=12 #{fetch(:branch)}")
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                def local_tarfile
         
     | 
| 
      
 48 
     | 
    
         
            +
                  "#{fetch(:tmp_dir)}/#{fetch(:application)}-#{fetch(:current_revision).strip}.tar.gz"
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                def remote_tarfile
         
     | 
| 
      
 52 
     | 
    
         
            +
                  "#{fetch(:tmp_dir)}/#{fetch(:application)}-#{fetch(:current_revision).strip}.tar.gz"
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                def release
         
     | 
| 
      
 56 
     | 
    
         
            +
                  if (tree = fetch(:repo_tree))
         
     | 
| 
      
 57 
     | 
    
         
            +
                    tree = tree.slice %r#^/?(.*?)/?$#, 1
         
     | 
| 
      
 58 
     | 
    
         
            +
                    components = tree.split('/').size
         
     | 
| 
      
 59 
     | 
    
         
            +
                    git :archive, fetch(:branch), tree, '--format', 'tar', "|gzip > #{local_tarfile}"
         
     | 
| 
      
 60 
     | 
    
         
            +
                  else
         
     | 
| 
      
 61 
     | 
    
         
            +
                    git :archive, fetch(:branch), '--format', 'tar', "|gzip > #{local_tarfile}"
         
     | 
| 
      
 62 
     | 
    
         
            +
                  end
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
              end 
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,46 +1,100 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            namespace :gitcopy do
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
               
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
              desc "Archive files to #{archive_name}"
         
     | 
| 
       6 
     | 
    
         
            -
              file archive_name do |file| 
         
     | 
| 
       7 
     | 
    
         
            -
                system "git ls-remote #{fetch(:repo_url)} | grep #{fetch(:branch)}"
         
     | 
| 
       8 
     | 
    
         
            -
                if $?.exitstatus == 0
         
     | 
| 
       9 
     | 
    
         
            -
                  system "git archive --remote #{fetch(:repo_url)} --format=tar #{fetch(:branch)}:#{fetch(:sub_directory)} | gzip > #{ archive_name }"
         
     | 
| 
       10 
     | 
    
         
            -
                else
         
     | 
| 
       11 
     | 
    
         
            -
                  puts "Can't find commit for: #{fetch(:branch)}"
         
     | 
| 
       12 
     | 
    
         
            -
                end
         
     | 
| 
      
 3 
     | 
    
         
            +
              def strategy
         
     | 
| 
      
 4 
     | 
    
         
            +
                @strategy ||= Capistrano::GitCopy.new(self, fetch(:git_strategy, Capistrano::GitCopy::DefaultStrategy))
         
     | 
| 
       13 
5 
     | 
    
         
             
              end
         
     | 
| 
       14 
6 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
               
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
              set :git_environmental_variables, ->() {
         
     | 
| 
      
 8 
     | 
    
         
            +
                {
         
     | 
| 
      
 9 
     | 
    
         
            +
                  git_askpass: "/bin/echo",
         
     | 
| 
      
 10 
     | 
    
         
            +
                  git_ssh:     "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
         
     | 
| 
      
 11 
     | 
    
         
            +
                }
         
     | 
| 
      
 12 
     | 
    
         
            +
              }
         
     | 
| 
       21 
13 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
              desc 'Generate the git wrapper script, this script guarantees that we can script git without getting an interactive prompt'
         
     | 
| 
      
 15 
     | 
    
         
            +
              task :wrapper do
         
     | 
| 
      
 16 
     | 
    
         
            +
                run_locally do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  execute :mkdir, "-p", "#{fetch(:tmp_dir)}/#{fetch(:application)}/"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  File.open("#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh", "w") do |file|
         
     | 
| 
      
 19 
     | 
    
         
            +
                    file.write ("#!/bin/sh -e\nexec /usr/bin/ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no \"$@\"\n")
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
                  execute :chmod, "+x", "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
              desc 'Check that the repository is reachable'
         
     | 
| 
      
 26 
     | 
    
         
            +
              task :check => :'gitcopy:wrapper' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                fetch(:branch)
         
     | 
| 
      
 28 
     | 
    
         
            +
                run_locally do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  with fetch(:git_environmental_variables) do
         
     | 
| 
      
 30 
     | 
    
         
            +
                    strategy.check
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
       29 
32 
     | 
    
         
             
                end
         
     | 
| 
       30 
33 
     | 
    
         
             
              end
         
     | 
| 
       31 
34 
     | 
    
         | 
| 
      
 35 
     | 
    
         
            +
              desc 'Clone the repo to the cache'
         
     | 
| 
      
 36 
     | 
    
         
            +
              task :clone => :'gitcopy:wrapper' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                run_locally do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  execute :mkdir, '-p', repo_path
         
     | 
| 
      
 39 
     | 
    
         
            +
                  if strategy.test
         
     | 
| 
      
 40 
     | 
    
         
            +
                    info t(:mirror_exists, at: repo_path)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  else
         
     | 
| 
      
 42 
     | 
    
         
            +
                    within repo_path do
         
     | 
| 
      
 43 
     | 
    
         
            +
                      with fetch(:git_environmental_variables) do
         
     | 
| 
      
 44 
     | 
    
         
            +
                        strategy.clone
         
     | 
| 
      
 45 
     | 
    
         
            +
                      end
         
     | 
| 
      
 46 
     | 
    
         
            +
                    end
         
     | 
| 
      
 47 
     | 
    
         
            +
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
       32 
50 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
               
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
      
 51 
     | 
    
         
            +
              desc 'Update the repo mirror to reflect the origin state'
         
     | 
| 
      
 52 
     | 
    
         
            +
              task :update => :'gitcopy:clone' do
         
     | 
| 
      
 53 
     | 
    
         
            +
                run_locally do
         
     | 
| 
      
 54 
     | 
    
         
            +
                  within repo_path do
         
     | 
| 
      
 55 
     | 
    
         
            +
                    with fetch(:git_environmental_variables) do
         
     | 
| 
      
 56 
     | 
    
         
            +
                      strategy.update
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
       36 
60 
     | 
    
         
             
              end
         
     | 
| 
       37 
     | 
    
         
            -
              after 'deploy:finished', 'gitcopy:clean'
         
     | 
| 
       38 
61 
     | 
    
         | 
| 
      
 62 
     | 
    
         
            +
              desc 'Create tarfile'
         
     | 
| 
      
 63 
     | 
    
         
            +
              task :create_tarfile => [:'gitcopy:update', :'gitcopy:set_current_revision'] do
         
     | 
| 
      
 64 
     | 
    
         
            +
                run_locally do
         
     | 
| 
      
 65 
     | 
    
         
            +
                  within repo_path do
         
     | 
| 
      
 66 
     | 
    
         
            +
                    with fetch(:git_environmental_variables) do
         
     | 
| 
      
 67 
     | 
    
         
            +
                      strategy.release
         
     | 
| 
      
 68 
     | 
    
         
            +
                    end
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
       39 
72 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
               
     | 
| 
      
 73 
     | 
    
         
            +
              desc 'Copy repo to releases'
         
     | 
| 
      
 74 
     | 
    
         
            +
              task :create_release => :'gitcopy:create_tarfile' do
         
     | 
| 
       41 
75 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 76 
     | 
    
         
            +
                on release_roles :all do
         
     | 
| 
      
 77 
     | 
    
         
            +
                  within deploy_to do
         
     | 
| 
      
 78 
     | 
    
         
            +
                    execute :mkdir, '-p', release_path
         
     | 
| 
      
 79 
     | 
    
         
            +
                    upload! strategy.local_tarfile, strategy.remote_tarfile
         
     | 
| 
      
 80 
     | 
    
         
            +
                    execute :tar, '--extract --verbose --file', strategy.remote_tarfile, '--directory', release_path
         
     | 
| 
      
 81 
     | 
    
         
            +
                    execute :rm, strategy.remote_tarfile
         
     | 
| 
      
 82 
     | 
    
         
            +
                  end
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
       43 
84 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
                run_locally do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  if File.exists? strategy.local_tarfile
         
     | 
| 
      
 87 
     | 
    
         
            +
                    execute :rm, strategy.local_tarfile
         
     | 
| 
      
 88 
     | 
    
         
            +
                  end
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
              end
         
     | 
| 
       45 
91 
     | 
    
         | 
| 
      
 92 
     | 
    
         
            +
              desc 'Determine the revision that will be deployed'
         
     | 
| 
      
 93 
     | 
    
         
            +
              task :set_current_revision do
         
     | 
| 
      
 94 
     | 
    
         
            +
                run_locally do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  with fetch(:git_environmental_variables) do
         
     | 
| 
      
 96 
     | 
    
         
            +
                    set :current_revision, strategy.fetch_revision
         
     | 
| 
      
 97 
     | 
    
         
            +
                  end
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
              end
         
     | 
| 
       46 
100 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,113 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'capistrano/gitcopy'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module Capistrano
         
     | 
| 
      
 6 
     | 
    
         
            +
              describe GitCopy do
         
     | 
| 
      
 7 
     | 
    
         
            +
                let(:context) { Class.new.new }
         
     | 
| 
      
 8 
     | 
    
         
            +
                subject { Capistrano::GitCopy.new(context, Capistrano::GitCopy::DefaultStrategy) }
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                describe "#git" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                  it "should call execute git in the context, with arguments" do
         
     | 
| 
      
 12 
     | 
    
         
            +
                    context.expects(:execute).with(:git, :init)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    subject.git(:init)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              describe GitCopy::DefaultStrategy do
         
     | 
| 
      
 19 
     | 
    
         
            +
                let(:context) { Class.new.new }
         
     | 
| 
      
 20 
     | 
    
         
            +
                subject { Capistrano::GitCopy.new(context, Capistrano::GitCopy::DefaultStrategy) }
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                describe "#test" do
         
     | 
| 
      
 23 
     | 
    
         
            +
                  it "should call test for repo HEAD" do
         
     | 
| 
      
 24 
     | 
    
         
            +
                    context.expects(:repo_path).returns("/path/to/repo")
         
     | 
| 
      
 25 
     | 
    
         
            +
                    context.expects(:test).with " [ -f /path/to/repo/HEAD ] "
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                    subject.test
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                describe "#check" do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  it "should test the repo url" do
         
     | 
| 
      
 33 
     | 
    
         
            +
                    context.expects(:repo_url).returns(:url)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    context.expects(:execute).with(:git, :'ls-remote --heads', :url).returns(true)
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                    subject.check
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                describe "#clone" do
         
     | 
| 
      
 41 
     | 
    
         
            +
                  it "should run git clone" do
         
     | 
| 
      
 42 
     | 
    
         
            +
                    context.expects(:fetch).with(:git_shallow_clone).returns(nil)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    context.expects(:repo_url).returns(:url)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    context.expects(:repo_path).returns(:path)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    context.expects(:execute).with(:git, :clone, '--verbose', '--mirror', :url, :path)
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                    subject.clone
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  it "should run git clone in shallow mode" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                    context.expects(:fetch).with(:git_shallow_clone).returns('1')
         
     | 
| 
      
 52 
     | 
    
         
            +
                    context.expects(:repo_url).returns(:url)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    context.expects(:repo_path).returns(:path)
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    context.expects(:execute).with(:git, :clone, '--verbose', '--mirror', "--depth", '1', '--no-single-branch', :url, :path)
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                    subject.clone
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                describe "#update" do
         
     | 
| 
      
 62 
     | 
    
         
            +
                  it "should run git update" do
         
     | 
| 
      
 63 
     | 
    
         
            +
                    context.expects(:fetch).with(:git_shallow_clone).returns(nil)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    context.expects(:execute).with(:git, :remote, :update)
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                    subject.update
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  it "should run git update in shallow mode" do
         
     | 
| 
      
 70 
     | 
    
         
            +
                    context.expects(:fetch).with(:git_shallow_clone).returns('1')
         
     | 
| 
      
 71 
     | 
    
         
            +
                    context.expects(:fetch).with(:branch).returns(:branch)
         
     | 
| 
      
 72 
     | 
    
         
            +
                    context.expects(:execute).with(:git, :fetch, "--depth", '1', "origin",  :branch)
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                    subject.update
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                describe "#release" do
         
     | 
| 
      
 79 
     | 
    
         
            +
                  it "should run git archive without a subtree" do
         
     | 
| 
      
 80 
     | 
    
         
            +
                    context.expects(:fetch).with(:repo_tree).returns(nil)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    context.expects(:fetch).with(:branch).returns(:branch)
         
     | 
| 
      
 82 
     | 
    
         
            +
                    context.expects(:fetch).with(:tmp_dir).returns('/tmp')
         
     | 
| 
      
 83 
     | 
    
         
            +
                    context.expects(:fetch).with(:application).returns('rspec-test')
         
     | 
| 
      
 84 
     | 
    
         
            +
                    context.expects(:fetch).with(:current_revision).returns('ABCDEF')
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                    context.expects(:execute).with(:git, :archive, :branch, '--format', 'tar', "|gzip > /tmp/rspec-test-ABCDEF.tar.gz")
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                    subject.release
         
     | 
| 
      
 89 
     | 
    
         
            +
                  end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                  it "should run git archive with a subtree" do
         
     | 
| 
      
 92 
     | 
    
         
            +
                    context.expects(:fetch).with(:repo_tree).returns('tree')
         
     | 
| 
      
 93 
     | 
    
         
            +
                    context.expects(:fetch).with(:branch).returns(:branch)
         
     | 
| 
      
 94 
     | 
    
         
            +
                    context.expects(:fetch).with(:tmp_dir).returns('/tmp')
         
     | 
| 
      
 95 
     | 
    
         
            +
                    context.expects(:fetch).with(:application).returns('rspec-test')
         
     | 
| 
      
 96 
     | 
    
         
            +
                    context.expects(:fetch).with(:current_revision).returns('ABCDEF')
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                    context.expects(:execute).with(:git, :archive, :branch, 'tree', '--format', 'tar', "|gzip > /tmp/rspec-test-ABCDEF.tar.gz")
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                    subject.release
         
     | 
| 
      
 101 
     | 
    
         
            +
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                describe "#fetch_revision" do
         
     | 
| 
      
 105 
     | 
    
         
            +
                  it "should capture git rev-list" do
         
     | 
| 
      
 106 
     | 
    
         
            +
                    context.expects(:fetch).with(:branch).returns(:branch)
         
     | 
| 
      
 107 
     | 
    
         
            +
                    context.expects(:capture).with(:git, "rev-list --max-count=1 --abbrev-commit --abbrev=12 branch").returns("01abcde")
         
     | 
| 
      
 108 
     | 
    
         
            +
                    revision = subject.fetch_revision
         
     | 
| 
      
 109 
     | 
    
         
            +
                    expect(revision).to eq("01abcde")
         
     | 
| 
      
 110 
     | 
    
         
            +
                  end
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
      
 112 
     | 
    
         
            +
              end
         
     | 
| 
      
 113 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         
     | 
| 
      
 2 
     | 
    
         
            +
            $LOAD_PATH.unshift(File.dirname(__FILE__))
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'capistrano/all'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'rspec'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'mocha/api'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'time'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            # Requires supporting files with custom matchers and macros, etc,
         
     | 
| 
      
 9 
     | 
    
         
            +
            # in ./support/ and its subdirectories.
         
     | 
| 
      
 10 
     | 
    
         
            +
            Dir['#{File.dirname(__FILE__)}/support/**/*.rb'].each {|f| require f}
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            RSpec.configure do |config|
         
     | 
| 
      
 13 
     | 
    
         
            +
            	config.raise_errors_for_deprecations!
         
     | 
| 
      
 14 
     | 
    
         
            +
              config.mock_framework = :mocha
         
     | 
| 
      
 15 
     | 
    
         
            +
              config.order = 'random'
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: capistrano-scm-gitcopy
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jack Wu
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date:  
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2016-01-30 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: capistrano
         
     | 
| 
         @@ -25,6 +25,34 @@ dependencies: 
     | 
|
| 
       25 
25 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       26 
26 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       27 
27 
     | 
    
         
             
                    version: '3.0'
         
     | 
| 
      
 28 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 29 
     | 
    
         
            +
              name: rspec
         
     | 
| 
      
 30 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 31 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 32 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 33 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 34 
     | 
    
         
            +
                    version: 3.0.0
         
     | 
| 
      
 35 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 36 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 37 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 38 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 39 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 40 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 41 
     | 
    
         
            +
                    version: 3.0.0
         
     | 
| 
      
 42 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 43 
     | 
    
         
            +
              name: mocha
         
     | 
| 
      
 44 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 45 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 46 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 47 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 48 
     | 
    
         
            +
                    version: 1.1.0
         
     | 
| 
      
 49 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 50 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 51 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 52 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 53 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 54 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 55 
     | 
    
         
            +
                    version: 1.1.0
         
     | 
| 
       28 
56 
     | 
    
         
             
            description: Gitcopy strategy for capistrano 3.x
         
     | 
| 
       29 
57 
     | 
    
         
             
            email:
         
     | 
| 
       30 
58 
     | 
    
         
             
            - xuwupeng2000@gmail.com
         
     | 
| 
         @@ -41,6 +69,8 @@ files: 
     | 
|
| 
       41 
69 
     | 
    
         
             
            - lib/capistrano-scm-gitcopy.rb
         
     | 
| 
       42 
70 
     | 
    
         
             
            - lib/capistrano/gitcopy.rb
         
     | 
| 
       43 
71 
     | 
    
         
             
            - lib/capistrano/tasks/gitcopy.rake
         
     | 
| 
      
 72 
     | 
    
         
            +
            - spec/lib/capistrano/gitcopy_spec.rb
         
     | 
| 
      
 73 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     | 
| 
       44 
74 
     | 
    
         
             
            homepage: https://github.com/xuwupeng2000/capsitrano-scm-gitcopy.git
         
     | 
| 
       45 
75 
     | 
    
         
             
            licenses:
         
     | 
| 
       46 
76 
     | 
    
         
             
            - MIT
         
     | 
| 
         @@ -61,8 +91,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       61 
91 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       62 
92 
     | 
    
         
             
            requirements: []
         
     | 
| 
       63 
93 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       64 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 94 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
       65 
95 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       66 
96 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       67 
97 
     | 
    
         
             
            summary: Gitcopy strategy for capistrano 3.x
         
     | 
| 
       68 
     | 
    
         
            -
            test_files: 
     | 
| 
      
 98 
     | 
    
         
            +
            test_files:
         
     | 
| 
      
 99 
     | 
    
         
            +
            - spec/lib/capistrano/gitcopy_spec.rb
         
     | 
| 
      
 100 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     |