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

Ticket #9635 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Git SCM for Capistrano 2.0

Reported by: garrydolley Assigned to: minam
Priority: normal Milestone: 1.x
Component: Capistrano Version: edge
Severity: normal Keywords:
Cc:

Description

I'm submitting the module I wrote for Capistrano 2.0 that allows one to deploy from a Git repository. Parts of this plugin was borrowed from Scott Chacon's version, which I found on the Capistrano mailing list but failed to be able to get working. I believe my version is a bit more feature complete also.

Full details are in my announcement: http://scie.nti.st/2007/9/4/capistrano-2-0-with-git-shared-repository

To apply, download the patch, cd to your capistrano-2.0.0 directory and run:

patch -p1 < git-2.0.diff

Attachments

git-2.0.diff (11.4 kB) - added by garrydolley on 09/28/07 08:40:26.

Change History

09/23/07 11:37:07 changed by garrydolley

  • type changed from defect to enhancement.

09/25/07 15:56:44 changed by topfunky

The existing patch doesn't support the remote_cache deployment strategy. I've enhanced it to do that and will upload an enhanced patch with tests soon.

http://pastie.textmate.org/100640

09/26/07 17:28:44 changed by schacon

I've modified topfunkys patch with the ability to specify a depth for a shallow clone for a much faster clone if not using the remote_cache strategy.

http://pastie.textmate.org/101098

+1 - I've tested both garry's and topfunky's versions and they both work

09/26/07 19:12:44 changed by garrydolley

Thanks for the updates guys. I'll take both versions and attach an updated patch.

09/28/07 08:04:18 changed by garrydolley

topfunky,

There's an issue with the sync() method if someone specifies "origin/cool_branch" as the branch to deploy. All branches will be remote branches cloned from the push-only repo specified by :repository. Nothing new there. But, the sync() would generate:

git pull origin origin/cool_branch

which would be incorrect, "origin/" needs to be stripped off the branch name since origin is already specified as the remote (1st arg to pull).

Alternatively, since string manipulation does not sound like a good solution, we can modify the sync() like so:

git fetch origin && git merge origin/cool_branch

This does about the same thing, only difference is that the remote branch updates are stored, instead of thrown away with 'pull'. Requires more disk space but not much of an issue otherwise, IMO.

If no branch is specified at all, then the 2nd half of that command would reduce to "git merge HEAD", which does nothing useful. So I have to work that out.

Your thoughts?

09/28/07 08:40:26 changed by garrydolley

  • attachment git-2.0.diff added.

09/28/07 08:43:49 changed by garrydolley

Gentlemen,

I've updated the attached .diff with the contributions from topfunky and Scott. I had to modify sync() a bit, but the general idea is still there. I added tests for sync() and :git_shallow_clone.

Thanks guys for your contributions.

09/28/07 08:48:05 changed by garrydolley

Oh, and I answered my own question by playing around with a test repo. "git merge HEAD" doesn't do anything, but "git merge origin/HEAD" does indeed make the local branch up-to-date w/ the remote origin. Assuming we never checkout'd a specific branch (just left it at the default), origin's HEAD is the remote branch we'd be tracking.

09/28/07 14:54:23 changed by topfunky

+1

This works for me. Originally I was confused by the -b deploy on initial clone, but it makes sense now. I tried it with master and with other branches and it works correctly.

The only thing is that one may need to delete the repository_cache if deploying a different branch. I use this:

desc "Delete repository cache on server"
task :delete_repository_cache do
  run "rm -rf #{shared_path}/#{repository_cache}"
end

09/28/07 19:37:58 changed by garrydolley

Yep, without "-b deploy" you'll get a warning each time you checkout.

Regarding the repistory_cache, they'll indeed need to delete the cache if a different branch is deployed. I wonder if we could detect what branch they "came from" (sibling of "deploy"), and if a different one is deployed, it'll do a checkout instead of merge. I'll play around with this some.

09/30/07 15:05:00 changed by minam

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

(In [7695]) Git SCM module (closes #9635)

09/30/07 15:05:59 changed by minam

Thanks for the excellent patch! I decided to apply it to the 2.1 release after all, given that it doesn't touch any existing functionality and looks well tested and reviewed.