Module: SvnCommandHelper::Svn::ModuleMethods
- Includes:
- SystemCommandHelper
- Included in:
- SvnCommandHelper::Svn
- Defined in:
- lib/svn_command_helper.rb
Overview
module methods
Instance Method Summary collapse
-
#base_uri_of(uris) ⇒ String
find common part of the given uris.
-
#cat(path) ⇒ String
svn cat.
-
#check_exists(transaction, raise_if_from_not_found = true) ⇒ Boolean
check transaction from file exists.
-
#commit(message, path = ".") ⇒ Object
svn commit.
-
#copy_multi(transactions, message) ⇒ Object
copy multi transactions.
-
#copy_single(transaction, message) ⇒ Object
copy single transaction.
-
#exist?(uri) ⇒ Boolean
check svn uri exists or not.
-
#exist_file?(uri) ⇒ Boolean
check svn uri file exists or not.
-
#info(path = ".") ⇒ Hash<String, String>
svn info -> yaml parse.
-
#list(uri, recursive = false) ⇒ Array<String>
svn list.
-
#list_files(uri, recursive = false) ⇒ Array<String>
svn list -> grep only files.
-
#list_files_recursive(uri) ⇒ Array<String>
svn list –recursive -> grep only files.
-
#list_recursive(uri) ⇒ Array<String>
svn list –recursive.
-
#update(path = ".", depth = nil) ⇒ Object
svn update.
-
#update_deep(path, depth = nil) ⇒ Object
svn update to deep path recursive.
-
#working_copy_root_path(path = ".") ⇒ String
Working Copy Root Path from svn info.
Instance Method Details
#base_uri_of(uris) ⇒ String
find common part of the given uris
124 125 126 127 128 129 130 |
# File 'lib/svn_command_helper.rb', line 124 def base_uri_of(uris) uris.reduce(Pathname.new(uris.first.to_s)) do |base_uri, uri| rel = Pathname.new(uri).relative_path_from(base_uri) to_parent = rel.to_s.match(/(?:\.\.\/)*/).to_s to_parent.empty? ? base_uri : base_uri + to_parent end.to_s end |
#cat(path) ⇒ String
svn cat
110 111 112 |
# File 'lib/svn_command_helper.rb', line 110 def cat(path) cap("svn cat #{path}") end |
#check_exists(transaction, raise_if_from_not_found = true) ⇒ Boolean
check transaction from file exists
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/svn_command_helper.rb', line 185 def check_exists(transaction, raise_if_from_not_found = true) unless transaction.from_exist? if !raise_if_from_not_found false elsif transaction.to_exist? puts "[WARNING] File:#{file}はコピー先のみにあります" false else raise "[Error] File:#{file}が見つかりません!" end else true end end |
#commit(message, path = ".") ⇒ Object
svn commit
17 18 19 20 21 22 23 24 25 |
# File 'lib/svn_command_helper.rb', line 17 def commit(, path = ".") if cap("svn status #{path}").empty? sys "svn revert -R #{path}" puts "[WARNING] no change: #{}" else sys "svn commit -m '#{}' #{path}" end sys "svn update #{path}" end |
#copy_multi(transactions, message) ⇒ Object
copy multi transactions
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/svn_command_helper.rb', line 160 def copy_multi(transactions, ) base_uri = base_uri_of(transactions.map(&:from_base) + trnsactions.map(&:to_base)) transactions.each do |transaction| raise "copy_multi: #{transaction.from} not exists" unless transaction.from_exist? end Dir.tmpdir do |dir| sys "svn checkout --depth empty #{base_uri} ." transactions.each do |transaction| relative_to = transaction.relative_to(base_uri) Svn.update_deep(relative_to, "empty") # mkpath的な なくてもエラーにはならないので if transaction.to_exist? # toがある場合マージ sys "svn merge --accept theirs-full #{transaction.from} #{relative_to}" else # toがない場合コピー sys "svn copy --parents #{transaction.from} #{relative_to}" end end Svn.commit(, ".") end end |
#copy_single(transaction, message) ⇒ Object
copy single transaction
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/svn_command_helper.rb', line 135 def copy_single(transaction, ) transactions = transaction.glob_transactions raise "copy_single: #{transaction.from} not exists" if transactions.empty? to_exist_transactions = Svn.list_files(transaction.to_base).select do |_file| transactions.find {|_transaction| _transaction.file == _file} end.compact only_from_transactions = transactions - to_exist_transactions if to_exist_transactions.empty? # toにファイルがない sys "svn copy --parents #{only_from_transactions.map(&:from).join(' ')} #{transaction.to_base} -m '#{}'" else Dir.mktmpdir do |dir| sys "svn checkout --depth empty #{transaction.to_base} ." sys "svn copy --parents #{only_from_transactions.map(&:from).join(' ')} ." to_exist_transactions.each do |_transaction| sys "svn update --set-depth infinity #{_transaction.file}" sys "svn merge --accept theirs-full #{_transaction.from} #{_transaction.file}" end Svn.commit(, ".") end end end |
#exist?(uri) ⇒ Boolean
check svn uri exists or not
61 62 63 64 |
# File 'lib/svn_command_helper.rb', line 61 def exist?(uri) basename = File.basename(uri) list(File.dirname(uri)).find{|_basename| File.fnmatch(basename, _basename.sub(/\/$/, ''))} end |
#exist_file?(uri) ⇒ Boolean
check svn uri file exists or not
69 70 71 72 |
# File 'lib/svn_command_helper.rb', line 69 def exist_file?(uri) file = File.basename(uri) list_files(File.dirname(uri)).find{|_file| File.fnmatch(file, _file)} end |
#info(path = ".") ⇒ Hash<String, String>
svn info -> yaml parse
103 104 105 |
# File 'lib/svn_command_helper.rb', line 103 def info(path = ".") YAML.load(cap("svn info #{path}")) end |
#list(uri, recursive = false) ⇒ Array<String>
svn list
31 32 33 34 |
# File 'lib/svn_command_helper.rb', line 31 def list(uri, recursive = false) cap("svn list #{recursive ? '-R' : ''} #{uri}").split(/\n/).compact .reject {|path| path.empty?} end |
#list_files(uri, recursive = false) ⇒ Array<String>
svn list -> grep only files
47 48 49 |
# File 'lib/svn_command_helper.rb', line 47 def list_files(uri, recursive = false) list(uri, recursive).reject {|path| path.end_with?("/")} # dir end |
#list_files_recursive(uri) ⇒ Array<String>
svn list –recursive -> grep only files
54 55 56 |
# File 'lib/svn_command_helper.rb', line 54 def list_files_recursive(uri) list_files(uri, true) end |
#list_recursive(uri) ⇒ Array<String>
svn list –recursive
39 40 41 |
# File 'lib/svn_command_helper.rb', line 39 def list_recursive(uri) list(uri, true) end |
#update(path = ".", depth = nil) ⇒ Object
svn update
77 78 79 |
# File 'lib/svn_command_helper.rb', line 77 def update(path = ".", depth = nil) sys "svn update #{depth ? "--set-depth #{depth}" : ""} #{path}" end |
#update_deep(path, depth = nil) ⇒ Object
svn update to deep path recursive
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/svn_command_helper.rb', line 84 def update_deep(path, depth = nil) root = Pathname.new(Svn.working_copy_root_path(path)).realpath end_path = Pathname.new(path.to_s)..realpath parents = [end_path] while parents.first != root parents.unshift(parents.first.parent) end parents.each do |dir| if dir.exist? sys "svn update #{dir}" else sys "svn update #{depth ? "--set-depth #{depth}" : ""} #{dir}" end end end |
#working_copy_root_path(path = ".") ⇒ String
Working Copy Root Path from svn info
117 118 119 |
# File 'lib/svn_command_helper.rb', line 117 def working_copy_root_path(path = ".") info(path)["Working Copy Root Path"] end |