dir2svn 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4f2af29be30d12a177d853d184732cfe8df5385
4
+ data.tar.gz: 35c4acf1f766e13b014ba63ce4af761c57a4444d
5
+ SHA512:
6
+ metadata.gz: b2ff9603bb48f1c22efa6d3a28ff388b62e166605641d9d0a9881546b46f6c810309bc00aafe5c2f9341e3f1c7380b5cd0ceb680b57004b33bf998c455317706
7
+ data.tar.gz: d10adf0fc19a1070968b430c0e3b0a1981e4cace2f19ade59dc87e955fc5dea21b0140e05275ad091c9f0ef0dc5b6f560521dd779c611a6536f4620915aed9b0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dir2svn.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/dir2svn.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dir2svn/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dir2svn"
8
+ spec.version = Dir2svn::VERSION
9
+ spec.authors = ["Onno"]
10
+ spec.email = ["onno@onknows.com"]
11
+
12
+ spec.summary = %q{Sync a folder to Subversion.}
13
+ spec.description = %q{Sync a folder to a Subversion working copy. It will make changes to the working copy so that is equal to the source folder}
14
+ spec.homepage = "https://rubygems.org/profiles/onknows"
15
+ spec.license = "MIT"
16
+
17
+ #spec.files = `svn ls -R`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.files = ['exe/dir2svn','lib/dir2svn.rb','lib/dir2svn/version.rb','dir2svn.gemspec','Gemfile','Rakefile']
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.8"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency 'pry', '~> 0.10'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'geminabox', '~> 0.12'
28
+ spec.add_development_dependency 'rubocop', '~> 0.25'
29
+ end
data/exe/dir2svn ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'svnutil'
4
+ cmdline = ARGV.join(' ')
5
+ dir2svn = Svnutil::Dir2svn.new(ARGV[0],ARGV[1])
6
+ dir2svn.do_puts = false if cmdline.include? '--silent'
7
+
8
+ dir2svn.sync
@@ -0,0 +1,3 @@
1
+ module Dir2svn
2
+ VERSION = "0.1.0"
3
+ end
data/lib/dir2svn.rb ADDED
@@ -0,0 +1,152 @@
1
+ require "dir2svn/version"
2
+ require 'find'
3
+ require 'fileutils'
4
+
5
+ module Dir2svn
6
+ ERR1 = 'Provide the source and target path before doing a sync'
7
+ ERR2 = 'Source folder does not exist'
8
+ ERR3 = 'Target needs to be in a Subversion managed folder'
9
+
10
+ # Utility to sync a folder to a Subversion working copy
11
+ # The working copy folder is the 'target'
12
+ class Sync
13
+ attr_accessor :source, :target, :exclude, :do_puts
14
+
15
+ def initialize(*args)
16
+ @source = args[0]
17
+ @target = args[1]
18
+ @exclude = args[2] || '.svn,.trashbin,.folder,__generated.txt'
19
+ @do_puts = args[3] || true
20
+ end
21
+
22
+ def check_source_target_etc
23
+ fail ERR1 if source.nil? || target.nil?
24
+ fail ERR2 unless File.exist? source
25
+ end
26
+
27
+ def svn_mkdir_target
28
+ `svn mkdir --parents \"#{target}\" 2>>svn_mkdir.tmp 1>>svn_mkdir.tmp`
29
+ svn_mkdir = File.read('svn_mkdir.tmp')
30
+ File.delete('svn_mkdir.tmp')
31
+ fail ERR3 if svn_mkdir.include? 'is not a working copy'
32
+ end
33
+
34
+ def run
35
+ check_source_target_etc
36
+ svn_mkdir_target
37
+ results = Dir2svn.sync_paths(source, target, exclude, do_puts)
38
+ end
39
+ end
40
+
41
+ def sync_paths(src, dest, exclude, do_puts)
42
+ src = File.expand_path(src) + '/'
43
+ dest = File.expand_path(dest) + '/'
44
+ results = nil
45
+ # First files, then folders,
46
+ # as the processing of files can also sync folders
47
+ results = Dir2svn.sync_file_paths(src, dest, exclude, do_puts)
48
+ Dir2svn.sync_folder_paths(src, dest, exclude, do_puts)
49
+ results
50
+ end
51
+ module_function :sync_paths
52
+
53
+ # See SvnRepository#sync_paths
54
+ def sync_file_paths(src, dest, exclude, do_puts)
55
+ fls_dest = Dir2svn.find_files(dest, exclude, do_puts).collect { |p| p.sub(dest, '') }
56
+ fls_src = Dir2svn.find_files(src, exclude, do_puts).collect { |p| p.sub(src, '') }
57
+ fls_d = fls_dest - fls_src # deleted: in DEST but not (anymore) in SRC
58
+ fls_a = fls_src - fls_dest # added: in SRC but not (yet) in SRC
59
+ fls_f = fls_src - fls_a # found: in SRC and DEST: everything in SRC that we didn't add
60
+ fls_u = [] # updated
61
+ fls_e = [] # equal
62
+
63
+ # Update files
64
+ fls_f.collect do |p| # update files
65
+ p1 = File.expand_path(p, src) # new version
66
+ p0 = File.expand_path(p, dest) # existing version
67
+ if File.identical?(p1, p0)
68
+ fls_e << p
69
+ else
70
+ FileUtils.cp(p1, p0)
71
+ fls_u << p
72
+ end
73
+ end
74
+
75
+ # Add files
76
+ fls_a.each do |p|
77
+ p1 = File.expand_path(p, src) # new version
78
+ p0 = File.expand_path(p, dest)
79
+ unless File.exist?(File.dirname(p0)) # create parent dir of new file unless it exists
80
+ # self.makedir_parents(File.dirname(p0)) unless File.exists?(File.dirname(p0))
81
+ cmd = "svn mkdir --parents \"#{File.dirname(p0)}\""
82
+ out = `#{cmd}`
83
+ puts "#{cmd}\n#{out}" if do_puts
84
+ end
85
+ FileUtils.cp(p1, p0)
86
+ cmd = "svn add \"#{p0}\""
87
+ out = `#{cmd}`
88
+ puts "#{cmd}\n#{out}" if do_puts
89
+ end
90
+
91
+ # delete files
92
+ fls_d.each do |p|
93
+ p0 = File.expand_path(p, dest)
94
+ cmd = "svn rm \"#{p0}\""
95
+ out = `#{cmd}`
96
+ puts "#{cmd}\n#{out}" if do_puts
97
+ end
98
+ { deleted: fls_d, added: fls_a, updated: fls_u, equal: fls_e }
99
+ end
100
+ module_function :sync_file_paths
101
+
102
+ # See SvnRepository#sync_paths
103
+ def sync_folder_paths(src, dest, exclude, do_puts)
104
+ fldrs_src = Dir2svn.find_folders(src, exclude, do_puts).collect { |p| p.sub(src, '') }
105
+ fldrs_dest = Dir2svn.find_folders(dest, exclude, do_puts).collect { |p| p.sub(dest, '') }
106
+ fldrs_d = (fldrs_dest - fldrs_src) # deleted folders: see deleted files
107
+ fldrs_a = (fldrs_src - fldrs_dest) # add folders: see added files
108
+ fldrs_d.each do |p| # deleted folders
109
+ p0 = File.expand_path(p, dest)
110
+ next unless File.exist?(p0)
111
+ cmd = "svn rm \"#{p0}\""
112
+ out = `#{cmd}`
113
+ puts "#{cmd}\n#{out}" if do_puts
114
+ end
115
+ fldrs_a.each do |p| # added folders (must be empty, not very useful but..)
116
+ p0 = File.expand_path(p, dest)
117
+ cmd = "svn mkdir --parents \"#{p0}\""
118
+ out = `#{cmd}`
119
+ puts "#{cmd}\n#{out}" if do_puts
120
+ end
121
+ end
122
+ module_function :sync_folder_paths
123
+
124
+ def find_files(path, exclude, do_puts)
125
+ Dir2svn.find_paths(path, exclude, do_puts)[:files]
126
+ end
127
+ module_function :find_files
128
+
129
+ def find_folders(path, exclude, do_puts)
130
+ Dir2svn.find_paths(path, exclude, do_puts)[:folders]
131
+ end
132
+ module_function :find_folders
133
+
134
+ def find_paths(path, exclude, _do_puts)
135
+ fls = []
136
+ fldrs = []
137
+ Find.find(path) do |p|
138
+ if FileTest.directory?(p)
139
+ if exclude.include?(File.basename(p))
140
+ Find.prune # Don't look any further into this directory.
141
+ else
142
+ fldrs << p
143
+ next
144
+ end
145
+ else # ignore .folder files
146
+ fls << p unless exclude.include?(File.basename(p))
147
+ end
148
+ end
149
+ { files: fls, folders: fldrs }
150
+ end
151
+ module_function :find_paths
152
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dir2svn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Onno
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: geminabox
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.25'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.25'
97
+ description: Sync a folder to a Subversion working copy. It will make changes to the
98
+ working copy so that is equal to the source folder
99
+ email:
100
+ - onno@onknows.com
101
+ executables:
102
+ - dir2svn
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - Gemfile
107
+ - Rakefile
108
+ - dir2svn.gemspec
109
+ - exe/dir2svn
110
+ - lib/dir2svn.rb
111
+ - lib/dir2svn/version.rb
112
+ homepage: https://rubygems.org/profiles/onknows
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.6
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Sync a folder to Subversion.
136
+ test_files: []