oxen_deployer_git 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Manifest.txt +6 -0
  2. data/lib/oxen_deployer/git.rb +86 -0
  3. metadata +68 -0
data/Manifest.txt ADDED
@@ -0,0 +1,6 @@
1
+ .autotest
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/oxen_deployer/git.rb
@@ -0,0 +1,86 @@
1
+ class OxenDeployer::Git
2
+
3
+ # Duh.
4
+ VERSION = "1.0.0"
5
+
6
+ set :source, OxenDeployer::Git.new
7
+ set :git_cmd, "git"
8
+
9
+ # Returns the command that will check out +revision+ from the
10
+ # repository into directory +destination+. +revision+ can be any
11
+ # SHA1 or equivalent (e.g. branch, tag, etc...)
12
+
13
+ def checkout(revision, destination)
14
+ 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
37
+ end
38
+
39
+ # Returns the command that will export +revision+ from the current
40
+ # directory into the directory +destination+. Expects to be run
41
+ # from +scm_path+ after Vlad::Git#checkout.
42
+
43
+ def export(revision, destination)
44
+ revision = 'HEAD' if revision =~ /head/i
45
+ revision = "deployed-#{revision}"
46
+
47
+ [ "mkdir -p #{destination}",
48
+ "cd repo",
49
+ "#{git_cmd} archive --format=tar #{revision} | (cd #{destination} && tar xf -)",
50
+ "#{git_cmd} submodule foreach '#{git_cmd} archive --format=tar $sha1 | (cd #{destination}/$path && tar xf -)'",
51
+ "cd -",
52
+ "cd .."
53
+ ].join(" && ")
54
+ end
55
+
56
+ # Returns a command that maps human-friendly revision identifier
57
+ # +revision+ into a git SHA1.
58
+
59
+ def revision(revision)
60
+ revision = 'HEAD' if revision =~ /head/i
61
+
62
+ "`#{git_cmd} rev-parse #{revision}`"
63
+ end
64
+
65
+ private
66
+
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
81
+ end
82
+
83
+ def submodule_cmd
84
+ "#{git_cmd} submodule sync && #{git_cmd} submodule update --init --recursive"
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oxen_deployer_git
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Walther Diechmann
9
+ - Enrique Phillips
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-07-18 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oxen_deployer
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.0.1
31
+ description: OxenDeployer plugin for Git support. Just another pitty rip-off off the
32
+ Vlad-Git plugin
33
+ email:
34
+ - walther@diechmann.net
35
+ - enrique.phillips.wac@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files:
39
+ - Manifest.txt
40
+ files:
41
+ - Manifest.txt
42
+ - lib/oxen_deployer/git.rb
43
+ homepage: https://github.com/wdiechmann/oxen_deployer_git
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project: oxen_deployer_git
63
+ rubygems_version: 1.8.23
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: OxenDeployer plugin for Git support
67
+ test_files: []
68
+ has_rdoc: