svnignore 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/Rakefile CHANGED
@@ -1,21 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = 'svnignore'
8
- gem.summary = 'git style ignores with subversion'
9
- gem.description = 'git style ignores with subversion'
10
- gem.email = 'shuber@huberry.com'
11
- gem.homepage = 'http://github.com/shuber/svnignore'
12
- gem.authors = ['Sean Huber']
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
- end
15
- rescue LoadError
16
- puts 'Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler'
17
- end
18
-
19
4
  require 'rake/testtask'
20
5
  Rake::TestTask.new(:test) do |test|
21
6
  test.libs << 'lib' << 'test'
@@ -36,8 +21,6 @@ rescue LoadError
36
21
  end
37
22
  end
38
23
 
39
- task :test => :check_dependencies
40
-
41
24
  task :default => :test
42
25
 
43
26
  require 'rake/rdoctask'
@@ -52,4 +35,5 @@ Rake::RDocTask.new do |rdoc|
52
35
  rdoc.title = "svnignore #{version}"
53
36
  rdoc.rdoc_files.include('README*')
54
37
  rdoc.rdoc_files.include('bin/**/*.rb')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
39
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -1,55 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'tempfile'
3
+ require 'rubygems' unless respond_to?(:gem)
4
+ require 'optparse'
5
+ begin
6
+ require 'svnignore'
7
+ rescue LoadError
8
+ require File.join(File.dirname(File.dirname(__FILE__)), 'lib', 'svnignore')
9
+ end
4
10
 
