svnauto 1.0.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.
@@ -0,0 +1,68 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2006 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module SC
26
+ ################################################################################
27
+ class Create < Command
28
+ ################################################################################
29
+ set(:name, :create)
30
+ set(:description, "Create a new project in the repository")
31
+ set(:without_project)
32
+ set(:usage, "[options] project-name")
33
+ set(:args_min, 1)
34
+ set(:args_max, 1)
35
+
36
+ option('-C', '--no-checkout', "Don't checkout the new project") do |val, opthash|
37
+ opthash[:no_checkout] = true
38
+ end
39
+
40
+ ################################################################################
41
+ def run (project, args)
42
+ project.name = Project.clean_name(args.first)
43
+
44
+ unless opthash[:force]
45
+ if project.name != args.first and !Constants::TERMINAL.agree("Is #{project.name} OK for the project name? ")
46
+ raise "please pick a project name that doesn't contain any special characters"
47
+ end
48
+
49
+ exit unless Constants::TERMINAL.agree("Create project " +
50
+ Constants::TERMINAL.color(project.name, :green) + " in " +
51
+ Constants::TERMINAL.color(project.repository, :blue) + "? ")
52
+ end
53
+
54
+ if project.name != args.first
55
+ Constants::TERMINAL.say("using #{Constants::TERMINAL.color(project.name, :green)}) for the project name")
56
+ end
57
+
58
+ project.create
59
+
60
+ unless opthash[:no_checkout]
61
+ Constants::TERMINAL.say("Checked out to: #{Constants::TERMINAL.color(Path.relative_to_home(project.checkout), :green)}")
62
+ end
63
+ end
64
+
65
+ end
66
+ ################################################################################
67
+ end
68
+ ################################################################################
@@ -0,0 +1,142 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2006 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module SC
26
+ ################################################################################
27
+ class Experimental < Command
28
+ ################################################################################
29
+ set(:name, :experimental)
30
+ set(:description, "Work with experimental branches off the trunk")
31
+ set(:usage, "[options] branch-name")
32
+ set(:args_min, 1)
33
+ set(:args_max, 1)
34
+
35
+ option('-p', '--prefix PATH', 'Use branch prefix PATH instead of exp') do |val, opts|
36
+ opts[:prefix] = val
37
+ end
38
+
39
+ option('-u', '--up', 'Merge the trunk up onto this experimental branch') do |val, opts|
40
+ opts[:up] = true
41
+ end
42
+
43
+ option('-d', '--down', 'Merge this experimental branch down to the trunk') do |val, opts|
44
+ opts[:down] = true
45
+ end
46
+
47
+ option('-C', '--no-checkout', "Don't checkout the new project") do |val, opthash|
48
+ opthash[:no_checkout] = true
49
+ end
50
+
51
+ ################################################################################
52
+ def run (project, args)
53
+ if opthash[:up] and opthash[:down]
54
+ raise "you can only use one of --up or --down"
55
+ end
56
+
57
+ @branch_name = Project.clean_name(args.first)
58
+
59
+ unless opthash[:force]
60
+ if @branch_name != args.first and !Constants::TERMINAL.agree("Is #{@branch_name} OK for the branch name? ")
61
+ raise "please pick a branch name that doesn't include any special characters"
62
+ end
63
+ end
64
+
65
+ if @branch_name != args.first
66
+ Constants::TERMINAL.say("using #{Constants::TERMINAL.color(@branch_name, :green)} as the branch name")
67
+ end
68
+
69
+ @project = project
70
+ @prefix = opthash[:prefix] || 'exp'
71
+ @path = "#{@prefix}/#{@branch_name}"
72
+ @has_path = Svn.has_path(@project.branches(@path))
73
+
74
+ if opthash[:up]
75
+ merge('UP', @project.branches(@path), @project.trunk)
76
+ elsif opthash[:down]
77
+ merge('DOWN', @project.trunk, @project.branches(@path))
78
+ else
79
+ create_experimental_branch
80
+ end
81
+ end
82
+
83
+ ################################################################################
84
+ def create_experimental_branch
85
+ raise "branch #@path already exists" if @has_path
86
+
87
+ unless opthash[:force]
88
+ name = @branch_name
89
+ name = @path if @prefix != 'exp'
90
+
91
+ exit unless Constants::TERMINAL.agree("Create experimental branch " +
92
+ Constants::TERMINAL.color(name, :green) + " off " +
93
+ Constants::TERMINAL.color(@project.to_s, :green) + "/trunk? ")
94
+ end
95
+
96
+ Svn.branch(@project, @project.trunk, @project.branches(@path))
97
+ Svn.branch(@project, @project.branches(@path), @project.tags("#{@prefix}/PRE-#{@branch_name}"))
98
+
99
+ unless opthash[:no_checkout]
100
+ Constants::TERMINAL.say("Checked out: " +
101
+ Constants::TERMINAL.color(Path.relative_to_home(@project.checkout(@project.branches(@path))), :green))
102
+ end
103
+ end
104
+
105
+ ################################################################################
106
+ def merge (direction, merge_to, end_tag)
107
+ raise "there is no experimental branch with the name #{@branch_name}" unless @has_path
108
+
109
+ last_merge_number = latest_merge(direction)
110
+ start = last_merge_number ? "#{direction}#{last_merge_number}" : "PRE"
111
+ next_merge_number = last_merge_number ? last_merge_number+1 : 1
112
+
113
+ start_tag = "#{@prefix}/#{start}-#{@branch_name}"
114
+
115
+ # tag the current merge point for our next merge
116
+ Svn.branch(@project, end_tag, @project.tags("#{@prefix}/#{direction}#{next_merge_number}-#{@branch_name}"))
117
+
118
+ # merge the trunk to the branch
119
+ @project.merge(merge_to, start_tag, end_tag) do
120
+ "then commit your changes to finish the #{direction} merge"
121
+ end
122
+ end
123
+
124
+ ################################################################################
125
+ def latest_merge (prefix)
126
+ merges = []
127
+
128
+ Svn.list(@project.tags(@prefix)) do |line|
129
+ if m = line.match(/^#{prefix}(\d+)-#{@branch_name}\/?$/)
130
+ merges << m[1].to_i
131
+ end
132
+ end
133
+
134
+ merges.sort.last
135
+ end
136
+
137
+ end
138
+ ################################################################################
139
+ end
140
+ ################################################################################
141
+
142
+
@@ -0,0 +1,54 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2006 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module SC
26
+ ################################################################################
27
+ class Info < Command
28
+ set(:name, :info)
29
+ set(:description, "Show information about a project")
30
+
31
+ def run (project, args)
32
+ if URI.parse(project.repository.url).scheme != 'file'
33
+ puts "Getting project info from #{project.repository} ..."
34
+ $stdout.flush
35
+ end
36
+
37
+ unless Svn.has_path(project.trunk)
38
+ raise "there's no #{project} project in #{project.repository}"
39
+ end
40
+
41
+ rel_branch = project.latest_release_branch
42
+ rel_tag = project.latest_release_tag(rel_branch) if rel_branch
43
+
44
+ puts "=============================================================================="
45
+ puts " Trunk: #{project.trunk}"
46
+ puts " Latest Release Branch: #{rel_branch || "no major.minor releases yet"}"
47
+ puts " Latest Release Tag: #{rel_tag || "no macro releases yet"}"
48
+ puts " Repository Workspace: #{project.repository.workspace}"
49
+ puts "=============================================================================="
50
+ end
51
+ end
52
+ ################################################################################
53
+ end
54
+ ################################################################################
@@ -0,0 +1,40 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2006 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module SC
26
+ ################################################################################
27
+ class List < Command
28
+ ################################################################################
29
+ set(:name, [:list, :ls])
30
+ set(:description, "List directory contents, projects, releases, etc.")
31
+ set(:without_project)
32
+
33
+ ################################################################################
34
+ def run (project, args)
35
+ Svn.list("#{project.repository.url}/#{args.join('/')}")
36
+ end
37
+ end
38
+ ################################################################################
39
+ end
40
+ ################################################################################
@@ -0,0 +1,98 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2006 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ module SC
26
+ ################################################################################
27
+ class Release < Command
28
+ set(:name, :release)
29
+ set(:description, "Create a release branch (major.minor), or tag a release (macro)")
30
+ set(:usage, "[options] major.minor[.macro]")
31
+ set(:args_min, 1)
32
+ set(:args_max, 1)
33
+
34
+ option('-C', '--no-checkout', "Don't checkout the rel branch") do |val, opts|
35
+ opts[:no_checkout] = true
36
+ end
37
+
38
+ ################################################################################
39
+ def run (project, args)
40
+ @version = Version.new(args.first)
41
+ @project = project
42
+ @has_branch = Svn.has_path(@project.branches("rel/#{@version.major_minor}"))
43
+
44
+ if @has_branch and @version.macro.nil?
45
+ raise "release branch #{@version} already exists, you can tag it by giving a MACRO version"
46
+ end
47
+
48
+ @has_branch ? tag_release_branch : make_release_branch
49
+ end
50
+
51
+ ################################################################################
52
+ def make_release_branch
53
+ unless opthash[:force]
54
+ question = "Create " + Constants::TERMINAL.color(@project.to_s, :green)
55
+ question << " release branch " + Constants::TERMINAL.color(@version.major_minor, :red) + "? "
56
+ exit unless Constants::TERMINAL.agree(question)
57
+ end
58
+
59
+ Svn.branch(@project, @project.trunk, @project.branches("rel/#{@version.major_minor}"))
60
+
61
+ if @version.macro.nil?
62
+ question = "Tag release branch as "
63
+ question << Constants::TERMINAL.color(@version.to_s + '.0', :red) + "? "
64
+
65
+ if opthash[:force] or Constants::TERMINAL.agree(question)
66
+ @version.macro = 0
67
+ end
68
+ end
69
+
70
+ tag_release_branch unless @version.macro.nil?
71
+
72
+ unless opthash[:no_checkout]
73
+ Constants::TERMINAL.say("Checked out to: " +
74
+ Constants::TERMINAL.color(Path.relative_to_home(
75
+ @project.checkout(@project.branches("rel/#{@version.major_minor}"))), :green))
76
+ end
77
+ end
78
+
79
+ ################################################################################
80
+ def tag_release_branch
81
+ if @version.macro.nil?
82
+ raise "Woah, a bad version number was passed to me!"
83
+ end
84
+
85
+ if Svn.has_path(@project.tags("rel/#{@version}"))
86
+ raise "a release tag already exists for version #{@version}"
87
+ end
88
+
89
+ Constants::TERMINAL.say("Creating #{Constants::TERMINAL.color(@version.to_s, :red)} release tag for " +
90
+ Constants::TERMINAL.color(@project.to_s, :green))
91
+
92
+ Svn.branch(@project, @project.branches("rel/#{@version.major_minor}"), @project.tags("rel/#{@version}"))
93
+ end
94
+
95
+ end
96
+ ################################################################################
97
+ end
98
+ ################################################################################
@@ -0,0 +1,87 @@
1
+ ################################################################################
2
+ #
3
+ # Copyright (C) 2006 Peter J Jones (pjones@pmade.com)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ ################################################################################
25
+ require 'yaml'
26
+ ################################################################################
27
+ module SC
28
+ ################################################################################
29
+ class ConfigFile
30
+ ################################################################################
31
+ ENV_OVERRIDE = 'SC_CONFIG_FILE'
32
+ FILENAME = File.join(ENV['HOME'], '.sc')
33
+
34
+ ################################################################################
35
+ # load in the user's configuration file
36
+ def initialize
37
+ @file_name = ENV[ENV_OVERRIDE] ? ENV[ENV_OVERRIDE] : FILENAME
38
+
39
+ @config =
40
+ if File.exists?(@file_name)
41
+ File.open(@file_name) {|file| YAML.load(file)}
42
+ end
43
+
44
+ @config = Hash.new unless @config.is_a?(Hash)
45
+ @config[:repositories] ||= Array.new
46
+ @config[:color] = false unless @config.has_key?(:color)
47
+ end
48
+
49
+ ################################################################################
50
+ # locate a repository by it's name
51
+ def find_repository (name)
52
+ @config[:repositories].find {|r| r.name == name}
53
+ end
54
+
55
+ ################################################################################
56
+ # prompt the user to choose a repository
57
+ def prompt_for_repository
58
+ if @config[:repositories].empty?
59
+ raise "you don't have any repositories defined, use 'config --add'"
60
+ end
61
+
62
+ Constants::TERMINAL.choose do |menu|
63
+ menu.header = "Repositories"
64
+ menu.prompt = "Please choose a repository: "
65
+
66
+ @config[:repositories].each do |rep|
67
+ menu.choice(rep.to_s) {rep}
68
+ end
69
+ end
70
+ end
71
+ ################################################################################
72
+ # save the configuration file
73
+ def save
74
+ File.open(@file_name, "w") do |file|
75
+ YAML.dump(@config, file)
76
+ end
77
+ end
78
+
79
+ ################################################################################
80
+ # helper methods
81
+ def [] (name) @config[name] end
82
+ def []= (name, value) @config[name] = value end
83
+
84
+ end
85
+ ################################################################################
86
+ end
87
+ ################################################################################