ext 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
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
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ October 9, 2011 Version 1.0.4 released
2
+ - Dependency on programs such as rm, rmdir, cp, etc, removed. Now only
3
+ dependent on the actual SCM executables (and gzip to run the tests.)
4
+ - Tests have been restructured and now take significantly much less time to run.
5
+ - Fixed a bug caused by a file failing to be packaged with the rest of the
6
+ 1.0.3 gem.
7
+
1
8
  September 28, 2011 Version 1.0.3 released
2
9
  - "up" now changes branches of subprojects
3
10
  - Subversion branch support added
data/README CHANGED
@@ -33,6 +33,8 @@ ext [OPTIONS] <command> [repository] [-b <branch>] [path]
33
33
  '--scm svn'.
34
34
  -b, --branch BRANCH The branch you want the subproject to checkout when
35
35
  doing 'ext install'
36
+ -r, --revision REVISION The revision you want the subproject to checkout when
37
+ doing 'ext install'
36
38
  -f, --force_removal When doing an uninstall of a subproject, remove it's
37
39
  files and subfolders, too.
38
40
  -w, --workdir DIR The working directory to execute commands from. Use
data/Rakefile CHANGED
@@ -10,79 +10,6 @@ $LOAD_PATH << File.join(root_dir, 'lib')
10
10
 
11
11
  require File.join(root_dir, 'lib', 'externals', 'ext')
12
12
 
13
- desc "Creates the starting repositories needed to run the tests.
14
- If you plan on running the tests, you only need
15
- to run this once."
16
- task :prep_test do
17
- Dir.chdir File.join(root_dir, 'test') do
18
-
19
- puts `rm -rf cleanreps`
20
- Dir.mkdir('cleanreps')
21
- Dir.chdir('cleanreps') do
22
- %w(redhillonrails_core foreign_key_migrations empty_plugin).each do |p|
23
- puts `cp ../setup/#{p}.svn.gz .`
24
- puts `gzip -d #{p}.svn.gz`
25
- puts `svnadmin create #{p}`
26
- puts `svnadmin load #{p} < #{p}.svn`
27
- end
28
-
29
- puts `git clone --bare git://github.com/azimux/engines.git engines.git`
30
-
31
- %w(acts_as_list ssl_requirement).each do |p|
32
- puts `git clone --bare git://github.com/rails/#{p}.git #{p}.git`
33
- end
34
-
35
- if File.exists? 'C:\\tmp\\rails'
36
- puts `cp -a C:\\tmp\\rails full_rails`
37
- elsif File.exists? '/tmp/rails'
38
- puts `cp -a /tmp/rails full_rails`
39
- else
40
- puts `git clone git://github.com/rails/rails.git full_rails`
41
- end
42
- puts `cp -a full_rails fake_rails`
43
-
44
- #let's make the repo smaller by removing all but 1 file from each
45
- #directory to save time
46
- Dir.chdir 'fake_rails' do
47
- puts `rm -rf .git`
48
- raise "something wrong with rm" if File.exists? '.git'
49
- end
50
-
51
- dirs = []
52
- Find.find('fake_rails') do |f|
53
- dirs << f if File.directory?(f)
54
- end
55
-
56
- dirs.each do |dir|
57
- files = Dir.entries(dir)
58
-
59
- Dir.chdir(dir) do
60
- files = files.select {|e|e != ".gitignore" && File.file?(e)}.sort
61
- files.shift #let's keep the first file in the list.
62
- files.each do |file|
63
- File.delete(file)
64
- end
65
- end
66
- end
67
-
68
- raise "why is rails already here?" if File.exists? 'rails.git'
69
-
70
- Dir.mkdir('rails.git')
71
-
72
- Dir.chdir('rails.git') do
73
- puts `git init --bare`
74
- end
75
-
76
- Dir.chdir 'fake_rails' do
77
- puts `git init`
78
- puts `git add .`
79
- puts `git commit -m "rails with all but 1 file per directory deleted"`
80
- puts `git push ../rails.git master`
81
- end
82
- end
83
- end
84
- end
85
-
86
13
  Rake::TestTask.new('test') do |task|
87
14
  task.libs = [File.expand_path('lib'),File.expand_path('test')]
88
15
  task.pattern = './test/test_*.rb'
@@ -132,7 +59,7 @@ the main project.}
132
59
  specification.email = "azimux@gmail.com"
133
60
  specification.homepage = "http://nopugs.com/ext-tutorial"
