Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10918 (closed defect: fixed)

Opened 10 months ago

Last modified 9 months ago

Git module for capistrano should use checkout instead of merge.

Reported by: nuttycom Assigned to: minam
Priority: normal Milestone: 2.x
Component: Capistrano Version: edge
Severity: normal Keywords: capistrano 2.1.0
Cc:

Description

The current git recipe for capistrano uses "git checkout -b #{branchname}" and "git merge #{head}" to update the code to be deployed. However, this doesn't make much sense since these merges can create conflicts when switching the deployment branch. Since there is no need to edit the code on the deployment server, it makes much more sense to simply check out the appropriate origin branch for deployment.

A patch to fix this problem (by simply using checkout instead of branch & merge) is attached. The patch was generated against the source of the capistrano-2.1.0 gem.

Attachments

git.rb.patch (0.9 kB) - added by nuttycom on 01/24/08 21:49:35.
Patch to use git checkout instead of branch & merge

Change History

01/24/08 21:49:35 changed by nuttycom

  • attachment git.rb.patch added.

Patch to use git checkout instead of branch & merge

01/25/08 19:24:24 changed by jwarchol

+1 Works for me.

01/25/08 19:28:14 changed by galtenberg

+1 so far so good

01/30/08 17:48:04 changed by stetz

+1 git 2 it!

01/30/08 17:50:59 changed by francp

+1

01/30/08 17:55:08 changed by nuttycom

  • keywords changed from capistrano 2.1.0 to capistrano 2.1.0 verified.

01/30/08 18:15:31 changed by rfg

+1 :)

02/15/08 23:24:14 changed by nzkoz

  • keywords changed from capistrano 2.1.0 verified to capistrano 2.1.0.

Removing verified tag as that's for rails patches, not capistrano ones.

However, this looks good jamis :)

02/19/08 23:19:57 changed by minam

  • status changed from new to closed.
  • resolution set to fixed.

(In [8901]) use checkout instead of merge for git SCM (closes #10918)

02/25/08 22:52:01 changed by garrydolley

But if the code never changes on the server, like you mentioned, why would there be conflicts?

You removed the "-b" in checkout, which I had originally when I wrote this module, it causes problems in the long run.

IMO, I'd say don't apply this patch, but I guess it's too late.

02/26/08 02:12:00 changed by garrydolley

This patch, accepted into rev 8901, produces failing test cases:

/Volumes/FLASH/dev/capistrano $ svn up -r 8901
U    test/deploy/scm/git_test.rb
U    test/configuration/namespace_dsl_test.rb
U    lib/capistrano/upload.rb
U    lib/capistrano/recipes/deploy/scm/subversion.rb
U    lib/capistrano/recipes/deploy/scm/git.rb
U    lib/capistrano/configuration/namespaces.rb
U    CHANGELOG
Updated to revision 8901.
/Volumes/FLASH/dev/capistrano $ ruby test/deploy/scm/git_test.rb 
Loaded suite test/deploy/scm/git_test
Started
F............FF
Finished in 0.104176 seconds.

  1) Failure:
test_checkout(DeploySCMGitTest)
    [test/deploy/scm/git_test.rb:25:in `test_checkout'
     /Users/garry/sys//lib/ruby/gems/1.8/gems/mocha-0.5.5/lib/mocha/test_case_adapter.rb:19:in `run']:
<"git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy HEAD"> expected but was
<"git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout HEAD">.

  2) Failure:
test_shallow_clone(DeploySCMGitTest)
    [test/deploy/scm/git_test.rb:69:in `test_shallow_clone'
     /Users/garry/sys//lib/ruby/gems/1.8/gems/mocha-0.5.5/lib/mocha/test_case_adapter.rb:19:in `run']:
<"git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy HEAD"> expected but was
<"git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout HEAD">.

  3) Failure:
test_sync(DeploySCMGitTest)
    [test/deploy/scm/git_test.rb:54:in `test_sync'
     /Users/garry/sys//lib/ruby/gems/1.8/gems/mocha-0.5.5/lib/mocha/test_case_adapter.rb:19:in `run']:
<"cd /var/www && git fetch origin && git merge origin/HEAD"> expected but was
<"cd /var/www && git fetch origin && git checkout origin/HEAD">.

15 tests, 21 assertions, 3 failures, 0 errors

What the heck guys? I wrote those tests so this kind of breakage wouldn't occur.

The Rails patch submission guidelines even say to provide test cases, I figured it was *assumed* that existing tests should pass also.

With these test failures, I must -1 this patch (too late, but oh well).

02/26/08 23:23:51 changed by nuttycom

"But if the code never changes on the server, like you mentioned, why would there be conflicts?"

Here's the scenario where I encountered conflicts:

We have 3 branches: master, release-1.0, bugfix-1.0. bugfix-1.0 has descended from release-1.0, which is descended from master. bugfix-1.0 is the release currently deployed on the server. Now, when we cut release-2.0 from master, which has changed significantly since release-1.0 including the removal of some files that are in bugfix-1.0, if we do a merge onto the deploy branch, it will create conflicts because the new release is not descended from bugfix-1.0.

Using the checkout avoids this entirely. Sorry that I missed fixing those tests - I'll create a patch shortly.

02/26/08 23:32:03 changed by garrydolley

OK, I see where the conflicts can arise, thanks for the explanation.

No need for a patch on those tests, b/c later patches were applied and it rakes clean. The current version doesn't even use your switch from "merge" to "checkout", in fact it uses "reset --hard". I'm not sure why it was changed, I don't like to do reset on anything unless absolutely necessary.

02/26/08 23:42:06 changed by nuttycom

Ah, that makes sense. reset --hard just sets the current HEAD, so it's actually a little safer than checkout because checkout will fail if there are uncommitted changes.