svn_tools 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/svntools +145 -0
- data/init.rb +1 -0
- data/lib/svn_tools.rb +115 -0
- data/lib/tasks/rubyforge_config.yml +5 -0
- metadata +52 -0
data/bin/svntools
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'optparse'
|
3
|
+
require 'optparse/time'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'pp'
|
6
|
+
require 'find'
|
7
|
+
|
8
|
+
class SvnTools
|
9
|
+
|
10
|
+
def self.available_apps
|
11
|
+
[:lock, :unlock, :show_branches_and_revisions, :export_branches]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.lock(options)
|
15
|
+
lock_or_unlock("lock", options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.unlock(options)
|
19
|
+
lock_or_unlock("unlock", options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.show_branches_and_revisions(options)
|
23
|
+
branches, svn_base_url = get_branches
|
24
|
+
branches.each do |branch|
|
25
|
+
puts "Branch #{branch[0]} revision #{branch[1]} url #{svn_base_url}/branches/#{branch[0]}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.export_branches(options)
|
30
|
+
branch_names_list = options.branch_names
|
31
|
+
base_export_directory = options.base_export_directory
|
32
|
+
unless File.exists?(base_export_directory)
|
33
|
+
`mkdir -p #{base_export_directory}`
|
34
|
+
end
|
35
|
+
branches_to_export = branch_names_list.split(',').collect {|branch_name| branch_name.strip.downcase }
|
36
|
+
branches, svn_base_url = get_branches
|
37
|
+
branches.each do |branch_info|
|
38
|
+
branch = branch_info[0]
|
39
|
+
if branch_names_list == '' or branches_to_export.include?(branch)
|
40
|
+
export_directory = "#{base_export_directory}/#{branch}"
|
41
|
+
branch_url = "#{svn_base_url}/branches/#{branch}"
|
42
|
+
svn_cmd = "svn export #{branch_url} #{export_directory}"
|
43
|
+
puts svn_cmd
|
44
|
+
result = `#{svn_cmd}`
|
45
|
+
if options.show_output == 'true'
|
46
|
+
puts result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def self.lock_or_unlock(com, options)
|
55
|
+
Find.find(FileUtils.pwd) do |f|
|
56
|
+
if FileTest.directory?(f) and f =~ /\.svn/
|
57
|
+
Find.prune
|
58
|
+
else
|
59
|
+
if FileTest.file?(f)
|
60
|
+
puts `svn #{com} #{f}`
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def self.get_branches
|
68
|
+
svn_base_url = `svn info | grep URL`.gsub(/URL\:/,'').gsub(/\/trunk/,'').strip
|
69
|
+
all_revs = []
|
70
|
+
all_branches = `svn list #{svn_base_url}/branches`.split("\n")
|
71
|
+
all_branches.each do |branch|
|
72
|
+
unless branch =~ /test/
|
73
|
+
branch.strip!
|
74
|
+
branch = branch[0..-2]
|
75
|
+
all_lines = `svn log --stop-on-copy #{svn_base_url}/branches/#{branch}`.split("\n").reverse
|
76
|
+
all_lines.pop
|
77
|
+
rev_line = nil
|
78
|
+
all_lines.each do |one_line|
|
79
|
+
if one_line =~ /^r[\d]+\s/
|
80
|
+
rev_line = one_line
|
81
|
+
revision = one_line[1..one_line.index(/\s/)].to_i
|
82
|
+
all_revs << [branch, revision]
|
83
|
+
break
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
return [all_revs, svn_base_url]
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
class SvnToolsError < Exception
|
94
|
+
|
95
|
+
def initialize
|
96
|
+
err = %{
|
97
|
+
Available tools are:
|
98
|
+
#{SvnTools.available_apps.join("\n")}
|
99
|
+
|
100
|
+
To use any of these tools simply type:
|
101
|
+
svntools <toolname> # example: svntools lock
|
102
|
+
|
103
|
+
export_branches (options):
|
104
|
+
-v # This will set the show_output flag to true.
|
105
|
+
-n # This will allow you to set a list of branch names.
|
106
|
+
-e # This will set the base export directory.
|
107
|
+
|
108
|
+
}
|
109
|
+
puts err
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
app = ARGV[0]
|
115
|
+
|
116
|
+
raise SvnToolsError.new if app.nil?
|
117
|
+
|
118
|
+
options = OpenStruct.new
|
119
|
+
options.show_output = false
|
120
|
+
options.branch_names = ''
|
121
|
+
options.base_export_directory = '../branches'
|
122
|
+
|
123
|
+
opts = OptionParser.new do |opts|
|
124
|
+
|
125
|
+
opts.on("-v") do
|
126
|
+
options.show_output = true
|
127
|
+
end
|
128
|
+
|
129
|
+
opts.on("-n [BRANCH_NAMES]") do |v|
|
130
|
+
options.branch_names = v
|
131
|
+
end
|
132
|
+
|
133
|
+
opts.on("-e [BASE_EXPORT_DIRECTORY]") do |v|
|
134
|
+
options.base_export_directory = v
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
opts.parse!(ARGV)
|
140
|
+
|
141
|
+
begin
|
142
|
+
SvnTools.send(app, options)
|
143
|
+
rescue => e
|
144
|
+
raise SvnToolsError.new
|
145
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#require 'svn_tools'
|
data/lib/svn_tools.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
class SvnTools
|
2
|
+
|
3
|
+
def self.lock_or_unlock(com)
|
4
|
+
Find.find(FileUtils.pwd) do |f|
|
5
|
+
if FileTest.directory?(f) and f =~ /\.svn/
|
6
|
+
Find.prune
|
7
|
+
else
|
8
|
+
if FileTest.file?(f)
|
9
|
+
puts `svn #{com} #{f}`
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
# class SubversionRakeUtils
|
18
|
+
#
|
19
|
+
# def self.get_branches
|
20
|
+
# svn_base_url = `svn info | grep URL`.gsub(/URL\:/,'').gsub(/\/trunk/,'').strip
|
21
|
+
# all_revs = []
|
22
|
+
# all_branches = `svn list #{svn_base_url}/branches`.split("\n")
|
23
|
+
# all_branches.each do |branch|
|
24
|
+
# unless branch =~ /test/
|
25
|
+
# branch.strip!
|
26
|
+
# branch = branch[0..-2]
|
27
|
+
# all_lines = `svn log --stop-on-copy #{svn_base_url}/branches/#{branch}`.split("\n").reverse
|
28
|
+
# all_lines.pop
|
29
|
+
# rev_line = nil
|
30
|
+
# all_lines.each do |one_line|
|
31
|
+
# if one_line =~ /^r[\d]+\s/
|
32
|
+
# rev_line = one_line
|
33
|
+
# revision = one_line[1..one_line.index(/\s/)].to_i
|
34
|
+
# all_revs << [branch, revision]
|
35
|
+
# break
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
# return [all_revs, svn_base_url]
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# require 'find'
|
46
|
+
# require 'fileutils'
|
47
|
+
# namespace :h do
|
48
|
+
#
|
49
|
+
# namespace :subversion do
|
50
|
+
#
|
51
|
+
# desc "Show branches and associated revisions"
|
52
|
+
# task :show_branches_and_revisions => :environment do |t|
|
53
|
+
#
|
54
|
+
# branches, svn_base_url = SubversionRakeUtils.get_branches
|
55
|
+
# branches.each do |branch|
|
56
|
+
# puts "Branch #{branch[0]} revision #{branch[1]} url #{svn_base_url}/branches/#{branch[0]}"
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
#
|
62
|
+
# desc "Export branches"
|
63
|
+
# task :export_branches => :environment do |t|
|
64
|
+
# show_output = ENV['SHOW_OUTPUT'] || 'false'
|
65
|
+
# branch_names_list = ENV['BRANCH_NAMES'] || ''
|
66
|
+
# base_export_directory = ENV['BASE_EXPORT_DIRECTORY'] || '../branches'
|
67
|
+
# unless File.exists?(base_export_directory)
|
68
|
+
# `mkdir -p #{base_export_directory}`
|
69
|
+
# end
|
70
|
+
# branches_to_export = branch_names_list.split(',').collect {|branch_name| branch_name.strip.downcase }
|
71
|
+
# branches, svn_base_url = SubversionRakeUtils.get_branches
|
72
|
+
# branches.each do |branch_info|
|
73
|
+
# branch = branch_info[0]
|
74
|
+
# if branch_names_list == '' or branches_to_export.include?(branch)
|
75
|
+
# export_directory = "#{base_export_directory}/#{branch}"
|
76
|
+
# branch_url = "#{svn_base_url}/branches/#{branch}"
|
77
|
+
# svn_cmd = "svn export #{branch_url} #{export_directory}"
|
78
|
+
# puts svn_cmd
|
79
|
+
# result = `#{svn_cmd}`
|
80
|
+
# if show_output == 'true'
|
81
|
+
# puts result
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# task :lock do |t|
|
89
|
+
# Find.find(FileUtils.pwd) do |f|
|
90
|
+
# if FileTest.directory?(f) and f =~ /\.svn/
|
91
|
+
# Find.prune
|
92
|
+
# else
|
93
|
+
# if FileTest.file?(f)
|
94
|
+
# puts `svn lock #{f}`
|
95
|
+
# end
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# task :unlock do |t|
|
101
|
+
# Find.find(FileUtils.pwd) do |f|
|
102
|
+
# if FileTest.directory?(f) and f =~ /\.svn/
|
103
|
+
# Find.prune
|
104
|
+
# else
|
105
|
+
# if FileTest.file?(f)
|
106
|
+
# puts `svn unlock #{f}`
|
107
|
+
# end
|
108
|
+
# end
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# end
|
115
|
+
#
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: svn_tools
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2007-11-07 00:00:00 -05:00
|
8
|
+
summary: svn_tools
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- lib
|
12
|
+
- lib
|
13
|
+
- lib/tasks
|
14
|
+
email:
|
15
|
+
homepage:
|
16
|
+
rubyforge_project: magrathea
|
17
|
+
description: "svn_tools was developed by: markbates"
|
18
|
+
autorequire:
|
19
|
+
- svn_tools
|
20
|
+
default_executable:
|
21
|
+
bindir: bin
|
22
|
+
has_rdoc: false
|
23
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.0.0
|
28
|
+
version:
|
29
|
+
platform: ruby
|
30
|
+
signing_key:
|
31
|
+
cert_chain:
|
32
|
+
post_install_message:
|
33
|
+
authors:
|
34
|
+
- markbates
|
35
|
+
files:
|
36
|
+
- init.rb
|
37
|
+
- lib/svn_tools.rb
|
38
|
+
- lib/tasks/rubyforge_config.yml
|
39
|
+
test_files: []
|
40
|
+
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
executables:
|
46
|
+
- svntools
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies: []
|
52
|
+
|