ext 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/CHANGELOG +7 -0
  2. data/README +2 -0
  3. data/Rakefile +1 -74
  4. data/bin/ext +0 -0
  5. data/lib/externals/ext.rb +25 -9
  6. data/lib/externals/extensions/file_utils.rb +40 -0
  7. data/lib/externals/extensions/string.rb +1 -1
  8. data/lib/externals/project.rb +3 -0
  9. data/lib/externals/scms/git_project.rb +3 -4
  10. data/lib/externals/scms/svn_project.rb +10 -12
  11. data/lib/externals/test/basic_git_repository.rb +41 -0
  12. data/lib/externals/test/engines.rb +11 -0
  13. data/lib/externals/test/engines_with_branch1.rb +36 -0
  14. data/lib/externals/test/fake_rails_repository.rb +112 -0
  15. data/lib/externals/test/git_repository_from_internet.rb +19 -0
  16. data/lib/externals/test/modules_svn_branches_repository.rb +72 -0
  17. data/lib/externals/test/modules_svn_repository.rb +41 -0
  18. data/lib/externals/test/rails_app_git_branches.rb +100 -0
  19. data/lib/externals/test/rails_app_git_repository.rb +55 -0
  20. data/lib/externals/test/rails_app_svn_branches.rb +132 -0
  21. data/lib/externals/test/rails_app_svn_repository.rb +106 -0
  22. data/lib/externals/test/rails_app_unmanaged.rb +25 -0
  23. data/lib/externals/test/repository.rb +188 -0
  24. data/lib/externals/test/svn_repository_from_dump.rb +27 -0
  25. data/lib/externals/test/svn_repository_helper.rb +10 -0
  26. data/lib/externals/test_case.rb +16 -307
  27. data/test/setup/empty_plugin.svn.gz +0 -0
  28. data/test/setup/foreign_key_migrations.svn.gz +0 -0
  29. data/test/setup/redhillonrails_core.svn.gz +0 -0
  30. data/test/test_checkout_git.rb +16 -25
  31. data/test/test_checkout_with_subprojects_git.rb +109 -193
  32. data/test/test_checkout_with_subprojects_svn.rb +239 -294
  33. data/test/test_file_utils_extensions.rb +29 -0
  34. data/test/test_freeze_to_revision.rb +46 -85
  35. data/test/test_git_project_extract_name.rb +10 -8
  36. data/test/test_init_git.rb +19 -29
  37. data/test/test_projects.rb +87 -93
  38. data/test/test_rails_detection.rb +12 -17
  39. data/test/test_string_extensions.rb +32 -30
  40. data/test/test_svn_branches.rb +227 -383
  41. data/test/test_touch_emptydirs.rb +39 -34
  42. data/test/test_version.rb +18 -16
  43. metadata +47 -23