5
- Dir[File.join(Dir.pwd, '**', '.svnignore')].each do |file|
6
- # Stores the parsed ignore patterns
7
- #
8
- ignores = Hash.new { |hash, key| hash[key] = [] }
9
-
10
- # Read the patterns from the svn ignore file
11
- #
12
- patterns = File.read(file).split("\n")
13
-
14
- patterns.each do |pattern|
15
- # Figure out paths
16
- #
17
- path = File.join(File.dirname(file), pattern)
18
- parent = File.dirname(path)
19
- relative_path = (parent == Dir.pwd) ? '.' : File.join(parent.gsub(File.join(Dir.pwd, ''), ''), '')
20
-
21
- # Check for ** in path (recursive ignore)
22
- #
23
- if relative_path =~ /\*\*\//
24
- relative_path.gsub!(/\*\*\/.*$/, '')
25
- relative_path = '.' if relative_path.empty?
26
- recursive = '-R '
27
- else
28
- recursive = ''
29
- end
30
-
31
- ignores[relative_path] << { :pattern => File.basename(pattern), :recursive => recursive }
32
- end
33
-
34
- # Ignore the patterns
35
- #
36
- ignores.sort.each do |(relative_path, patterns)|
37
- if patterns.length == 1
38
- options = patterns.first[:recursive]
39
- pattern = "'#{patterns.first[:pattern].gsub(/'/, "\\\\'")}'"
40
- else
41
- # Create a temporary file to store a newline separated list of files to ignore for this relative path
42
- #
43
- temp_file = Tempfile.new('svn-ignore-', Dir.pwd)
44
- temp_file.print(patterns.map { |configuration| configuration[:pattern] }.join("\n"))
45
- temp_file.flush
46
-
47
- options = '-F '
48
- pattern = File.basename(temp_file.path)
49
- end
50
-
51
- command = "svn propset svn:ignore #{options}#{pattern} #{relative_path}"
52
- # puts command
53
- system command
54
- end
55
- end
11
+ OptionParser.new do |opts|
12
+ opts.banner = 'Usage: svnignore [options]'
13
+ opts.on('-f', '--file [FILE]', String, 'The file to parse ignore rules from. Default: .svnigore') { |file| Svnignore.default_options[:file] = file }
14
+ opts.on('--no-recursive', 'Do not recursively look up files with ignore rules.') { |recursive| Svnignore.default_options[:recursive] = false }
15
+ end.parse!
16
+
17
+ Svnignore.ignore(Dir.pwd)
@@ -0,0 +1,79 @@
1
+ require 'tempfile'
2
+
3
+ class Svnignore
4
+
5
+ TEMPFILE_PREFIX = 'svnignore-'
6
+
7
+ def self.default_options
8
+ @default_options ||= { :file => '.svnignore', :recursive => true }
9
+ end
10
+
11
+ def self.ignore(current_working_directory, options = {})
12
+ options = default_options.merge(options)
13
+ files = find_files_with_ignore_rules(current_working_directory, options)
14
+ files.each do |file|
15
+ ignore_rules = parse_ignore_rules_from_file(file, current_working_directory)
16
+ commands = generate_svn_commands_for_ignore_rules(ignore_rules)
17
+ commands.each { |command| execute command }
18
+ end
19
+ end
20
+
21
+ protected
22
+
23
+ def self.create_tempfile_for_patterns(patterns)
24
+ tempfile = Tempfile.new(TEMPFILE_PREFIX, Dir.pwd)
25
+ tempfile.print(patterns.map { |configuration| configuration[:pattern] }.join("\n"))
26
+ tempfile.flush
27
+ tempfile
28
+ end
29
+
30
+ def self.execute(command)
31
+ system command
32
+ end
33
+
34
+ def self.find_files_with_ignore_rules(current_working_directory, options)
35
+ path = [current_working_directory]
36
+ path << '**' if options[:recursive]
37
+ path << options[:file]
38
+ Dir[File.join(*path)]
39
+ end
40
+
41
+ def self.generate_svn_commands_for_ignore_rules(ignore_rules)
42
+ ignore_rules.sort.inject([]) do |commands, (relative_path, patterns)|
43
+ if patterns.length == 1
44
+ options = patterns.first[:recursive] ? '-R ' : ''
45
+ pattern = "'#{patterns.first[:pattern].gsub(/'/, "\\\\'")}'"
46
+ else
47
+ tempfile = create_tempfile_for_patterns(patterns)
48
+ options = '-F '
49
+ pattern = File.basename(tempfile.path)
50
+ end
51
+
52
+ commands << "svn propset svn:ignore #{options}#{pattern} #{relative_path}"
53
+ end
54
+ end
55
+
56
+ def self.parse_ignore_rules_from_file(file, current_working_directory)
57
+ ignore_rules = Hash.new { |hash, key| hash[key] = [] }
58
+ patterns = File.read(file).split("\n")
59
+
60
+ patterns.each do |pattern|
61
+ path = File.join(File.dirname(file), pattern)
62
+ parent = File.dirname(path)
63
+ relative_path = (parent == current_working_directory) ? '.' : File.join(parent.gsub(File.join(current_working_directory, ''), ''), '')
64
+
65
+ if relative_path =~ /\*\*\// # recursive ignore
66
+ relative_path.gsub!(/\*\*\/.*$/, '')
67
+ relative_path = '.' if relative_path.empty?
68
+ recursive = true
69
+ else
70
+ recursive = false
71
+ end
72
+
73
+ ignore_rules[relative_path] << { :pattern => File.basename(pattern), :recursive => recursive }
74
+ end
75
+
76
+ ignore_rules
77
+ end
78
+
79
+ end
@@ -0,0 +1,6 @@
1
+ **/.DS_Store
2
+ config/application_settings.yml
3
+ config/database.yml
4
+ db/*.sqlite3
5
+ log/*.log
6
+ tmp/*
@@ -0,0 +1 @@
1
+ testing.txt
@@ -0,0 +1 @@
1
+ other_file.txt
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class SvnignoreTest < Test::Unit::TestCase
4
+
5
+ should 'have a TEMPFILE_PREFIX' do
6
+ assert Svnignore.const_defined?('TEMPFILE_PREFIX')
7
+ assert !Svnignore::TEMPFILE_PREFIX.nil?
8
+ assert !Svnignore::TEMPFILE_PREFIX.empty?
9
+ end
10
+
11
+ should 'parse the correct ignore rules from file' do
12
+ assert_equal parsed_rules, Svnignore.send(:parse_ignore_rules_from_file, tempfile.path, Dir.pwd)
13
+ end
14
+
15
+ should 'find files with ignore rules' do
16
+ assert_equal 2, Svnignore.send(:find_files_with_ignore_rules, fixtures_path, { :file => '.svnignore', :recursive => true }).size
17
+ assert_equal 1, Svnignore.send(:find_files_with_ignore_rules, fixtures_path, { :file => '.svnignore', :recursive => false }).size
18
+ assert_equal 1, Svnignore.send(:find_files_with_ignore_rules, fixtures_path, { :file => 'svnignore.txt', :recursive => true }).size
19
+ end
20
+
21
+ should 'generate svn commands for ignore rules' do
22
+ parsed_svn_commands = Svnignore.send(:generate_svn_commands_for_ignore_rules, parsed_rules)
23
+ svn_commands.each_with_index do |command, index|
24
+ if command =~ / -F /
25
+ assert_equal command.gsub(/ -F (\S+)/, ' -F ' + parsed_svn_commands[index].match(/ -F (\S+)/).captures[0]), parsed_svn_commands[index]
26
+ else
27
+ assert_equal command, parsed_svn_commands[index]
28
+ end
29
+ end
30
+ end
31
+
32
+ should 'execute svn commands' do
33
+ Svnignore.ignore(fixtures_path, :recursive => false)
34
+ assert_equal svn_commands.size, Svnignore.execute.size
35
+ end
36
+
37
+ end
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'svnignore'
8
+
9
+ Svnignore.class_eval do
10
+ def self.execute(command = nil)
11
+ @commands ||= []
12
+ @commands << command unless command.nil?
13
+ @commands
14
+ end
15
+ end
16
+
17
+ class Test::Unit::TestCase
18
+
19
+ def fixtures_path
20
+ File.join(File.dirname(__FILE__), 'fixtures')
21
+ end
22
+
23
+ def parsed_rules
24
+ @parsed_rules ||= {
25
+ '.' => [{ :pattern => '.DS_Store', :recursive => true }],
26
+ 'config/' => [{ :pattern => 'application_settings.yml', :recursive => false }, { :pattern => 'database.yml', :recursive => false }],
27
+ 'db/' => [{ :pattern => '*.sqlite3', :recursive => false }],
28
+ 'log/' => [{ :pattern => '*.log', :recursive => false }],
29
+ 'tmp/' => [{ :pattern => '*', :recursive => false }]
30
+ }
31
+ end
32
+
33
+ def rules
34
+ @rules ||= [
35
+ '**/.DS_Store',
36
+ 'config/application_settings.yml',
37
+ 'config/database.yml',
38
+ 'db/*.sqlite3',
39
+ 'log/*.log',
40
+ 'tmp/*'
41
+ ]
42
+ end
43
+
44
+ def svn_commands
45
+ @svn_commands ||= [
46
+ "svn propset svn:ignore -R '.DS_Store' .",
47
+ "svn propset svn:ignore -F some_temp_file config/",
48
+ "svn propset svn:ignore '*.sqlite3' db/",
49
+ "svn propset svn:ignore '*.log' log/",
50
+ "svn propset svn:ignore '*' tmp/"
51
+ ]
52
+ end
53
+
54
+ def tempfile
55
+ if @tempfile.nil?
56
+ @tempfile = Tempfile.new('svnignore_test', Dir.pwd)
57
+ @tempfile.print(rules.join("\n"))
58
+ @tempfile.flush
59
+ end
60
+ @tempfile
61
+ end
62
+
63
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svnignore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-06 00:00:00 -08:00
12
+ date: 2010-01-22 00:00:00 -08:00
13
13
  default_executable: svnignore
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
16
25
  description: git style ignores with subversion