134
61
 
135
- specification.test_files = FileList['test/test_*.rb']
62
+ specification.test_files = FileList['test/test_*.rb', 'test/setup/*.gz']
136
63
 
137
64
  specification.bindir = "bin"
138
65
  specification.executables = ['ext']
data/bin/ext CHANGED
File without changes
@@ -2,10 +2,14 @@ require 'externals/project'
2
2
  require 'externals/configuration/configuration'
3
3
  require 'optparse'
4
4
  require 'externals/command'
5
- require 'externals/extensions/symbol'
5
+ require 'fileutils'
6
+
7
+ Dir.entries(File.join(File.dirname(__FILE__), 'extensions')).each do |extension|
8
+ require "externals/extensions/#{extension}" if extension =~ /.rb$/
9
+ end
6
10
 
7
11
  module Externals
8
- VERSION = '1.0.3'
12
+ VERSION = '1.0.4'
9
13
  PROJECT_TYPES_DIRECTORY = File.join(File.dirname(__FILE__), '..', 'externals','project_types')
10
14
 
11
15
  # Full commands operate on the main project as well as the externals
@@ -79,9 +83,8 @@ module Externals
79
83
 
80
84
  COMMANDS = FULL_COMMANDS + SHORT_COMMANDS + MAIN_COMMANDS
81
85
 
82
- Dir.entries(File.join(File.dirname(__FILE__), 'extensions')).each do |extension|
83
- require "externals/extensions/#{extension}" if extension =~ /.rb$/
84
- end
86
+ COULD_NOT_DETERMINE_SCM = 1
87
+ NO_EXTERNALS_FILE = 2
85
88
 
86
89
  Dir.entries(File.join(File.dirname(__FILE__), '..', 'externals','scms')).each do |project|
87
90
  require "externals/scms/#{project}" if project =~ /_project.rb$/
@@ -92,6 +95,9 @@ module Externals
92
95
  end
93
96
 
94
97
  class Ext
98
+ include FileUtils
99
+ extend FileUtils
100
+
95
101
  attr_accessor :path_calculator
96
102
 
97
103
  def self.project_types
@@ -143,6 +149,11 @@ module Externals
143
149
  *"The branch you want the
144
150
  subproject to checkout when doing 'ext install'".lines_by_width(summary_width)
145
151
  ) {|branch| sub_options[:branch] = main_options[:branch] = branch}
