diff_dirs 0.1.1 → 0.1.2
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.
- data/VERSION +1 -1
- data/lib/diff_dirs.rb +17 -5
- data/test/diff_dirs_test.rb +40 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/diff_dirs.rb
CHANGED
@@ -20,10 +20,10 @@ class DiffDirs
|
|
20
20
|
# New/Deleted files
|
21
21
|
match = line.match(/^Only in ([^:]*): ([^$]*)$/)
|
22
22
|
if match
|
23
|
-
if match[1]
|
24
|
-
return [:deleted, match[2]] # deleted from second dir
|
25
|
-
elsif match[1]
|
26
|
-
return [:new, match[2]] # new in second dir
|
23
|
+
if match[1].starts_with?(dir1)
|
24
|
+
return [:deleted, remove_dir_from_path("#{match[1]}/#{match[2]}", dir1)] # deleted from second dir
|
25
|
+
elsif match[1].starts_with?(dir2)
|
26
|
+
return [:new, remove_dir_from_path("#{match[1]}/#{match[2]}", dir2)] # new in second dir
|
27
27
|
else
|
28
28
|
raise "#{dir1} or #{dir2} didn't match #{match[1]}"
|
29
29
|
end
|
@@ -43,7 +43,7 @@ class DiffDirs
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.remove_dir_from_path(path, dir)
|
46
|
-
dir
|
46
|
+
dir = add_slash(dir)
|
47
47
|
path.sub(Regexp.new("^#{dir}"), "")
|
48
48
|
end
|
49
49
|
|
@@ -54,6 +54,18 @@ class DiffDirs
|
|
54
54
|
dir
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
def self.add_slash(path)
|
59
|
+
path += "/" unless path[-1..-1] == "/"
|
60
|
+
path
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class String
|
65
|
+
def starts_with?(prefix)
|
66
|
+
prefix = prefix.to_s
|
67
|
+
self[0, prefix.length] == prefix
|
68
|
+
end
|
57
69
|
end
|
58
70
|
|
59
71
|
public
|
data/test/diff_dirs_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../diff_dirs'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/diff_dirs'
|
3
3
|
|
4
4
|
class DiffDirsTest < Test::Unit::TestCase
|
5
5
|
context "diff executable" do
|
@@ -67,4 +67,43 @@ class DiffDirsTest < Test::Unit::TestCase
|
|
67
67
|
assert_not_equal "~/", DiffDirs.send(:expand_path, "~/")
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
context "complex real life directory structure" do
|
72
|
+
setup do
|
73
|
+
@path = "/tmp/diff-dirs-test-#{rand(10000)}"
|
74
|
+
exec "mkdir -p #{@path}/1/dir1/dir2"
|
75
|
+
exec "touch #{@path}/1/dir1/file1"
|
76
|
+
exec "touch #{@path}/1/dir1/dir2/file2"
|
77
|
+
exec "mkdir -p #{@path}/1/foo/bar"
|
78
|
+
exec "touch #{@path}/1/foo/file_in_foo"
|
79
|
+
exec "touch #{@path}/1/file_in_root"
|
80
|
+
exec "touch #{@path}/1/another_file_in_root"
|
81
|
+
exec "echo hello > #{@path}/1/foo/file_with_content"
|
82
|
+
|
83
|
+
exec "mkdir -p #{@path}/2/foo/bar"
|
84
|
+
exec "touch #{@path}/2/foo/file_in_foo"
|
85
|
+
exec "touch #{@path}/2/foo/bar/file_in_bar"
|
86
|
+
exec "touch #{@path}/2/file_in_root"
|
87
|
+
exec "touch #{@path}/2/yet_another_file_in_root"
|
88
|
+
exec "echo world > #{@path}/2/foo/file_with_content"
|
89
|
+
end
|
90
|
+
|
91
|
+
teardown do
|
92
|
+
`rm -fr #{@path}`
|
93
|
+
end
|
94
|
+
|
95
|
+
should "run the full stack properly and return the correct diff result" do
|
96
|
+
|
97
|
+
assert_equal [[:deleted, "another_file_in_root"],
|
98
|
+
[:deleted, "dir1"],
|
99
|
+
[:new, "foo/bar/file_in_bar"],
|
100
|
+
[:modified, "foo/file_with_content"],
|
101
|
+
[:new, "yet_another_file_in_root"]], DiffDirs.diff_dirs("#{@path}/1", "#{@path}/2")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def exec(cmd)
|
106
|
+
# puts cmd
|
107
|
+
`#{cmd}`
|
108
|
+
end
|
70
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diff_dirs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Mercier
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-20 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|