public
Description: Syncs one directory to another (example: a git project to an svn repo)
Clone URL: git://github.com/technoweenie/duplikate.git
add Duplikate#ignore
osteele (author)
Sun Apr 06 08:11:54 -0700 2008
commit  dc4c73182bd56c9e765e983e5fa8ce2810131450
tree    ac690f8709df384db4baf167abf646ff19fef7d9
parent  17034859650054beec134a5e04d8c51de259cfe8
...
3
4
5
6
7
 
 
 
...
3
4
5
 
 
6
7
8
0
@@ -3,5 +3,6 @@ duplikate changes
0
 
0
 trunk
0
 -----
0
-add report method, to display lists of files by category
0
-add dry_run method, to display commands
0
+add Duplikate#ignore method
0
+add Duplikate#report and Duplikate.report, to display lists of files by kategory
0
+add Duplikate#dry_run and Duplikate.dry_run, to print commands that would execute
...
2
3
4
5
 
6
7
8
...
52
53
54
 
 
 
 
 
 
 
55
56
57
...
128
129
130
 
131
132
133
...
135
136
137
138
 
139
 
140
141
142
...
155
156
157
 
 
 
 
158
...
2
3
4
 
5
6
7
8
...
52
53
54
55
56
57
58
59
60
61
62
63
64
...
135
136
137
138
139
140
141
...
143
144
145
 
146
147
148
149
150
151
...
164
165
166
167
168
169
170
171
0
@@ -2,7 +2,7 @@ require 'pathname'
0
 require 'fileutils'
0
 class Duplikate
0
   attr_accessor :source, :destination
0
- attr_reader :deleted_files, :deleted_directories, :added_files, :added_directories, :existing_files, :commands
0
+ attr_reader :deleted_files, :deleted_directories, :added_files, :added_directories, :existing_files, :commands, :ignore_patterns
0
 
0
   # Processes the differences between the given source and destination
0
   # paths. The returned Duplikate object has the *_directories and *_files
0
@@ -52,6 +52,13 @@ class Duplikate
0
     @debug = @options[:debug]
0
     @source, @destination = Pathname.new(source), Pathname.new(dest)
0
     @inverse = self.class.new(dest, source, @options.merge(:is_inverse => true)) unless @options[:is_inverse]
0
+ @ignore_patterns = [/^\.(git|svn)?\.?$/]
0
+ end
0
+
0
+ # Ignores paths that match one of the +patterns+, where each pattern
0
+ # is either a String or Regexp
0
+ def ignore(*patterns)
0
+ @ignore_patterns += patterns
0
   end
0
   
0
   def process
0
@@ -128,6 +135,7 @@ protected
0
     unless path.nil?
0
       dest_entry = @destination + path
0
       unless dest_entry.directory?
0
+ return if ignore?(path.to_s)
0
         puts "ADDING DIR: #{path.inspect}" if @debug
0
         @added_directories << path.to_s
0
         return
0
@@ -135,8 +143,9 @@ protected
0
     end
0
 
0
     (path.nil? ? @source : @source + path).each_entry do |entry|
0
- next if entry.to_s =~ /^\.(git|svn)?\.?$/
0
+ next if entry.to_s =~ /^\.{1,2}$/
0
       full_entry = path.nil? ? entry : path + entry
0
+ next if ignore?(full_entry.to_s)
0
       source_entry = @source + full_entry
0
       if source_entry.directory?
0
         process_path(full_entry)
0
@@ -155,4 +164,8 @@ protected
0
       @added_files << file.to_s
0
     end
0
   end
0
+
0
+ def ignore?(pathname)
0
+ ignore_patterns.find { |p| p === pathname }
0
+ end
0
 end
...
79
80
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
83
84
...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
0
@@ -79,6 +79,33 @@ describe Duplikate do
0
   end
0
 end
0
 
0
+describe Duplikate, "ignore" do
0
+ before do
0
+ @source = File.join(File.dirname(__FILE__), 'source')
0
+ @dest = File.join(File.dirname(__FILE__), 'dest')
0
+ @duplikate = Duplikate.new @source, @dest
0
+ end
0
+
0
+ it "omits ignored files" do
0
+ @duplikate.ignore 'addme.txt'
0
+ @duplikate.process
0
+ @duplikate.added_files.should_not include("addme.txt")
0
+ end
0
+
0
+ it "omits ignored directories" do
0
+ @duplikate.ignore 'foo/addme'
0
+ @duplikate.process
0
+ @duplikate.added_directories.should_not include("foo/addme")
0
+ end
0
+
0
+ it "omits ignored file patterns" do
0
+ @duplikate.ignore /ad*me/
0
+ @duplikate.process
0
+ @duplikate.added_directories.should_not include("foo/addme")
0
+ @duplikate.added_files.should_not include("addme.txt")
0
+ end
0
+end
0
+
0
 describe Duplikate, "syncing two directories" do
0
   before do
0
     @source = File.join(File.dirname(__FILE__), 'source')

Comments

    No one has commented yet.