Changeset 8923
- Timestamp:
- 02/22/08 03:38:08 (5 months ago)
- Files:
-
- tools/capistrano/CHANGELOG (modified) (1 diff)
- tools/capistrano/lib/capistrano/recipes/deploy/scm/git.rb (modified) (5 diffs)
- tools/capistrano/test/deploy/scm/git_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tools/capistrano/CHANGELOG
r8920 r8923 1 1 *SVN* 2 3 * Distributed git support for better operability with remote_cache strategy [voidlock] 2 4 3 5 * Use a default line length in help text if line length is otherwise too small [Jamis Buck] tools/capistrano/lib/capistrano/recipes/deploy/scm/git.rb
r8901 r8923 50 50 # or any SHA1 you are deploying, for example: 51 51 # 52 # set :branch, " origin/master"52 # set :branch, "master" 53 53 # 54 54 # Otherwise, HEAD is assumed. I strongly suggest you set this. HEAD is 55 55 # not always the best assumption. 56 # 57 # You may also set <tt>:remote</tt>, which will be used as a name for remote 58 # tracking of repositories. This option is intended for use with the 59 # <tt>:remote_cache</tt> strategy in a distributed git environment. 60 # 61 # For example in the projects <tt>config/deploy.rb</tt>: 62 # 63 # set :repository, "#{scm_user}@somehost:~/projects/project.git" 64 # set :remote, "#{scm_user}" 65 # 66 # Then each person with deploy priveledges can add the following to their 67 # local <tt>~/.caprc</tt> file: 68 # 69 # set :scm_user, 'someuser' 70 # 71 # Now any time a person deploys the project, their repository will be 72 # setup as a remote git repository within the cached repository. 56 73 # 57 74 # The <tt>:scm_command</tt> configuration variable, if specified, will … … 79 96 # 80 97 # For faster clone, you can also use shallow cloning. This will set the 81 # '--depth' flag using the depth specified. This *cannot* be used 98 # '--depth' flag using the depth specified. This *cannot* be used 82 99 # together with the :remote_cache strategy 83 100 # … … 89 106 # Garry Dolley http://scie.nti.st 90 107 # Contributions by Geoffrey Grosenbach http://topfunky.com 91 # and Scott Chacon http://jointheconversation.org 92 108 # Scott Chacon http://jointheconversation.org 109 # and Alex Arnell http://twologic.com 110 93 111 class Git < Base 94 112 # Sets the default command name for this SCM on your *local* machine. … … 103 121 end 104 122 123 def origin 124 configuration[:remote] || 'origin' 125 end 126 105 127 # Performs a clone on the remote machine, then checkout on the branch 106 128 # you want to deploy. 107 129 def checkout(revision, destination) 108 git = command 109 110 branch = head 111 112 fail "No branch specified, use for example 'set :branch, \"origin/master\"' in your deploy.rb" unless branch 130 git = command 131 remote = origin 132 133 args = [] 134 args << "-o #{remote}" unless remote == 'origin' 135 if depth = configuration[:git_shallow_clone] 136 args << "--depth #{depth}" 137 end 113 138 114 139 execute = [] 115 if depth = configuration[:git_shallow_clone]116 execute << "#{git} clone --depth #{depth}#{configuration[:repository]} #{destination}"140 if args.empty? 141 execute << "#{git} clone #{configuration[:repository]} #{destination}" 117 142 else 118 execute << "#{git} clone #{configuration[:repository]} #{destination}" 119 end 120 121 execute << "cd #{destination}" 122 execute << "#{git} checkout #{branch}" 143 execute << "#{git} clone #{args.join(' ')} #{configuration[:repository]} #{destination}" 144 end 145 146 # checkout into a local branch rather than a detached HEAD 147 execute << "cd #{destination} && #{git} checkout -b deploy #{revision}" 148 123 149 if configuration[:git_enable_submodules] 124 execute << "#{git} submodule init" 125 execute << "#{git} submodule update" 150 execute << "#{git} submodule init" 151 execute << "#{git} submodule update" 126 152 end 127 153 … … 132 158 # deployment strategy 133 159 def sync(revision, destination) 134 git = command 160 git = command 161 remote = origin 162 135 163 execute = [] 136 execute << "cd #{destination} && #{git} fetch origin" 137 138 if head == 'HEAD' 139 execute << "#{git} checkout origin/HEAD" 140 else 141 execute << "#{git} checkout #{head}" 142 end 143 164 execute << "cd #{destination}" 165 166 # Use git-config to setup a remote tracking branches. Could use 167 # git-remote but it complains when a remote of the same name already 168 # exists, git-config will just silenty overwrite the setting every 169 # time. This could cause wierd-ness in the remote cache if the url 170 # changes between calls, but as long as the repositories are all 171 # based from each other it should still work fine. 172 if remote != 'origin' 173 execute << "#{git} config remote.#{remote}.url #{configuration[:repository]}" 174 execute << "#{git} config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/*" 175 end 176 177 # since we're in a local branch already, just reset to specified revision rather than merge 178 execute << "#{git} fetch #{remote} && #{git} reset --hard #{revision}" 179 144 180 if configuration[:git_enable_submodules] 145 181 execute << "#{git} submodule update" tools/capistrano/test/deploy/scm/git_test.rb
r8904 r8923 20 20 end 21 21 22 def origin 23 asser_equal "origin", @source.origin 24 @config[:remote] = "git" 25 assert_equal "git", @source.origin 26 end 27 22 28 def test_checkout 23 29 @config[:repository] = "git@somehost.com:project.git" 24 30 dest = "/var/www" 25 assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout HEAD", @source.checkout('Not used', dest) 31 rev = 'c2d9e79' 32 assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest) 26 33 27 34 # With branch 28 35 @config[:branch] = "origin/foo" 29 assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout origin/foo", @source.checkout('Not used', dest)36 assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest) 30 37 end 31 38 … … 52 59 def test_sync 53 60 dest = "/var/www" 54 assert_equal "cd #{dest} && git fetch origin && git checkout origin/HEAD", @source.sync('Not used', dest) 61 rev = 'c2d9e79' 62 assert_equal "cd #{dest} && git fetch origin && git reset --hard #{rev}", @source.sync(rev, dest) 55 63 56 64 # With branch 57 @config[:branch] = "origin/foo" 58 assert_equal "cd #{dest} && git fetch origin && git checkout origin/foo", @source.sync('Not used', dest) 65 @config[:branch] = "foo" 66 rev = '92d9e79' # simulate rev change 67 assert_equal "cd #{dest} && git fetch origin && git reset --hard #{rev}", @source.sync(rev, dest) 59 68 60 69 # With :scm_command 61 @config[:scm_command] = "/opt/local/bin/git" 62 assert_equal "cd #{dest} && /opt/local/bin/git fetch origin && /opt/local/bin/git checkout origin/foo", @source.sync('Not used', dest) 70 git = "/opt/local/bin/git" 71 @config[:scm_command] = git 72 assert_equal "cd #{dest} && #{git} fetch origin && #{git} reset --hard #{rev}", @source.sync(rev, dest) 73 end 74 75 def test_sync_with_remote 76 dest = "/var/www" 77 rev = 'c2d9e79' 78 remote = "username" 79 repository = "git@somehost.com:project.git" 80 81 @config[:repository] = repository 82 @config[:remote] = remote 83 84 assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch #{remote} && git reset --hard #{rev}", @source.sync(rev, dest) 63 85 end 64 86 … … 67 89 @config[:git_shallow_clone] = 1 68 90 dest = "/var/www" 69 assert_equal "git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout HEAD", @source.checkout('Not used', dest) 91 rev = 'c2d9e79' 92 assert_equal "git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest) 70 93 71 94 # With branch 72 95 @config[:branch] = "origin/foo" 73 assert_equal "git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout origin/foo", @source.checkout('Not used', dest) 96 rev = '92d9e79' # simulate rev change 97 assert_equal "git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest) 98 end 99 100 def test_remote_clone 101 @config[:repository] = "git@somehost.com:project.git" 102 @config[:remote] = "username" 103 dest = "/var/www" 104 rev = 'c2d9e79' 105 assert_equal "git clone -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest) 106 107 # With branch 108 @config[:branch] = "foo" 109 assert_equal "git clone -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest) 74 110 end 75 111