Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Reduced amount of checkout, simplifying things a bit. #14

Open
wants to merge 2 commits into from

2 participants

Jarl Friis Aaron Suggs
Jarl Friis

This is also to unify that revision is in context of the repository (not the local working repository)

Jarl Friis

You should also be aware of seattlerb/rake-remote_task#19

Aaron Suggs

Why do you remove fast checkout? It provides a great speed boost on subsequent deploys.

It is errorprone. The temporary repository in #{destination} can be different from the repository set with set :repository. Some may actually have changed the the :repository in such a degree that a given tag or branch (say master) is changed. Further it may be that "#{git_cmd} remote -v | grep -q #{repository}" returns true, but the repository is no more origin, but maybe old_origin. In that case the code "#{git_cmd} checkout -q origin" (line 20) will fail. origin may not even be a remote anymore in #{destination}. So I considered the code fragile compared to what it gave. Even in some case the code would perform slower than doing a shallow clone.

Aaron Suggs

This seems error-prone.

In what way does it seem error-prone?

Collaborator

There may be an branch or tag name using the letters a-f.

'effaced' was a word that came to mind, though seems implausible as a branch name.

Is there much of a tradeoff in always doing a clone depth of 1?

Yes, but the consequence is not fatal (not even erroneous) , it just means that it will make a deep clone instead of shallow clone. There is a trade-of from useability to chance of making a deep clone, the tradeof can be adjusted by changing the first number in the count match: From /^[0-9a-f]{6,40}$/ (high usability, "high" chance of deep clone) to /^[0-9a-f]{40,40}$/ (low usability, "low" chance of deep clone). You are welcome to change it to the later... Personally I would always either use a named commit or full SHA1.

Aaron Suggs
Collaborator

What's the motivation here?

I'm not sure that shallow clones are faster for most use cases. Some example here show shallow clones are ~89% the size of a full clone.

This patch would do the shallow clone every deploy; whereas fast checkout only downloads the changes since the last commit.

Jarl Friis

I don't mind skipping the --depth= argument completely for stability/clarity reasons... It will also eliminate any concerns regarding is_commit_id?(revision) My personal experience though is that the size is ~50% size, only really large projects (linux kernel) goes down to ~15%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
13  README.rdoc
Source Rendered
@@ -33,13 +33,22 @@ In config/deploy.rb, set the repository:
33 33
  set :deploy_to, "/path/to/install"
34 34
  set :repository, 'git@example.com:project'
35 35
 
36  
-By default, vlad-git will deploy origin/master. To deploy an arbitrary
  36
+By default, vlad-git will deploy "master". To deploy an arbitrary
37 37
 rev-spec, set the :revision in config/deploy.rb:
38 38
 
39  
- set :revision, "origin/my_branch" # Deploy a branch
  39
+ set :revision, "my_branch"        # Deploy a branch
40 40
  set :revision, "v2.0"             # Deploy a tag
41 41
  set :revision, "a3539b3f3e9edba1" # Deploy a commit
42 42
 
  43
+If you want to deploy from your local repository, you can use
  44
+
  45
+ set :repository,  "file://#{Dir.pwd}"
  46
+
  47
+But you should be aware the that :revision refers branches, tags,
  48
+commit-ids in the repository, and branch names may be different in
  49
+your repository from branch names in a remote repository. And tags and
  50
+commit-ids may not be up to date.
  51
+
43 52
 == Contributors
44 53
 
45 54
 * John Barnette http://github.com/jbarnette
52  lib/vlad/git.rb
@@ -5,6 +5,7 @@ class Vlad::Git
5 5
 
6 6
   set :source,  Vlad::Git.new
7 7
   set :git_cmd, "git"
  8
+  set :revision, (revision || "master") ##This can be either branch, tag or git-commit
8 9
 
9 10
   # Returns the command that will check out +revision+ from the
10 11
   # repository into directory +destination+.  +revision+ can be any
@@ -12,28 +13,14 @@ class Vlad::Git
12 13
 
13 14
   def checkout(revision, destination)
14 15
     destination = File.join(destination, 'repo')
15  
-    revision = 'HEAD' if revision =~ /head/i
16  
-    new_revision = ('HEAD' == revision) ? "origin" : revision
17  
-
18  
-    if fast_checkout_applicable?(revision, destination)
19  
-      [ "cd #{destination}",
20  
-        "#{git_cmd} checkout -q origin",
21  
-        "#{git_cmd} fetch",
22  
-        "#{git_cmd} reset --hard #{new_revision}",
23  
-        submodule_cmd,
24  
-        "#{git_cmd} branch -f deployed-#{revision} #{revision}",
25  
-        "#{git_cmd} checkout deployed-#{revision}",
26  
-        "cd -"
27  
-      ].join(" && ")
28  
-    else
29  
-      [ "rm -rf #{destination}",
30  
-        "#{git_cmd} clone #{repository} #{destination}",
31  
-        "cd #{destination}",
32  
-        "#{git_cmd} checkout -f -b deployed-#{revision} #{revision}",
33  
-        submodule_cmd,
34  
-        "cd -"
35  
-      ].join(" && ")
36  
-    end
  16
+    depth = is_commit_id?(revision) ? "0" : "1"
  17
+    [ "rm -rf #{destination}",
  18
+      "#{git_cmd} clone --depth=#{depth} #{repository} #{destination}",
  19
+      "cd #{destination}",
  20
+      "#{git_cmd} checkout -q #{revision}",
  21
+      submodule_cmd,
  22
+      "cd -"
  23
+    ].join(" && ")
37 24
   end
38 25
 
39 26
   # Returns the command that will export +revision+ from the current
@@ -41,9 +28,6 @@ def checkout(revision, destination)
41 28
   # from +scm_path+ after Vlad::Git#checkout.
42 29
 
43 30
   def export(revision, destination)
44  
-    revision = 'HEAD' if revision =~ /head/i
45  
-    revision = "deployed-#{revision}"
46  
-
47 31
     [ "mkdir -p #{destination}",
48 32
       "cd repo",
49 33
       "#{git_cmd} archive --format=tar #{revision} | (cd #{destination} && tar xf -)",
@@ -57,27 +41,13 @@ def export(revision, destination)
57 41
   # +revision+ into a git SHA1.
58 42
 
59 43
   def revision(revision)
60  
-    revision = 'HEAD' if revision =~ /head/i
61  
-
62 44
     "`#{git_cmd} rev-parse #{revision}`"
63 45
   end
64 46
 
65 47
   private
66 48
 
67  
-  # Checks if fast-checkout is applicable
68  
-  def fast_checkout_applicable?(revision, destination)
69  
-    revision = 'HEAD' if revision =~ /head/i
70  
-
71  
-    begin
72  
-      cmd = [ "if cd #{destination}",
73  
-              "#{git_cmd} rev-parse #{revision}",
74  
-              "#{git_cmd} remote -v | grep -q #{repository}",
75  
-              "cd -; then exit 0; else exit 1; fi &>/dev/null" ].join(" && ")
76  
-      run cmd
77  
-      return true
78  
-    rescue Rake::CommandFailedError
79  
-      return false
80  
-    end
  49
+  def is_commit_id?(revision)
  50
+    revision.match(/^[0-9a-f]{6,40}$/) ? true : false
81 51
   end
82 52
 
83 53
   def submodule_cmd
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.