17
26
  email: shuber@huberry.com
18
27
  executables:
@@ -22,12 +31,17 @@ extensions: []
22
31
  extra_rdoc_files:
23
32
  - README.rdoc
24
33
  files:
25
- - CHANGELOG
26
34
  - MIT-LICENSE
27
35
  - README.rdoc
28
36
  - Rakefile
29
37
  - VERSION
30
38
  - bin/svnignore
39
+ - lib/svnignore.rb
40
+ - test/fixtures/.svnignore
41
+ - test/fixtures/nested/.svnignore
42
+ - test/fixtures/svnignore.txt
43
+ - test/svnignore_test.rb
44
+ - test/test_helper.rb
31
45
  has_rdoc: true
32
46
  homepage: http://github.com/shuber/svnignore
33
47
  licenses: []
@@ -56,5 +70,9 @@ rubygems_version: 1.3.5
56
70
  signing_key:
57
71
  specification_version: 3
58
72
  summary: git style ignores with subversion
59
- test_files: []
60
-
73
+ test_files:
74
+ - test/fixtures/.svnignore
75
+ - test/fixtures/nested/.svnignore
76
+ - test/fixtures/svnignore.txt
77
+ - test/svnignore_test.rb
78
+ - test/test_helper.rb
data/CHANGELOG DELETED
@@ -1,6 +0,0 @@
1
- 2009-03-05 - Sean Huber (shuber@huberry.com)
2
- * Initial commit
3
- * Change file permissions
4
- * Add ignore logic
5
- * Remove symlink to svnignore file
6
- * Update README