svn_command_helper 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +11 -9
- data/lib/svn_command_helper.rb +97 -6
- data/lib/svn_command_helper/version.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d47ea36471b94fda56202e1c64b89d24b989ae98
|
4
|
+
data.tar.gz: 794513a1bc00aea3fdcb3e426e09e3a7732f56f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45ca7ade456b31728cc8ba6737792f8a9fdff942f64442f398ee5f323d62168d0324d1321b03c6d9d573240317a21d71a9fcd283d99eb33d01cf6dd60b1dcfcd
|
7
|
+
data.tar.gz: 3c6af82ce304903f6710383f0eebc088a7d331078110b4b035a13d4a021e28edd38834b9f283ecc54525935e9a6173e0becc8f11baa9cba802738d76ac889b20
|
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# SvnCommandHelper
|
2
|
+
# [SvnCommandHelper](https://github.com/SystemCommandHelperRB/svn_command_helper)
|
2
3
|
|
3
|
-
|
4
|
+
[](https://rubygems.org/gems/svn_command_helper)
|
5
|
+
[](https://rubygems.org/gems/svn_command_helper)
|
6
|
+
[](https://gemnasium.com/github.com/SystemCommandHelperRB/svn_command_helper)
|
7
|
+
[](http://inch-ci.org/github/SystemCommandHelperRB/svn_command_helper)
|
4
8
|
|
5
|
-
|
9
|
+
svn command helper
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
@@ -20,10 +24,6 @@ Or install it yourself as:
|
|
20
24
|
|
21
25
|
$ gem install svn_command_helper
|
22
26
|
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
27
|
## Development
|
28
28
|
|
29
29
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -32,10 +32,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SystemCommandHelperRB/svn_command_helper.
|
36
36
|
|
37
|
+
## API
|
37
38
|
|
38
|
-
|
39
|
+
[API Document](http://www.rubydoc.info/github/SystemCommandHelperRB/svn_command_helper)
|
39
40
|
|
40
|
-
|
41
|
+
## License
|
41
42
|
|
43
|
+
This is released under [MIT License](http://narazaka.net/license/MIT?2016).
|
data/lib/svn_command_helper.rb
CHANGED
@@ -3,11 +3,17 @@ require 'pathname'
|
|
3
3
|
require 'yaml'
|
4
4
|
require "system_command_helper"
|
5
5
|
|
6
|
+
# Subversion command helper
|
6
7
|
module SvnCommandHelper
|
8
|
+
# Subversion native command and some utilities
|
7
9
|
module Svn
|
10
|
+
# module methods
|
8
11
|
module ModuleMethods
|
9
12
|
include ::SystemCommandHelper
|
10
13
|
|
14
|
+
# svn commit
|
15
|
+
# @param [String] message commit message
|
16
|
+
# @param [path string like] path target path
|
11
17
|
def commit(message, path = ".")
|
12
18
|
if cap("svn status #{path}").empty?
|
13
19
|
sys "svn revert -R #{path}"
|
@@ -18,27 +24,61 @@ module SvnCommandHelper
|
|
18
24
|
sys "svn update #{path}"
|
19
25
|
end
|
20
26
|
|
27
|
+
# svn list
|
28
|
+
# @param [uri string like] uri target uri
|
29
|
+
# @param [Boolean] recursive --recursive
|
30
|
+
# @return [Array<String>] paths
|
21
31
|
def list(uri, recursive = false)
|
22
32
|
cap("svn list #{recursive ? '-R' : ''} #{uri}").split(/\n/).compact
|
23
33
|
.reject {|path| path.empty?}
|
24
34
|
end
|
25
35
|
|
36
|
+
# svn list --recursive
|
37
|
+
# @param [uri string like] uri target uri
|
38
|
+
# @return [Array<String>] paths
|
26
39
|
def list_recursive(uri)
|
27
40
|
list(uri, true)
|
28
41
|
end
|
29
42
|
|
43
|
+
# svn list -> grep only files
|
44
|
+
# @param [uri string like] uri target uri
|
45
|
+
# @param [Boolean] recursive --recursive
|
46
|
+
# @return [Array<String>] file paths
|
30
47
|
def list_files(uri, recursive = false)
|
31
48
|
list(uri, recursive).reject {|path| path.end_with?("/")} # dir
|
32
49
|
end
|
33
50
|
|
51
|
+
# svn list --recursive -> grep only files
|
52
|
+
# @param [uri string like] uri target uri
|
53
|
+
# @return [Array<String>] file paths
|
34
54
|
def list_files_recursive(uri)
|
35
55
|
list_files(uri, true)
|
36
56
|
end
|
37
57
|
|
38
|
-
|
58
|
+
# check svn uri exists or not
|
59
|
+
# @param [uri string like] uri target uri
|
60
|
+
# @return [Boolean] true if exists
|
61
|
+
def exist?(uri)
|
62
|
+
list(File.dirname(uri)).find{|_file| File.fnmatch(@file, _file.sub(/\/$/, ''))}
|
63
|
+
end
|
64
|
+
|
65
|
+
# check svn uri file exists or not
|
66
|
+
# @param [uri string like] uri target uri
|
67
|
+
# @return [Boolean] true if exists
|
68
|
+
def exist_file?(uri)
|
69
|
+
list_files(File.dirname(uri)).find{|_file| File.fnmatch(@file, _file)}
|
70
|
+
end
|
71
|
+
|
72
|
+
# svn update
|
73
|
+
# @param [path string like] path target path
|
74
|
+
# @param [depth] depth --set-depth
|
75
|
+
def update(path = ".", depth = nil)
|
39
76
|
sys "svn update #{depth ? "--set-depth #{depth}" : ""} #{path}"
|
40
77
|
end
|
41
78
|
|
79
|
+
# svn update to deep path recursive
|
80
|
+
# @param [path string like] path target path
|
81
|
+
# @param [depth] depth --set-depth for only new updated dirs
|
42
82
|
def update_deep(path, depth = nil)
|
43
83
|
root = Pathname.new(Svn.working_copy_root_path(path)).realpath
|
44
84
|
end_path = Pathname.new(path.to_s).expand_path.realpath
|
@@ -55,18 +95,30 @@ module SvnCommandHelper
|
|
55
95
|
end
|
56
96
|
end
|
57
97
|
|
98
|
+
# svn info -> yaml parse
|
99
|
+
# @param [path string like] path target path
|
100
|
+
# @return [Hash<String, String>] svn info contents
|
58
101
|
def info(path = ".")
|
59
102
|
YAML.load(cap("svn info #{path}"))
|
60
103
|
end
|
61
104
|
|
105
|
+
# svn cat
|
106
|
+
# @param [path string like] path target path
|
107
|
+
# @return [String] file contents
|
62
108
|
def cat(path)
|
63
109
|
cap("svn cat #{path}")
|
64
110
|
end
|
65
111
|
|
112
|
+
# Working Copy Root Path from svn info
|
113
|
+
# @param [path string like] path target path
|
114
|
+
# @return [String] Working Copy Root Path
|
66
115
|
def working_copy_root_path(path = ".")
|
67
116
|
info(path)["Working Copy Root Path"]
|
68
117
|
end
|
69
118
|
|
119
|
+
# find common part of the given uris
|
120
|
+
# @param [Array<uri string like>] uris target uri
|
121
|
+
# @return [String] common part of the given uris
|
70
122
|
def base_uri_of(uris)
|
71
123
|
uris.reduce(Pathname.new(uris.first.to_s)) do |base_uri, uri|
|
72
124
|
rel = Pathname.new(uri).relative_path_from(base_uri)
|
@@ -75,6 +127,9 @@ module SvnCommandHelper
|
|
75
127
|
end.to_s
|
76
128
|
end
|
77
129
|
|
130
|
+
# copy single transaction
|
131
|
+
# @param [SvnFileCopyTransaction] transaction from and to info
|
132
|
+
# @param [String] message commit message
|
78
133
|
def copy_single(transaction, message)
|
79
134
|
transactions = transaction.glob_transactions
|
80
135
|
raise "copy_single: #{transaction.from} not exists" if transactions.empty?
|
@@ -97,6 +152,9 @@ module SvnCommandHelper
|
|
97
152
|
end
|
98
153
|
end
|
99
154
|
|
155
|
+
# copy multi transactions
|
156
|
+
# @param [Array<SvnFileCopyTransaction>] transactions from and to info list
|
157
|
+
# @param [String] message commit message
|
100
158
|
def copy_multi(transactions, message)
|
101
159
|
base_uri = base_uri_of(transactions.map(&:from_base) + trnsactions.map(&:to_base))
|
102
160
|
transactions.each do |transaction|
|
@@ -118,16 +176,22 @@ module SvnCommandHelper
|
|
118
176
|
end
|
119
177
|
end
|
120
178
|
|
179
|
+
# check transaction from file exists
|
180
|
+
# @param [SvnFileCopyTransaction] transaction from and to info
|
181
|
+
# @param [Boolean] raise_if_from_not_found raise if from not found
|
182
|
+
# @return [Boolean] true if file exists
|
121
183
|
def check_exists(transaction, raise_if_from_not_found = true)
|
122
184
|
unless transaction.from_exist?
|
123
185
|
if !raise_if_from_not_found
|
124
|
-
|
186
|
+
false
|
125
187
|
elsif transaction.to_exist?
|
126
188
|
puts "[WARNING] File:#{file}はコピー先のみにあります"
|
127
|
-
|
189
|
+
false
|
128
190
|
else
|
129
191
|
raise "[Error] File:#{file}が見つかりません!"
|
130
192
|
end
|
193
|
+
else
|
194
|
+
true
|
131
195
|
end
|
132
196
|
end
|
133
197
|
end
|
@@ -135,49 +199,76 @@ module SvnCommandHelper
|
|
135
199
|
extend ModuleMethods
|
136
200
|
end
|
137
201
|
|
202
|
+
# svn file copy transaction
|
203
|
+
# @attr [String] from_base from base uri
|
204
|
+
# @attr [String] to_base to base uri
|
205
|
+
# @attr [String] file file basename
|
138
206
|
class SvnFileCopyTransaction
|
139
|
-
attr_reader :from_base
|
207
|
+
attr_reader :from_base
|
208
|
+
attr_reader :to_base
|
209
|
+
attr_reader :file
|
140
210
|
|
211
|
+
# @param [String] from_base from base uri
|
212
|
+
# @param [String] to_base to base uri
|
213
|
+
# @param [String] file file basename
|
141
214
|
def initialize(from_base:, to_base:, file:)
|
142
215
|
@from_base = from_base
|
143
216
|
@to_base = to_base
|
144
217
|
@file = file
|
145
218
|
end
|
146
219
|
|
220
|
+
# from uri
|
221
|
+
# @return [String] from uri
|
147
222
|
def from
|
148
223
|
File.join(@from_base, @file)
|
149
224
|
end
|
150
225
|
|
226
|
+
# to uri
|
227
|
+
# @return [String] to uri
|
151
228
|
def to
|
152
229
|
File.join(@to_base, @file)
|
153
230
|
end
|
154
231
|
|
232
|
+
# filename glob (like "hoge*") to each single file transaction
|
233
|
+
# @return [Array<SvnFileCopyTransaction>] transactions
|
155
234
|
def glob_transactions
|
156
235
|
Svn.list_files(@from_base)
|
157
236
|
.select{|_file| File.fnmatch(@file, _file)}
|
158
237
|
.map{|_file| SvnFileCopyTransaction.new(from_base: @from_base, to_base: @to_base, file: _file)}
|
159
238
|
end
|
160
239
|
|
240
|
+
# from uri exists?
|
241
|
+
# @return [Boolean]
|
161
242
|
def from_exist?
|
162
|
-
Svn.
|
243
|
+
Svn.exist_file?(from)
|
163
244
|
end
|
164
245
|
|
246
|
+
# to uri exists?
|
247
|
+
# @return [Boolean]
|
165
248
|
def to_exist?
|
166
|
-
Svn.
|
249
|
+
Svn.exist_file?(to)
|
167
250
|
end
|
168
251
|
|
252
|
+
# relative from base path from given base uri
|
253
|
+
# @return [String] relative from base path
|
169
254
|
def relative_from_base(path)
|
170
255
|
Pathname.new(@from_base).relative_path_from(Pathname.new(path)).to_s
|
171
256
|
end
|
172
257
|
|
258
|
+
# relative to base path from given base uri
|
259
|
+
# @return [String] relative to base path
|
173
260
|
def relative_to_base(path)
|
174
261
|
Pathname.new(@to_base).relative_path_from(Pathname.new(path)).to_s
|
175
262
|
end
|
176
263
|
|
264
|
+
# relative from path from given base uri
|
265
|
+
# @return [String] relative from path
|
177
266
|
def relative_from(path)
|
178
267
|
File.join(relative_from_base(path), @file)
|
179
268
|
end
|
180
269
|
|
270
|
+
# relative to path from given base uri
|
271
|
+
# @return [String] relative to path
|
181
272
|
def relative_to(path)
|
182
273
|
File.join(relative_from_to(path), @file)
|
183
274
|
end
|