svn_command_helper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/svn_command_helper/version.rb +3 -0
- data/lib/svn_command_helper.rb +185 -0
- data/svn_command_helper.gemspec +29 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 34acdb9910cb150f794c4319621e038c37737388
|
4
|
+
data.tar.gz: b8a942e444e3bed3a7539abc71d23d1abc80f6e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e58f2996c63cc5b46ede2f51328596bfc9f7486fa332f8e2530699ec9e1ddc9a89bf570bd775f956358cfafe50bfe1ec504d7dc66d23ce6e81a1134e2d84c44b
|
7
|
+
data.tar.gz: 55b53a1d787037835765696baf6252ce5f8522f4c40f95505127630f7670c3113d17a02d000585e6d9dea350bd7f5191698a8210bc69b7616dcf9e4a18eafc87
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Narazaka
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# SvnCommandHelper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/svn_command_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'svn_command_helper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install svn_command_helper
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
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.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/svn_command_helper.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "svn_command_helper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
require "svn_command_helper/version"
|
2
|
+
require 'pathname'
|
3
|
+
require 'yaml'
|
4
|
+
require "system_command_helper"
|
5
|
+
|
6
|
+
module SvnCommandHelper
|
7
|
+
module Svn
|
8
|
+
module ModuleMethods
|
9
|
+
include ::SystemCommandHelper
|
10
|
+
|
11
|
+
def commit(message, path = ".")
|
12
|
+
if cap("svn status #{path}").empty?
|
13
|
+
sys "svn revert -R #{path}"
|
14
|
+
puts "[WARNING] no change: #{message}"
|
15
|
+
else
|
16
|
+
sys "svn commit -m '#{message}' #{path}"
|
17
|
+
end
|
18
|
+
sys "svn update #{path}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def list(uri, recursive = false)
|
22
|
+
cap("svn list #{recursive ? '-R' : ''} #{uri}").split(/\n/).compact
|
23
|
+
.reject {|path| path.empty?}
|
24
|
+
end
|
25
|
+
|
26
|
+
def list_recursive(uri)
|
27
|
+
list(uri, true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def list_files(uri, recursive = false)
|
31
|
+
list(uri, recursive).reject {|path| path.end_with?("/")} # dir
|
32
|
+
end
|
33
|
+
|
34
|
+
def list_files_recursive(uri)
|
35
|
+
list_files(uri, true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def update(path, depth = nil)
|
39
|
+
sys "svn update #{depth ? "--set-depth #{depth}" : ""} #{path}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_deep(path, depth = nil)
|
43
|
+
root = Pathname.new(Svn.working_copy_root_path(path)).realpath
|
44
|
+
end_path = Pathname.new(path.to_s).expand_path.realpath
|
45
|
+
parents = [end_path]
|
46
|
+
while parents.first != root
|
47
|
+
parents.unshift(parents.first.parent)
|
48
|
+
end
|
49
|
+
parents.each do |dir|
|
50
|
+
if dir.exist?
|
51
|
+
sys "svn update #{dir}"
|
52
|
+
else
|
53
|
+
sys "svn update #{depth ? "--set-depth #{depth}" : ""} #{dir}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def info(path = ".")
|
59
|
+
YAML.load(cap("svn info #{path}"))
|
60
|
+
end
|
61
|
+
|
62
|
+
def cat(path)
|
63
|
+
cap("svn cat #{path}")
|
64
|
+
end
|
65
|
+
|
66
|
+
def working_copy_root_path(path = ".")
|
67
|
+
info(path)["Working Copy Root Path"]
|
68
|
+
end
|
69
|
+
|
70
|
+
def base_uri_of(uris)
|
71
|
+
uris.reduce(Pathname.new(uris.first.to_s)) do |base_uri, uri|
|
72
|
+
rel = Pathname.new(uri).relative_path_from(base_uri)
|
73
|
+
to_parent = rel.to_s.match(/(?:\.\.\/)*/).to_s
|
74
|
+
to_parent.empty? ? base_uri : base_uri + to_parent
|
75
|
+
end.to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
def copy_single(transaction, message)
|
79
|
+
transactions = transaction.glob_transactions
|
80
|
+
raise "copy_single: #{transaction.from} not exists" if transactions.empty?
|
81
|
+
to_exist_transactions = Svn.list_files(transaction.to_base).select do |_file|
|
82
|
+
transactions.find {|_transaction| _transaction.file == _file}
|
83
|
+
end.compact
|
84
|
+
only_from_transactions = transactions - to_exist_transactions
|
85
|
+
if to_exist_transactions.empty? # toにファイルがない
|
86
|
+
sys "svn copy --parents #{only_from_transactions.map(&:from).join(' ')} #{transaction.to_base} -m '#{message}'"
|
87
|
+
else
|
88
|
+
Dir.mktmpdir do |dir|
|
89
|
+
sys "svn checkout --depth empty #{transaction.to_base} ."
|
90
|
+
sys "svn copy --parents #{only_from_transactions.map(&:from).join(' ')} ."
|
91
|
+
to_exist_transactions.each do |_transaction|
|
92
|
+
sys "svn update --set-depth infinity #{_transaction.file}"
|
93
|
+
sys "svn merge --accept theirs-full #{_transaction.from} #{_transaction.file}"
|
94
|
+
end
|
95
|
+
Svn.commit(message, ".")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def copy_multi(transactions, message)
|
101
|
+
base_uri = base_uri_of(transactions.map(&:from_base) + trnsactions.map(&:to_base))
|
102
|
+
transactions.each do |transaction|
|
103
|
+
raise "copy_multi: #{transaction.from} not exists" unless transaction.from_exist?
|
104
|
+
end
|
105
|
+
Dir.tmpdir do |dir|
|
106
|
+
sys "svn checkout --depth empty #{base_uri} ."
|
107
|
+
transactions.each do |transaction|
|
108
|
+
relative_to = transaction.relative_to(base_uri)
|
109
|
+
Svn.update_deep(relative_to, "empty") # mkpath的な なくてもエラーにはならないので
|
110
|
+
|
111
|
+
if transaction.to_exist? # toがある場合マージ
|
112
|
+
sys "svn merge --accept theirs-full #{transaction.from} #{relative_to}"
|
113
|
+
else # toがない場合コピー
|
114
|
+
sys "svn copy --parents #{transaction.from} #{relative_to}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
Svn.commit(message, ".")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def check_exists(transaction, raise_if_from_not_found = true)
|
122
|
+
unless transaction.from_exist?
|
123
|
+
if !raise_if_from_not_found
|
124
|
+
return
|
125
|
+
elsif transaction.to_exist?
|
126
|
+
puts "[WARNING] File:#{file}はコピー先のみにあります"
|
127
|
+
return
|
128
|
+
else
|
129
|
+
raise "[Error] File:#{file}が見つかりません!"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
extend ModuleMethods
|
136
|
+
end
|
137
|
+
|
138
|
+
class SvnFileCopyTransaction
|
139
|
+
attr_reader :from_base, :to_base, :file
|
140
|
+
|
141
|
+
def initialize(from_base:, to_base:, file:)
|
142
|
+
@from_base = from_base
|
143
|
+
@to_base = to_base
|
144
|
+
@file = file
|
145
|
+
end
|
146
|
+
|
147
|
+
def from
|
148
|
+
File.join(@from_base, @file)
|
149
|
+
end
|
150
|
+
|
151
|
+
def to
|
152
|
+
File.join(@to_base, @file)
|
153
|
+
end
|
154
|
+
|
155
|
+
def glob_transactions
|
156
|
+
Svn.list_files(@from_base)
|
157
|
+
.select{|_file| File.fnmatch(@file, _file)}
|
158
|
+
.map{|_file| SvnFileCopyTransaction.new(from_base: @from_base, to_base: @to_base, file: _file)}
|
159
|
+
end
|
160
|
+
|
161
|
+
def from_exist?
|
162
|
+
Svn.list_files(@from_base).find{|_file| File.fnmatch(@file, _file)}
|
163
|
+
end
|
164
|
+
|
165
|
+
def to_exist?
|
166
|
+
Svn.list_files(@to_base).find{|_file| File.fnmatch(@file, _file)}
|
167
|
+
end
|
168
|
+
|
169
|
+
def relative_from_base(path)
|
170
|
+
Pathname.new(@from_base).relative_path_from(Pathname.new(path)).to_s
|
171
|
+
end
|
172
|
+
|
173
|
+
def relative_to_base(path)
|
174
|
+
Pathname.new(@to_base).relative_path_from(Pathname.new(path)).to_s
|
175
|
+
end
|
176
|
+
|
177
|
+
def relative_from(path)
|
178
|
+
File.join(relative_from_base(path), @file)
|
179
|
+
end
|
180
|
+
|
181
|
+
def relative_to(path)
|
182
|
+
File.join(relative_from_to(path), @file)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -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 'svn_command_helper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "svn_command_helper"
|
8
|
+
spec.version = SvnCommandHelper::VERSION
|
9
|
+
spec.authors = ["Narazaka"]
|
10
|
+
spec.email = ["info@narazaka.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{svn command helper}
|
13
|
+
spec.description = %q{convenient svn commands}
|
14
|
+
spec.homepage = "https://github.com/SystemCommandHelperRB/svn_command_helper"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "system_command_helper"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "yard", "~> 0.8.7"
|
27
|
+
spec.add_development_dependency "simplecov", "~> 0.11"
|
28
|
+
spec.add_development_dependency "codecov", "~> 0.1"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: svn_command_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Narazaka
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: system_command_helper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
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: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.8.7
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.7
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.11'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.11'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.1'
|
111
|
+
description: convenient svn commands
|
112
|
+
email:
|
113
|
+
- info@narazaka.net
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- lib/svn_command_helper.rb
|
128
|
+
- lib/svn_command_helper/version.rb
|
129
|
+
- svn_command_helper.gemspec
|
130
|
+
homepage: https://github.com/SystemCommandHelperRB/svn_command_helper
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.4.5.1
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: svn command helper
|
154
|
+
test_files: []
|
155
|
+
has_rdoc:
|