152
+ opts.on("--revision REVISION", "-r REVISION",
153
+ String,
154
+ *"The revision you want the
155
+ subproject to checkout when doing 'ext install'".lines_by_width(summary_width)
156
+ ) {|revision| sub_options[:revision] = main_options[:revision] = revision}
146
157
  opts.on("--force_removal", "-f",
147
158
  String,
148
159
  *"When doing an uninstall of a subproject,
@@ -401,7 +412,10 @@ Please use
401
412
  end
402
413
 
403
414
  def install args, options
404
- init args, options unless File.exists? '.externals'
415
+ if !File.exists? '.externals'
416
+ STDERR.puts "This project does not appear to be managed by externals. Try 'ext init' first"
417
+ exit NO_EXTERNALS_FILE
418
+ end
405
419
  repository = args[0]
406
420
  path = args[1]
407
421
 
@@ -412,10 +426,11 @@ Please use
412
426
  scm ||= infer_scm(repository)
413
427
 
414
428
  unless scm
415
- raise "Unable to determine SCM from the repository name.
429
+ STDERR.puts "Unable to determine SCM from the repository name.
416
430
  You need to either specify the scm used to manage the subproject
417
431
  that you are installing. Use an option to specify it
418
432
  (such as --git or --svn)"
433
+ exit COULD_NOT_DETERMINE_SCM
419
434
  end
420
435
 
421
436
  project = self.class.project_class(scm).new(:repository => repository,
@@ -427,6 +442,7 @@ that you are installing. Use an option to specify it
427
442
  raise "already exists" if configuration[path]
428
443
 
429
444
  project.branch = options[:branch] if options[:branch]
445
+ project.revision = options[:revision] if options[:revision]
430
446
 
431
447
  attributes = project.attributes.dup
432
448
  attributes.delete(:path)
@@ -456,7 +472,7 @@ that you are installing. Use an option to specify it
456
472
 
457
473
  if options[:force_removal]
458
474
  Dir.chdir File.dirname(project.path) do
459
- `rm -rf #{File.basename(project.path)}`
475
+ rm_rf File.basename(project.path)
460
476
  end
461
477
  end
462
478
  end
@@ -670,7 +686,7 @@ commands below if you actually wish to delete them."
670
686
  repository = args[0]
671
687
  path = args[1] || "."
672
688
 
673
- main_project = do_checkout_or_export repository, path, options, :checkout
689
+ main_project = do_checkout_or_export repository, path, options, :export
674
690
 
675
691
  if path == "."
676
692
  path = main_project.name
@@ -0,0 +1,40 @@
1
+ require 'fileutils'
2
+
3
+ FileUtils.class_eval do
4
+ # simulates cp -a
5
+ def cp_a source, dest, options = {}
6
+ cp_r source, dest, options.merge(:preserve => true)
7
+ end
8
+
9
+ # calls rm_rf if the file exists
10
+ def rm_rf_ie file, options = {}
11
+ rm_rf file, options if File.exists? file
12
+ end
13
+
14
+ # calls rmdir if the file exists and is empty
15
+ def rmdir_if_empty_ie path
16
+ rmdir path if File.exists?(path) && dir_empty?(path)
17
+ end
18
+
19
+ # calls rmdir if the file exists
20
+ def rmdir_ie path
21
+ rmdir path if File.exists?(path)
22
+ end
23
+
24
+ alias rm_rf_old rm_rf
25
+ #going to try to give a delay after calling rm if necessary...
26
+ def rm_rf *args
27
+ rm_rf_old *args
28
+ tries = 0
29
+ while File.exists?(args[0]) && tries < 10
30
+ sleep 1
31
+ tries += 1
32
+ end
33
+ end
34
+
35
+ def dir_empty? path
36
+ File.directory?(path) &&
37
+ File.exists?(path) &&
38
+ !Dir.entries(path).detect{|entry| !["..","."].include?(entry)}
39
+ end
40
+ end
@@ -8,7 +8,6 @@ String.class_eval do
8
8
  end
9
9
 
10
10
  #avoid collision
11
- raise unless instance_methods.include?("lines")
12
11
  raise if instance_methods.include?("lines_by_width")
13
12
  def lines_by_width(width = 32)
14
13
  width ||= 32
@@ -36,4 +35,5 @@ String.class_eval do
36
35
 
37
36
  lines
38
37
  end
38
+
39
39
  end
@@ -1,4 +1,5 @@
1
1
  require 'externals/extensions/symbol'
2
+ require 'fileutils'
2
3
 
3
4
  module Externals
4
5
  OPTS_SUFFIXES = ["co", "up", "st", "ex"] unless const_defined?('OPTS_SUFFIXES')
@@ -9,6 +10,8 @@ module Externals
9
10
 
10
11
  class Project
11
12
  attr_accessor :parent
13
+ include FileUtils
14
+ extend FileUtils
12
15
 
13
16
  def self.attr_attr_accessor *names
14
17
  names = [names].flatten
@@ -12,8 +12,7 @@ module Externals
12
12
 
13
13
  puts "path is #{path} repository is #{repository}"
14
14
  if path != '.'
15
- (rmdircmd = "rmdir #{path}")
16
- `#{rmdircmd}` if File.exists?(path)
15
+ rmdir_ie path
17
16
  end
18
17
 
19
18
  dest = path
@@ -118,8 +117,7 @@ module Externals
118
117
 
119
118
  def ex *args
120
119
  if path != '.'
121
- (rmdircmd = "rmdir #{path}")
122
- `#{rmdircmd}` if File.exists? path
120
+ rmdir_ie path
123
121
  end
124
122
 
125
123
  dest = path
@@ -176,6 +174,7 @@ module Externals
176
174
  #this is a test helper method
177
175
  def self.add_all
178
176
  puts `git add .`
177
+ raise unless $? == 0
179
178
  end
180
179
 
181
180
  def ignore_contains? path
@@ -9,8 +9,7 @@ module Externals
9
9
  public
10
10
  def co *args
11
11
  # delete path if not empty
12
- rmdircmd = "rmdir #{path}"
13
- `#{rmdircmd}` if File.exists? path
12
+ rmdir_ie path
14
13
 
15
14
  if File.exists? path
16
15
  up
@@ -26,7 +25,9 @@ module Externals
26
25
 
27
26
  puts(svncocmd = "svn #{opts} co #{url} #{path}")
28
27
  puts `#{svncocmd}`
29
- raise unless $? == 0
28
+ unless $? == 0
29
+ raise
30
+ end
30
31
 
31
32
  change_to_revision "co"
32
33
  end
@@ -44,8 +45,7 @@ module Externals
44
45
 
45
46
  def ex *args
46
47
  # delete path if not empty
47
- (rmdircmd = "rmdir #{path}")
48
- `#{rmdircmd}`
48
+ rmdir_ie path
49
49
 
50
50
  url = repository
51
51
 
@@ -58,8 +58,7 @@ module Externals
58
58
  url += "@#{revision}"
59
59
  end
60
60
 
61
- `#{rmdircmd}` if File.exists? path
62
- puts(svncocmd = "svn #{scm_opts_ex} export #{repository} #{path}")
61
+ puts(svncocmd = "svn #{scm_opts_ex} export #{url} #{path}")
63
62
  puts `#{svncocmd}`
64
63
  end
65
64
 
@@ -77,10 +76,8 @@ module Externals
77
76
  end
78
77
 
79
78
  def up *args
80
- # delete path if not empty
81
- rmdircmd = "rmdir #{path}"
82
- `#{rmdircmd}` if File.exists? path
83
-
79
+ # delete path if empty
80
+ rmdir_if_empty_ie path
84
81
 
85
82
  if File.exists? path
86
83
  puts "updating #{path}:"
@@ -142,6 +139,7 @@ module Externals
142
139
 
143
140
  status.split("\n").grep(/^\?/).each do |to_add|
144
141
  puts `svn add #{to_add.gsub(/^\?\s*/,"")}`
142
+ raise unless $? == 0
145
143
  end
146
144
  end
147
145
 
@@ -151,7 +149,7 @@ module Externals
151
149
 
152
150
  def current_branch
153
151
  require_repository
154
- branch = info_url.gsub(repository, "")
152
+ branch = info_url.gsub(/\/+/, "/").gsub(repository.gsub(/\/+/, "/"), "")
155
153
  if branch == repository
156
154
  raise "Could not determine branch from URL #{info_url}.
157
155
  Does not appear have a substring of #{repository}"
@@ -0,0 +1,41 @@
1
+ require 'externals/test/repository'
2
+
3
+ module Externals
4
+ module Test
5
+ class BasicGitRepository < Repository
6
+ def initialize
7
+ super "basic", "git"
8
+ end
9
+
10
+ def build_here
11
+ mkdir name
12
+
13
+ Dir.chdir("#{name}") do
14
+ `git init`
15
+ raise unless $? == 0
16
+
17
+ open 'readme.txt', 'w' do |f|
18
+ f.write "readme.txt Line 1
19
+ Line 2
20
+ Line 3"
21
+ end
22
+
23
+ `git add .`
24
+ raise unless $? == 0
25
+ `git commit -m "added readme.txt"`
26
+ raise unless $? == 0
27
+
28
+ open 'readme.txt', 'a' do |f|
29
+ f.write "line 4"
30
+ end
31
+
32
+ `git add .`
33
+ raise unless $? == 0
34
+ `git commit -m "added a line to readme.txt"`
35
+ raise unless $? == 0
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ require 'externals/test/repository'
2
+
3
+ module Externals
4
+ module Test
5
+ class Engines < GitRepositoryFromInternet
6
+ def initialize
7
+ super "engines.git", "git", "git://github.com/azimux"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ require 'externals/test/repository'
2
+ require 'externals/test/engines'
3
+
4
+ module Externals
5
+ module Test
6
+ class EnginesWithBranch1 < Repository
7
+ def initialize
8
+ super "engines.git", File.join("git", "with_branch1")
9
+ dependents.merge!(
10
+ :other_engines => Engines.new
11
+ )
12
+ end
13
+
14
+ #builds the test repository in the current directory
15
+ def build_here
16
+ rm_rf_ie name
17
+
18
+ puts `git clone --bare #{dependents[:other_engines].clean_dir} #{name}`
19
+ raise unless $? == 0
20
+
21
+ rm_rf_ie "workdir"
22
+ mkdir "workdir"
23
+ Dir.chdir 'workdir' do
24
+ `git clone #{clean_dir}`
25
+ raise unless $? == 0
26
+ Dir.chdir name.gsub(".git", "") do
27
+ `git push origin master:branch1`
28
+ raise unless $? == 0
29
+ end
30
+ end
31
+ rm_rf_ie "workdir"
32
+ end
33
+
34
+ end
35
+ end
36
+ end