svnauto 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
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 'rubygems'
26
+ require 'highline'
27
+ require 'uri'
28
+ ################################################################################
29
+ require 'sc/constants'
30
+ require 'sc/version'
31
+ require 'sc/config_file'
32
+ require 'sc/svn'
33
+ require 'sc/path'
34
+ require 'sc/project'
35
+ require 'sc/repository'
36
+ require 'sc/command'
37
+ require 'sc/dispatcher'
38
+ ################################################################################
@@ -0,0 +1,118 @@
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 'optparse'
26
+ require 'set'
27
+ ################################################################################
28
+ module SC
29
+ ################################################################################
30
+ class Command
31
+ ################################################################################
32
+ VALID_SET_KEYS = Set.new([
33
+ :name,
34
+ :description,
35
+ :without_project,
36
+ :without_repository,
37
+ :usage,
38
+ :args_min,
39
+ :args_max,
40
+ ])
41
+
42
+ ################################################################################
43
+ def self.inherited (klass)
44
+ klass.instance_eval do
45
+ @options = OptionParser.new
46
+ @opthash ||= {}
47
+ @attributes = {}
48
+ end
49
+
50
+ instance_eval do
51
+ (@commands ||= []) << klass
52
+ end
53
+
54
+ klass.option('-f', '--force', "Don't display any confirmation prompts") do |val, opthash|
55
+ opthash[:force] = true
56
+ end
57
+ end
58
+
59
+ ################################################################################
60
+ def self.commands
61
+ instance_eval { @commands }
62
+ end
63
+
64
+ ################################################################################
65
+ def self.options
66
+ instance_eval { @options }
67
+ end
68
+
69
+ ################################################################################
70
+ class << self
71
+ VALID_SET_KEYS.each do |method|
72
+ define_method(method, lambda {instance_eval{@attributes[method]}})
73
+ end
74
+ end
75
+
76
+ ################################################################################
77
+ # reset to a good state, mostly for testing, since commands get run over
78
+ # and over
79
+ def self.reset!
80
+ instance_eval { @opthash.clear }
81
+ end
82
+
83
+ ################################################################################
84
+ protected
85
+
86
+ ################################################################################
87
+ def self.option (*args, &block)
88
+ instance_eval do
89
+ @options.on(*args) do |option|
90
+ block.call(option, @opthash)
91
+ end
92
+ end
93
+ end
94
+
95
+ ################################################################################
96
+ def self.set (name, value=true)
97
+ unless VALID_SET_KEYS.include?(name)
98
+ raise "invalid set key #{name}, wanted one of #{VALID_SET_KEYS.join(', ')}"
99
+ end
100
+
101
+ instance_eval { @attributes[name] = value }
102
+ end
103
+
104
+ ################################################################################
105
+ def opthash
106
+ self.class.instance_eval { @opthash }
107
+ end
108
+
109
+ end
110
+ ################################################################################
111
+ end
112
+
113
+ ################################################################################
114
+ # load all commands
115
+ Dir.foreach(File.join(File.dirname(__FILE__), 'commands')) do |file|
116
+ next unless file.match(/\.rb$/)
117
+ require 'sc/commands/' + file
118
+ end
@@ -0,0 +1,161 @@
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 Bug < Command
28
+ ################################################################################
29
+ REL_BRN_PROP = 'sc:bug-fix-release-branch'
30
+
31
+ ################################################################################
32
+ set(:name, :bug)
33
+ set(:description, "Work with release branch bug fixes")
34
+ set(:usage, "[options] unique-bug-id")
35
+ set(:args_min, 1)
36
+ set(:args_max, 1)
37
+
38
+ option('-r', '--release VER', "Create branch off VER rel branch instead of latest rel") do |val, opthash|
39
+ opthash[:release] = val
40
+ end
41
+
42
+ option('-c', '--close', "Close the bug fix branch") do |val, opthash|
43
+ opthash[:close] = true
44
+ end
45
+
46
+ option('-t', '--no-trunk', "Don't merge bug fix to the trunk") do |val, opthash|
47
+ opthash[:no_trunk] = true
48
+ end
49
+
50
+ ################################################################################
51
+ def run (project, args)
52
+ @project = project
53
+ @bug_id = args.first
54
+
55
+ unless @bug_id.match(/^\d+/)
56
+ raise "bug id should be an integer: #{@bug_id}"
57
+ end
58
+
59
+ @version =
60
+ if opthash[:release]
61
+ Version.new(opthash[:release])
62
+ else
63
+ project.latest_release_branch
64
+ end
65
+
66
+ opthash[:close] ? close_bug : create_bug_fix_branch
67
+ end
68
+
69
+ ################################################################################
70
+ def create_bug_fix_branch
71
+ if @version.nil?
72
+ raise "there are no release branches for the #{@project} project"
73
+ end
74
+
75
+ unless Svn.has_path(@project.release(@version))
76
+ raise "there is no release branch for version #@version"
77
+ end
78
+
79
+ unless opthash[:force]
80
+ exit unless Constants::TERMINAL.agree("Create bug fix branch for bug " +
81
+ Constants::TERMINAL.color(@bug_id, :red) + " off release " +
82
+ Constants::TERMINAL.color(@project.to_s, :green) + "/" +
83
+ Constants::TERMINAL.color(@version.to_s, :red) + "? ")
84
+ end
85
+
86
+ # create the bug fix branch
87
+ Svn.branch(@project, @project.release(@version), @project.branches("bug/#@bug_id"))
88
+
89
+ # tag the start of the branch for merging later
90
+ Svn.branch(@project, @project.branches("bug/#@bug_id"), @project.tags("bug/PRE-#@bug_id"))
91
+
92
+ # check it out so that we can do the next step
93
+ dir = @project.checkout(@project.branches("bug/#@bug_id"))
94
+
95
+ # record the release branch so we can get back to it later
96
+ Svn.propset(REL_BRN_PROP, @version.to_s, dir) {|line|}
97
+ Svn.commit('-m', "'#{Constants::ME}: recording release branch for bug fix #@bug_id'", dir)
98
+
99
+ Constants::TERMINAL.say("Created bug fix branch and checked out to: " +
100
+ Constants::TERMINAL.color(Path.relative_to_home(dir), :green))
101
+ end
102
+
103
+ ################################################################################
104
+ def close_bug
105
+ unless Svn.has_path(@project.branches("bug/#@bug_id"))
106
+ raise "there isn't a bug fix branch for bug #@bug_id"
107
+ end
108
+
109
+ if Svn.has_path(@project.tags("bug/POST-#@bug_id"))
110
+ Constants::TERMINAL.say("bug #{Constants::TERMINAL.color(@bug_id, :red)} " +
111
+ "already closed and merged to release branch, skipping...")
112
+ else
113
+ # Figure out which release branch to merge to
114
+ version = ''
115
+ Svn.propget(REL_BRN_PROP, @project.branches("bug/#@bug_id")) do |line|
116
+ version << line.chomp
117
+ end
118
+
119
+ version.strip!
120
+ if version.empty?
121
+ raise "Woah! missing #{REL_BRN_PROP} prop on #{@project.branches("bug/#@bug_id")}"
122
+ end
123
+
124
+ version = Version.new(version)
125
+
126
+ unless opthash[:force]
127
+ exit unless Constants::TERMINAL.agree("Merge bug fix branch for bug " +
128
+ Constants::TERMINAL.color(@bug_id, :red) + " to release " +
129
+ Constants::TERMINAL.color(@project.to_s, :green) + "/" +
130
+ Constants::TERMINAL.color(version.to_s, :red) + "? ")
131
+ end
132
+
133
+ # tag the end of the branch
134
+ Svn.branch(@project, @project.branches("bug/#@bug_id"), @project.tags("bug/POST-#@bug_id"))
135
+
136
+ # merge bug fix changes to the release branch
137
+ @project.merge(version, "bug/PRE-#@bug_id", "bug/POST-#@bug_id") do
138
+ "then commit your changes, and run this tool again to merge to trunk"
139
+ end
140
+ end
141
+
142
+ # merge bug fix changes to the trunk
143
+ if opthash[:no_trunk].nil?
144
+ question = "Merge bug fix branch for bug "
145
+ question << Constants::TERMINAL.color(@bug_id, :red) + " to "
146
+ question << Constants::TERMINAL.color(@project.to_s, :green)
147
+ question << "/trunk? "
148
+
149
+ if opthash[:force] or Constants::TERMINAL.agree(question)
150
+ @project.merge(nil, "bug/PRE-#@bug_id", "bug/POST-#@bug_id") do
151
+ "then commit your changes to finish the merge to the trunk"
152
+ end
153
+ end
154
+ end
155
+ end
156
+
157
+ end
158
+ ################################################################################
159
+ end
160
+ ################################################################################
161
+
@@ -0,0 +1,71 @@
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 Checkout < Command
28
+ ################################################################################
29
+ set(:name, [:checkout, :co])
30
+ set(:description, "Checkout a project from the repository")
31
+
32
+ option('-r', '--release VER', 'Checkout a release instead of the trunk') do |val, opts|
33
+ opts[:co_release] = Version.new(val)
34
+ end
35
+
36
+ option('-b', '--bug ID', 'Checkout a bug fix branch instead of the trunk') do |val, opts|
37
+ opts[:co_bug] = val
38
+ end
39
+
40
+ option('-e', '--exp NAME', 'Checkout exp branch NAME instead of the trunk') do |val, opts|
41
+ opts[:co_exp] = val
42
+ end
43
+
44
+ option('-p', '--prefix PATH', 'Use branch path PATH instead of exp') do |val, opts|
45
+ opts[:prefix] = val
46
+ end
47
+
48
+ ################################################################################
49
+ def run (project, args)
50
+ what =
51
+ case
52
+ when opthash[:co_bug]
53
+ project.branches("bug/#{opthash[:co_bug]}")
54
+ when opthash[:co_exp]
55
+ opthash[:prefix] ||= 'exp'
56
+ project.branches("#{opthash[:prefix]}/#{opthash[:co_exp]}")
57
+ when opthash[:co_release]
58
+ opthash[:co_release]
59
+ else
60
+ nil
61
+ end
62
+
63
+ Constants::TERMINAL.say("Checked out to: " +
64
+ Constants::TERMINAL.color(Path.relative_to_home(project.checkout(what)), :green))
65
+ end
66
+
67
+ end
68
+ ################################################################################
69
+ end
70
+ ################################################################################
71
+
@@ -0,0 +1,58 @@
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 Config < Command
28
+ ################################################################################
29
+ set(:name, :config)
30
+ set(:description, "Manage sc Configuration")
31
+ set(:without_repository)
32
+ set(:without_project)
33
+
34
+ ################################################################################
35
+ option('-a', '--add', 'Add a repository') do |val, hash|
36
+ config = ConfigFile.new
37
+ config[:repositories] << Repository.ask
38
+ config.save
39
+ end
40
+
41
+ ################################################################################
42
+ option('--color', 'Enable color by default') do |val, hash|
43
+ config = ConfigFile.new
44
+ config[:color] = true
45
+ config.save
46
+ end
47
+
48
+ ################################################################################
49
+ option('--no-color', 'Disable color by default') do |val, hash|
50
+ config = ConfigFile.new
51
+ config[:color] = false
52
+ config.save
53
+ end
54
+
55
+ end
56
+ ################################################################################
57
+ end
58
+ ################################################################################