@@ -0,0 +1,112 @@
1
+ require 'externals/test/repository'
2
+ require 'find'
3
+ require 'externals/test/git_repository_from_internet'
4
+
5
+ module Externals
6
+ module Test
7
+ class FakeRailsRepository < Repository
8
+ def initialize
9
+ super "rails.git", "fake3"
10
+ end
11
+
12
+ def build_here
13
+ repository = GitRepositoryFromInternet.new("rails")
14
+ repository.prepare
15
+
16
+ rm_rf "fake_rails"
17
+
18
+ `git clone #{repository.clean_dir} fake_rails`
19
+ raise unless $? == 0
20
+
21
+ #let's make the repo smaller by removing all but 1 file from each
22
+ #directory to save time
23
+ Dir.chdir 'fake_rails' do
24
+ rm_rf ".git"
25
+ end
26
+
27
+ dirs = []
28
+ Find.find('fake_rails') do |f|
29
+ dirs << f if File.directory?(f)
30
+ end
31
+
32
+ dirs.each do |dir|
33
+ files = Dir.entries(dir)
34
+
35
+ Dir.chdir(dir) do
36
+ files = files.select {|e|e != ".gitignore" && File.file?(e)}.sort
37
+ files.shift #let's keep the first file in the list.
38
+ files.each do |file|
39
+ File.delete(file)
40
+ end
41
+ end
42
+ end
43
+
44
+ raise "why is rails already here?" if File.exists? 'rails.git'
45
+
46
+ Dir.mkdir('rails.git')
47
+
48
+ Dir.chdir('rails.git') do
49
+ puts `git init --bare`
50
+ raise unless $? == 0
51
+ end
52
+
53
+ Dir.chdir 'fake_rails' do
54
+ puts `git init`
55
+ raise unless $? == 0
56
+ puts `git add .`
57
+ raise unless $? == 0
58
+ puts `git commit -m "rails with all but 1 file per directory deleted"`
59
+ raise unless $? == 0
60
+ puts `git push ../rails.git master`
61
+ raise unless $? == 0
62
+
63
+ head1 = nil
64
+ head2 = nil
65
+ # let's make a couple commits...
66
+ open "heads", "a" do |file|
67
+ head1 = `git show HEAD`.match(/^\s*commit\s+([0-9a-f]{40})\s*$/)[1]
68
+ raise unless head1
69
+ file.puts head1
70
+ raise unless $? == 0
71
+ end
72
+ puts `git add .`
73
+ raise unless $? == 0
74
+ puts `git commit -m "dummy commit 1"`
75
+ raise unless $? == 0
76
+ puts `git push ../rails.git master`
77
+ raise unless $? == 0
78
+
79
+ open "heads", "a" do |file|
80
+ head2 = `git show HEAD`.match(/^\s*commit\s+([0-9a-f]{40})\s*$/)[1]
81
+ raise unless head2
82
+ raise unless head1 != head2
83
+ file.puts head2
84
+ raise unless $? == 0
85
+ end
86
+ puts `git add .`
87
+ raise unless $? == 0
88
+ puts `git commit -m "dummy commit 2"`
89
+ raise unless $? == 0
90
+ puts `git push ../rails.git master`
91
+ raise unless $? == 0
92
+
93
+ open "heads", "a" do |file|
94
+ head2 = `git show HEAD`.match(/^\s*commit\s+([0-9a-f]{40})\s*$/)[1]
95
+ raise unless head2
96
+ raise unless head1 != head2
97
+ file.puts head2
98
+ raise unless $? == 0
99
+ end
100
+ puts `git add .`
101
+ raise unless $? == 0
102
+ puts `git commit -m "dummy commit 3"`
103
+ raise unless $? == 0
104
+ puts `git push ../rails.git master`
105
+ raise unless $? == 0
106
+ end
107
+ rm_rf "fake_rails"
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,19 @@
1
+ require 'externals/test/repository'
2
+
3
+ module Externals
4
+ module Test
5
+ class GitRepositoryFromInternet < Repository
6
+ attr_accessor :url
7
+ def initialize name, subpath = nil, url = nil
8
+ super name, subpath || "git"
9
+ self.url = url || "git://github.com/rails"
10
+ end
11
+
12
+ #builds the test repository in the current directory
13
+ def build_here
14
+ puts `git clone --bare #{url}/#{name} #{name}`
15
+ raise unless $? == 0
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,72 @@
1
+ require 'externals/test/repository'
2
+ require 'externals/test/svn_repository_helper'
3
+
4
+ module Externals
5
+ module Test
6
+ class ModulesSvnBranchesRepository < Repository
7
+ include SvnRepositoryHelper
8
+
9
+ def initialize
10
+ super "modules_with_branches", "svn"
11
+ end
12
+
13
+ def build_here
14
+ puts `svnadmin create #{name}`
15
+
16
+ mkdir_p 'workdir'
17
+ Dir.chdir 'workdir' do
18
+ rm_rf name
19
+
20
+ cmd = "svn checkout \'#{clean_url}\'"
21
+ puts "about to run #{cmd}"
22
+ puts `#{cmd}`
23
+ unless $? == 0
24
+ raise
25
+ end
26
+
27
+ Dir.chdir name do
28
+ mkdir "branches"
29
+ mkdir "current"
30
+
31
+ SvnProject.add_all
32
+ puts `svn commit -m "created branch directory structure"`
33
+ raise unless $? == 0
34
+
35
+ `svn switch #{[clean_url, 'current'].join("/")}`
36
+ raise unless $? == 0
37
+
38
+ open("modules.txt", "w") do |f|
39
+ f.write "line1 of modules.txt\n"
40
+ end
41
+
42
+ SvnProject.add_all
43
+ puts `svn commit -m "created modules.txt"`
44
+ raise unless $? == 0
45
+
46
+ `svn copy #{
47
+ [clean_url, "current"].join("/")
48
+ } #{[clean_url, "branches", "branch2"].join("/")
49
+ } -m "created branch2"`
50
+ raise unless $? == 0
51
+
52
+ puts `svn switch #{
53
+ [clean_url, "branches", "branch2"].join("/")
54
+ }`
55
+ raise unless $? == 0
56
+
57
+ open("modules.txt", "w") do |f|
58
+ f.write 'line 2 of modules.txt ... this is branch2!\n'
59
+ end
60
+
61
+ SvnProject.add_all
62
+ puts `svn commit -m "changed modules.txt"`
63
+ raise unless $? == 0
64
+ end
65
+
66
+ rm_rf name
67
+ end
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,41 @@
1
+ require 'externals/test/repository'
2
+ require 'externals/test/svn_repository_helper'
3
+
4
+ module Externals
5
+ module Test
6
+ class ModulesSvnRepository < Repository
7
+ include SvnRepositoryHelper
8
+
9
+ def initialize
10
+ super "modules", "svn"
11
+ end
12
+
13
+ def build_here
14
+ puts `svnadmin create #{name}`
15
+
16
+ mkdir_p "workdir"
17
+ Dir.chdir 'workdir' do
18
+ rm_rf name
19
+
20
+ cmd = "svn checkout \"#{clean_url}\""
21
+ puts "about to run #{cmd}"
22
+ puts `#{cmd}`
23
+ raise unless $? == 0
24
+
25
+ Dir.chdir name do
26
+ open("modules.txt", "w") do |f|
27
+ f.write "line1 of modules.txt\n"
28
+ end
29
+
30
+ SvnProject.add_all
31
+ puts `svn commit -m "created modules.txt"`
32
+ raise unless $? == 0
33
+ end
34
+
35
+ rm_rf name
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,100 @@
1
+ require 'externals/test/repository'
2
+ require 'externals/test/git_repository_from_internet'
3
+ require 'externals/test/svn_repository_from_dump'
4
+ require 'externals/test/engines_with_branch1'
5
+ require 'externals/test/fake_rails_repository'
6
+ require 'externals/test/rails_app_unmanaged'
7
+
8
+ module Externals
9
+ module Test
10
+ class RailsAppGitBranches < Repository
11
+ def initialize
12
+ super "rails_app", File.join("git", "branches")
13
+ dependents.merge!(
14
+ :acts_as_list => GitRepositoryFromInternet.new("acts_as_list.git"),
15
+ :redhillonrails_core => SvnRepositoryFromDump.new("redhillonrails_core"),
16
+ :foreign_key_migrations => SvnRepositoryFromDump.new("foreign_key_migrations"),
17
+ :engines => EnginesWithBranch1.new,
18
+ :rails => FakeRailsRepository.new,
19
+ :rails_app_unmanaged => RailsAppUnmanaged.new
20
+ )
21
+ dependents[:foreign_key_migrations].attributes[:revision] = "2"
22
+ dependents[:acts_as_list].attributes[:revision] =
23
+ "9baff190a52c05cc542bfcaa7f77a91ce669f2f8"
24
+ end
25
+
26
+ def build_here
27
+ cp_a dependents[:rails_app_unmanaged].clean_dir, name
28
+
29
+ Dir.chdir name do
30
+ Ext.run "touch_emptydirs"
31
+
32
+ `git init`
33
+ raise unless $? == 0
34
+ Ext.run "init"
35
+ raise " could not create .externals" unless File.exists? '.externals'
36
+ Ext.run "install", dependents[:acts_as_list].clean_dir
37
+
38
+ #install a couple svn managed subprojects
39
+ [:foreign_key_migrations, :redhillonrails_core].each do |proj|
40
+ Ext.run "install", "--svn", 'file:///' + dependents[proj].clean_dir
41
+ end
42
+
43
+ ext = Ext.new
44
+ main_project = ext.main_project
45
+
46
+ unless !main_project.ignore_contains? "vendor/plugins/engines"
47
+ raise
48
+ end
49
+ #install project with a branch
50
+ Ext.run "install", dependents[:engines].clean_dir, "-b", "edge"
51
+ unless main_project.ignore_contains? "vendor/plugins/engines"
52
+ raise
53
+ end
54
+
55
+ #install fake_rails
56
+ unless !main_project.ignore_contains? "vendor/rails"
57
+ raise
58
+ end
59
+ Ext.run "install",
60
+ dependents[:rails].clean_dir
61
+ unless main_project.ignore_contains? "vendor/rails"
62
+ raise
63
+ end
64
+
65
+ GitProject.add_all
66
+ `git commit -m "created empty rails app with some subprojects"`
67
+ raise unless $? == 0
68
+
69
+ #let's create a branch for the main project called 'new_branch' and a
70
+ #branch for the engines subproject called 'new_branch' and make sure
71
+ #that checking one out and doing "ext up" correctly changes the branch
72
+ #of the subproject
73
+ `git checkout -b new_branch`
74
+ raise unless $? == 0
75
+
76
+ ext = Ext.new
77
+ main_project = ext.main_project
78
+
79
+ #update .externals
80
+ ext.configuration["vendor/plugins/engines"]["branch"] = "branch1"
81
+ ext.configuration.write
82
+
83
+ #let's uninstall rails
84
+ Ext.run "uninstall", "-f", "rails"
85
+ raise if File.exists?(File.join('vendor', 'rails', 'activerecord', 'lib'))
86
+
87
+ GitProject.add_all
88
+ raise unless $? == 0
89
+ `git commit -m "changed branch on engines subproject, removed rails"`
90
+ raise unless $? == 0
91
+
92
+ #switch back to master...
93
+ `git checkout master`
94
+ raise unless $? == 0
95
+ end
96
+ end
97
+
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,55 @@
1
+ require 'externals/test/repository'
2
+ require 'externals/test/git_repository_from_internet'
3
+ require 'externals/test/svn_repository_from_dump'
4
+ require 'externals/test/rails_app_unmanaged'
5
+
6
+ module Externals
7
+ module Test
8
+ class RailsAppGitRepository < Repository
9
+ def initialize
10
+ super "rails_app", "git"
11
+ dependents.merge!(
12
+ :acts_as_list => GitRepositoryFromInternet.new("acts_as_list.git"),
13
+ :redhillonrails_core => SvnRepositoryFromDump.new("redhillonrails_core"),
14
+ :foreign_key_migrations => SvnRepositoryFromDump.new("foreign_key_migrations"),
15
+ :rails_app_unmanaged => RailsAppUnmanaged.new
16
+ )
17
+ dependents[:foreign_key_migrations].attributes[:revision] = "2"
18
+ dependents[:acts_as_list].attributes[:revision] =
19
+ "9baff190a52c05cc542bfcaa7f77a91ce669f2f8"
20
+ end
21
+
22
+ def build_here
23
+ cp_a dependents[:rails_app_unmanaged].clean_dir, name
24
+
25
+ Dir.chdir name do
26
+ Ext.run "touch_emptydirs"
27
+
28
+ `git init`
29
+ raise unless $? == 0
30
+ Ext.run "init"
31
+ raise " could not create .externals" unless File.exists? '.externals'
32
+ Ext.run "install", dependents[:acts_as_list].clean_dir
33
+
34
+ #install a couple svn managed subprojects
35
+ [:foreign_key_migrations, :redhillonrails_core].each do |proj|
36
+ Ext.run "install", "--svn", 'file:///' + dependents[proj].clean_dir
37
+ end
38
+
39
+ Dir.chdir File.join('vendor', 'plugins', 'foreign_key_migrations') do
40
+ raise unless `svn info` !~ /^.*:\s*2\s*$/i
41
+ raise unless $? == 0
42
+ end
43
+
44
+ Ext.run "freeze", "foreign_key_migrations", "2"
45
+ Ext.run "freeze", "acts_as_list", "9baff190a52c05cc542bfcaa7f77a91ce669f2f8"
46
+
47
+ GitProject.add_all
48
+ `git commit -m "created empty rails app with some subprojects"`
49
+ raise unless $? == 0
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,132 @@
1
+ require 'externals/test/repository'
2
+ require 'externals/test/git_repository_from_internet'
3
+ require 'externals/test/svn_repository_from_dump'
4
+ require 'externals/test/svn_repository_helper'
5
+ require 'externals/test/engines_with_branch1'
6
+ require 'externals/test/fake_rails_repository'
7
+ require 'externals/test/modules_svn_branches_repository'
8
+ require 'externals/test/rails_app_unmanaged'
9
+
10
+ module Externals
11
+ module Test
12
+ class RailsAppSvnBranches < Repository
13
+ include SvnRepositoryHelper
14
+
15
+ def initialize
16
+ super "rails_app_svn_branches", "svn"
17
+ dependents.merge!(
18
+ :acts_as_list => GitRepositoryFromInternet.new("acts_as_list.git"),
19
+ :ssl_requirement => GitRepositoryFromInternet.new("ssl_requirement.git"),
20
+ :engines => EnginesWithBranch1.new,
21
+ :redhillonrails_core => SvnRepositoryFromDump.new("redhillonrails_core"),
22
+ :empty_plugin => SvnRepositoryFromDump.new("empty_plugin"),
23
+ #fkm seems to cause problems when running tests, concerning a corrupt repository.
24
+ #commenting out for now.
25
+ #:foreign_key_migrations => SvnRepositoryFromDump.new("foreign_key_migrations", ""),
26
+ :rails => FakeRailsRepository.new,
27
+ :modules => ModulesSvnBranchesRepository.new,
28
+ :rails_app_unmanaged => RailsAppUnmanaged.new
29
+ )
30
+
31
+ dependents[:ssl_requirement].attributes[:revision] =
32
+ "aa2dded823f8a9b378c22ba0159971508918928a"
33
+ end
34
+
35
+ def build_here
36
+ puts `svnadmin create #{name}`
37
+ raise unless $? == 0
38
+
39
+ mkdir "workdir" unless File.exists? 'workdir'
40
+ Dir.chdir 'workdir' do
41
+ rm_rf name if File.exists? name
42
+ cmd = "svn checkout \"#{clean_url}\""
43
+ puts "about to run #{cmd}"
44
+ puts `#{cmd}`
45
+ raise unless $? == 0
46
+
47
+ Dir.chdir name do
48
+ mkdir "branches"
49
+
50
+ cp_a dependents[:rails_app_unmanaged].clean_dir, name
51
+
52
+ mv name, "current"
53
+
54
+ SvnProject.add_all
55
+ puts `svn commit -m "created branch directory structure"`
56
+ raise unless $? == 0
57
+
58
+ puts `svn switch #{[clean_url, "current"].join("/")}`
59
+ raise unless $? == 0
60
+
61
+ Ext.run "init", "-b", "current"
62
+ raise " could not create .externals" unless File.exists? '.externals'
63
+
64
+ # this line is necessary as ext can't perform the necessary
65
+ # ignores otherwise if vendor and vendor/plugins haven't been added
66
+ SvnProject.add_all
67
+
68
+ #install some git subprojects
69
+ [:rails, :acts_as_list].each do |proj|
70
+ Ext.run "install", dependents[proj].clean_dir
71
+ end
72
+
73
+ #install a couple svn managed subprojects
74
+ [
75
+ #:foreign_key_migrations,
76
+ :redhillonrails_core
77
+ ].each do |proj|
78
+ Ext.run "install", "--svn", dependents[proj].clean_url
79
+ end
80
+
81
+ #install project with a git branch
82
+ Ext.run "install", dependents[:engines].clean_dir, "-b", "edge"
83
+
84
+ #install project with a non-default path and svn branching
85
+ Ext.run "install", "--svn",
86
+ "#{dependents[:modules].clean_url}",
87
+ "-b", "current",
88
+ "modules"
89
+
90
+ SvnProject.add_all
91
+
92
+ puts `svn commit -m "created empty rails app with some subprojects"`
93
+ raise unless $? == 0
94
+
95
+ # now let's make a branch in the main project called new_branch
96
+ `svn copy #{
97
+ [clean_url, "current"].join("/")
98
+ } #{[clean_url, "branches", "new_branch"].join("/")} -m "creating branch" `
99
+ raise unless $? == 0
100
+
101
+ # let's update the .externals file in new_branch to reflect these changes
102
+ `svn switch #{[clean_url, "branches", "new_branch"].join("/")}`
103
+ raise unless $? == 0
104
+
105
+ # let's remove rails from this branch
106
+ Ext.run "uninstall", "-f", "rails"
107
+
108
+ # add a git managed project...
109
+ Ext.run "install", dependents[:ssl_requirement].clean_dir,
110
+ "-r", dependents[:ssl_requirement].attributes[:revision]
111
+
112
+ # add a svn managed project
113
+ Ext.run "install", "--svn", dependents[:empty_plugin].clean_url
114
+
115
+ ext = Ext.new
116
+ ext.configuration["vendor/plugins/engines"]["branch"] = "branch1"
117
+ ext.configuration["modules"]["branch"] = "branches/branch2"
118
+ ext.configuration.write
119
+
120
+ SvnProject.add_all
121
+ `svn commit -m "updated .externals to point to new branches."`
122
+ raise unless $? == 0
123
+ end
124
+
125
+ rm_rf name
126
+ end
127
+ end
128
+
129
+ end
130
+ end
131
+
132
+ end