svnauto 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/bin/sc +2 -10
  2. data/{lib/sc/constants.rb → bin/sva} +8 -13
  3. data/lib/{sc.rb → svnauto.rb} +13 -9
  4. data/lib/{sc → svnauto}/command.rb +8 -3
  5. data/lib/{sc → svnauto}/commands/bug.rb +5 -2
  6. data/lib/{sc → svnauto}/commands/checkout.rb +3 -1
  7. data/lib/{sc → svnauto}/commands/config.rb +18 -2
  8. data/lib/{sc → svnauto}/commands/create.rb +2 -1
  9. data/lib/{sc → svnauto}/commands/experimental.rb +19 -5
  10. data/lib/svnauto/commands/externals.rb +128 -0
  11. data/lib/{sc → svnauto}/commands/info.rb +1 -1
  12. data/lib/{sc → svnauto}/commands/list.rb +3 -1
  13. data/lib/{sc → svnauto}/commands/release.rb +39 -7
  14. data/lib/{sc → svnauto}/config_file.rb +3 -3
  15. data/lib/{sc/path.rb → svnauto/constants.rb} +24 -18
  16. data/lib/{sc → svnauto}/dispatcher.rb +11 -4
  17. data/lib/svnauto/path.rb +138 -0
  18. data/lib/{sc → svnauto}/project.rb +16 -11
  19. data/lib/{sc → svnauto}/repository.rb +2 -2
  20. data/lib/{sc → svnauto}/svn.rb +51 -10
  21. data/lib/svnauto/svn_externals.rb +187 -0
  22. data/lib/svnauto/svn_info.rb +96 -0
  23. data/lib/{sc → svnauto}/version.rb +2 -2
  24. data/test/setup.rb +24 -28
  25. data/test/test_bug.rb +10 -10
  26. data/test/test_checkout.rb +3 -3
  27. data/test/test_create.rb +3 -3
  28. data/test/test_experimental.rb +33 -18
  29. data/test/test_externals.rb +55 -0
  30. data/test/test_path.rb +148 -0
  31. data/test/test_release.rb +11 -11
  32. data/test/test_svninfo.rb +17 -0
  33. data/test/test_version.rb +16 -16
  34. metadata +35 -42
  35. data/INSTALL +0 -48
  36. data/LICENSE +0 -22
  37. data/README +0 -81
  38. data/THANKS +0 -8
  39. data/TODO +0 -8
  40. data/doc/manual.txt +0 -241
data/bin/sc CHANGED
@@ -23,13 +23,5 @@
23
23
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  #
25
25
  ################################################################################
26
- require 'rubygems'
27
- require 'sc'
28
-
29
- begin
30
- SC::Dispatcher.new.run
31
- rescue RuntimeError => e
32
- $stderr.puts "#{SC::Constants::TERMINAL.color(SC::Constants::ME, :red)}: #{e}"
33
- exit 1
34
- end
35
- ################################################################################
26
+ puts "The 'sc' command has been renamed to 'sva', please use 'sva' instead."
27
+ exit 1
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
  ################################################################################
2
3
  #
3
4
  # Copyright (C) 2006 Peter J Jones (pjones@pmade.com)
@@ -22,19 +23,13 @@
22
23
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24
  #
24
25
  ################################################################################
25
- module SC
26
- module Constants
27
- ################################################################################
28
- # The version number for this copy of SC
29
- VERSION = '1.0.2'
26
+ require 'rubygems'
27
+ require 'svnauto'
30
28
 
31
- ################################################################################
32
- # What to call myself
33
- ME = 'sc'
34
-
35
- ################################################################################
36
- TERMINAL = HighLine.new
37
-
38
- end
29
+ begin
30
+ SvnAuto::Dispatcher.new.run
31
+ rescue RuntimeError => e
32
+ $stderr.puts "#{SvnAuto::Constants::TERMINAL.color(SvnAuto::Constants::ME, :red)}: #{e}"
33
+ exit 1
39
34
  end
40
35
  ################################################################################
@@ -25,15 +25,19 @@
25
25
  require 'rubygems'
26
26
  require 'highline'
27
27
  require 'uri'
28
+ require 'set'
28
29
  require 'pathname'
30
+ require 'tempfile'
29
31
  ################################################################################
30
- require 'sc/constants'
31
- require 'sc/version'
32
- require 'sc/config_file'
33
- require 'sc/svn'
34
- require 'sc/path'
35
- require 'sc/project'
36
- require 'sc/repository'
37
- require 'sc/command'
38
- require 'sc/dispatcher'
32
+ require 'svnauto/constants'
33
+ require 'svnauto/version'
34
+ require 'svnauto/config_file'
35
+ require 'svnauto/svn'
36
+ require 'svnauto/svn_info'
37
+ require 'svnauto/svn_externals'
38
+ require 'svnauto/path'
39
+ require 'svnauto/project'
40
+ require 'svnauto/repository'
41
+ require 'svnauto/command'
42
+ require 'svnauto/dispatcher'
39
43
  ################################################################################
@@ -25,13 +25,14 @@
25
25
  require 'optparse'
26
26
  require 'set'
27
27
  ################################################################################
28
- module SC
28
+ module SvnAuto
29
29
  ################################################################################
30
30
  class Command
31
31
  ################################################################################
32
32
  VALID_SET_KEYS = Set.new([
33
33
  :name,
34
34
  :description,
35
+ :example,
35
36
  :without_project,
36
37
  :without_repository,
37
38
  :usage,
@@ -104,7 +105,11 @@ module SC
104
105
  raise "invalid set key #{name}, wanted one of #{VALID_SET_KEYS.join(', ')}"
105
106
  end
106
107
 
107
- instance_eval { @attributes[name] = value }
108
+ if name == :example
109
+ instance_eval { (@attributes[name] ||= []) << value }
110
+ else
111
+ instance_eval { @attributes[name] = value }
112
+ end
108
113
  end
109
114
 
110
115
  ################################################################################
@@ -120,5 +125,5 @@ end
120
125
  # load all commands
121
126
  Dir.foreach(File.join(File.dirname(__FILE__), 'commands')) do |file|
122
127
  next unless file.match(/\.rb$/)
123
- require 'sc/commands/' + file
128
+ require 'svnauto/commands/' + file
124
129
  end
@@ -22,7 +22,7 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #
24
24
  ################################################################################
25
- module SC
25
+ module SvnAuto
26
26
  ################################################################################
27
27
  class Bug < Command
28
28
  ################################################################################
@@ -34,6 +34,9 @@ module SC
34
34
  set(:usage, "[options] unique-bug-id")
35
35
  set(:args_min, 1)
36
36
  set(:args_max, 1)
37
+ set(:example, "12 # create bug fix branch for bug ID 12")
38
+ set(:example, "--close 12 # close and merge changes")
39
+ set(:example, "--diff 12 # show diff for changes in bug 12")
37
40
 
38
41
  option('-r', '--release VER', "Create branch off VER rel branch instead of latest rel") do |val, opthash|
39
42
  opthash[:release] = val
@@ -103,7 +106,7 @@ module SC
103
106
 
104
107
  # record the release branch so we can get back to it later
105
108
  Svn.propset(REL_BRN_PROP, @version.to_s, dir) {|line|}
106
- Svn.commit('-m', "'#{Constants::ME}: recording release branch for bug fix #@bug_id'", dir)
109
+ Svn.commit('-m', "#{Constants::ME}: recording release branch for bug fix #@bug_id", dir)
107
110
 
108
111
  Constants::TERMINAL.say("Created bug fix branch and checked out to: " +
109
112
  Constants::TERMINAL.color(Path.relative_to_home(dir), :green))
@@ -22,13 +22,15 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #
24
24
  ################################################################################
25
- module SC
25
+ module SvnAuto
26
26
  ################################################################################
27
27
  class Checkout < Command
28
28
  ################################################################################
29
29
  set(:name, [:checkout, :co])
30
30
  set(:description, "Checkout a project from the repository")
31
31
  set(:args_max, 0)
32
+ set(:example, "# check out the trunk")
33
+ set(:example, "--bug 12 # check out bug fix branch for bug ID 12")
32
34
 
33
35
  option('-r', '--release VER', 'Checkout a release instead of the trunk') do |val, opts|
34
36
  opts[:co_release] = Version.new(val)
@@ -22,12 +22,12 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #
24
24
  ################################################################################
25
- module SC
25
+ module SvnAuto
26
26
  ################################################################################
27
27
  class Config < Command
28
28
  ################################################################################
29
29
  set(:name, :config)
30
- set(:description, "Manage sc Configuration")
30
+ set(:description, "Manage the sva configuration file")
31
31
  set(:args_max, 0)
32
32
  set(:without_repository)
33
33
  set(:without_project)
@@ -53,6 +53,22 @@ module SC
53
53
  config.save
54
54
  end
55
55
 
56
+ ################################################################################
57
+ option('--update', 'Update the config file for this version of sva') do |val, hash|
58
+ old_name = File.join(ENV['HOME'], '.sc')
59
+
60
+ if File.exist?(old_name)
61
+ File.open(old_name) do |old_file|
62
+ File.open(ConfigFile::FILENAME, 'w') do |new_file|
63
+ old_file.each_line {|l| new_file << l.gsub(/SC::/, 'SvnAuto::')}
64
+ end
65
+ end
66
+
67
+ FileUtils::rm(old_name)
68
+ puts "#{Constants::ME}: moved sc config file to sva location"
69
+ end
70
+ end
71
+
56
72
  end
57
73
  ################################################################################
58
74
  end
@@ -22,7 +22,7 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #
24
24
  ################################################################################
25
- module SC
25
+ module SvnAuto
26
26
  ################################################################################
27
27
  class Create < Command
28
28
  ################################################################################
@@ -32,6 +32,7 @@ module SC
32
32
  set(:usage, "[options] project-name")
33
33
  set(:args_min, 1)
34
34
  set(:args_max, 1)
35
+ set(:example, "hello-world # create a new project called hello-world")
35
36
 
36
37
  option('-C', '--no-checkout', "Don't checkout the new project") do |val, opthash|
37
38
  opthash[:no_checkout] = true
@@ -22,7 +22,7 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #
24
24
  ################################################################################
25
- module SC
25
+ module SvnAuto
26
26
  ################################################################################
27
27
  class Experimental < Command
28
28
  ################################################################################
@@ -31,6 +31,13 @@ module SC
31
31
  set(:usage, "[options] branch-name")
32
32
  set(:args_min, 1)
33
33
  set(:args_max, 1)
34
+ set(:example, "crazy # create an experimental branch called crazy")
35
+ set(:example, "--up crazy # merge the trunk onto crazy")
36
+ set(:example, "--down crazy # merge crazy to the trunk")
37
+
38
+ option('-r', '--revision REV', 'Branch at REV instead of trunk/HEAD') do |val, opts|
39
+ opts[:revision] = val
40
+ end
34
41
 
35
42
  option('-p', '--prefix PATH', 'Use branch prefix PATH instead of exp') do |val, opts|
36
43
  opts[:prefix] = val
@@ -88,12 +95,19 @@ module SC
88
95
  name = @branch_name
89
96
  name = @path if @prefix != 'exp'
90
97
 
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? ")
98
+ question = "Create experimental branch "
99
+ question << Constants::TERMINAL.color(name, :green) + " off "
100
+ question << Constants::TERMINAL.color(@project.to_s, :green) + "/trunk"
101
+ question << Constants::TERMINAL.color(":#{opthash[:revision]}", :red) if opthash[:revision]
102
+ question << "? "
103
+
104
+ exit unless Constants::TERMINAL.agree(question)
94
105
  end
95
106
 
96
- Svn.branch(@project, @project.trunk, @project.branches(@path))
107
+ branch_options = {}
108
+ branch_options[:revision] = opthash[:revision] if opthash[:revision]
109
+
110
+ Svn.branch(@project, @project.trunk, @project.branches(@path), branch_options)
97
111
  Svn.branch(@project, @project.branches(@path), @project.tags("#{@prefix}/PRE-#{@branch_name}"))
98
112
 
99
113
  unless opthash[:no_checkout]
@@ -0,0 +1,128 @@
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 SvnAuto
26
+ ################################################################################
27
+ class Externals < Command
28
+ ################################################################################
29
+ set(:name, :externals)
30
+ set(:description, "Lock/Unlock svn:externals at specific revisions")
31
+ set(:usage, "[options] [directory ...]")
32
+ set(:without_repository)
33
+ set(:without_project)
34
+ set(:example, "--lock --revision 1218 vendor/rails")
35
+ set(:example, "--unlock vendor/rails")
36
+ set(:example, "--info vendor/rails")
37
+
38
+ option('-r', '--revision REV', "Lock at REV instead of the current one") do |val, opthash|
39
+ raise "invalid format for revision: #{val}" unless val.match(/^\d+$/)
40
+ opthash[:revision] = val
41
+ end
42
+
43
+ option('-N', '--non-recursive', "Don't recurse into given directories") do |val, opthash|
44
+ opthash[:nonrecursive] = true
45
+ end
46
+
47
+ option('-l', '--lock', "Lock an external at a specific revision") do |val, opthash|
48
+ opthash[:lock] = true
49
+ end
50
+
51
+ option('-u', '--unlock', "Unlock externals so they track commits again") do |val, opthash|
52
+ opthash[:unlock] = true
53
+ end
54
+
55
+ option('-i', '--info', "Get info about locked/unlocked externals") do |val, opthash|
56
+ opthash[:info] = true
57
+ end
58
+
59
+ ################################################################################
60
+ def run (project, args)
61
+ @externals = SvnExternals.new(args, !opthash[:nonrecursive])
62
+
63
+ if opthash[:info]
64
+ info
65
+ elsif opthash[:lock] or opthash[:unlock]
66
+ if opthash[:lock] and opthash[:unlock]
67
+ raise "--lock and --unlock are mutually exclusive, you may only use one at a time"
68
+ end
69
+
70
+ uncommitted_check
71
+ lock if opthash[:lock]
72
+ unlock if opthash[:unlock]
73
+ end
74
+ end
75
+
76
+ ################################################################################
77
+ def info
78
+ show_info_for(:locked)
79
+ show_info_for(:unlocked)
80
+ end
81
+
82
+ ################################################################################
83
+ def lock
84
+ locking = @externals.unlocked.dup
85
+ @externals.lock
86
+ show_info_for(:locked, locking)
87
+ end
88
+
89
+ ################################################################################
90
+ def unlock
91
+ unlocking = @externals.locked.dup
92
+ @externals.unlock
93
+ show_info_for(:unlocked, unlocking)
94
+ end
95
+
96
+ ################################################################################
97
+ def show_info_for (state, collection=nil)
98
+ title = 'unlocked'
99
+ color = :green
100
+
101
+ if state == :locked
102
+ title = ' locked'
103
+ color = :red
104
+ end
105
+
106
+ collection ||= @externals.send(state)
107
+ collection.each do |external|
108
+ status = Constants::TERMINAL.color(title, color) + ' '
109
+ status << Constants::TERMINAL.color(external.revision.rjust(6), :red) + ' '
110
+ status << Constants::TERMINAL.color(external.path, :green) + ' '
111
+ status << Constants::TERMINAL.color(external.url, :cyan)
112
+ Constants::TERMINAL.say(status)
113
+ end
114
+ end
115
+
116
+ ################################################################################
117
+ # make sure we can't run if there are uncomitted changes
118
+ def uncommitted_check
119
+ Svn.status do |line|
120
+ next if line.match(/^\s*X/) or line.match(/^\s*$/)
121
+ next if line.match(/^\s*Performing/)
122
+ raise "you have uncommitted changes, you must commit first: #{line}"
123
+ end
124
+ end
125
+
126
+ end
127
+ end
128
+ ################################################################################
@@ -22,7 +22,7 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #
24
24
  ################################################################################
25
- module SC
25
+ module SvnAuto
26
26
  ################################################################################
27
27
  class Info < Command
28
28
  set(:name, :info)
@@ -22,13 +22,15 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #
24
24
  ################################################################################
25
- module SC
25
+ module SvnAuto
26
26
  ################################################################################
27
27
  class List < Command
28
28
  ################################################################################
29
29
  set(:name, [:list, :ls])
30
30
  set(:description, "List directory contents, projects, releases, etc.")
31
31
  set(:without_project)
32
+ set(:example, "# list projects")
33
+ set(:example, "hello-world/trunk # list the contents of the hello-world trunk")
32
34
 
33
35
  ################################################################################
34
36
  def run (project, args)
@@ -22,7 +22,7 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  #
24
24
  ################################################################################
25
- module SC
25
+ module SvnAuto
26
26
  ################################################################################
27
27
  class Release < Command
28
28
  set(:name, :release)
@@ -30,11 +30,21 @@ module SC
30
30
  set(:usage, "[options] major.minor[.macro]")
31
31
  set(:args_min, 1)
32
32
  set(:args_max, 1)
33
+ set(:example, "1.0 # create a release branch")
34
+ set(:example, "1.0.0 # create a branch if necessary, and tag it")
35
+
36
+ option('-r', '--revision REV', 'Branch at REV instead of trunk/HEAD') do |val, opts|
37
+ opts[:revision] = val
38
+ end
33
39
 
34
40
  option('-C', '--no-checkout', "Don't checkout the rel branch") do |val, opts|
35
41
  opts[:no_checkout] = true
36
42
  end
37
43
 
44
+ option('-l', '--lock-all', "Lock all svn:externals after release") do |val, opts|
45
+ opts[:lock_all] = true
46
+ end
47
+
38
48
  ################################################################################
39
49
  def run (project, args)
40
50
  @version = Version.new(args.first)
@@ -50,13 +60,23 @@ module SC
50
60
 
51
61
  ################################################################################
52
62
  def make_release_branch
63
+ if opthash[:no_checkout] and opthash[:lock_all]
64
+ raise "you can't use --lock-all with --no-checkout"
65
+ end
66
+
53
67
  unless opthash[:force]
54
- question = "Create " + Constants::TERMINAL.color(@project.to_s, :green)
55
- question << " release branch " + Constants::TERMINAL.color(@version.major_minor, :red) + "? "
68
+ question = "Create " + Constants::TERMINAL.color(@project.to_s, :green)
69
+ question << " release branch " + Constants::TERMINAL.color(@version.major_minor, :red)
70
+ question << " off the trunk"
71
+ question << " at revision #{opthash[:revision]}" if opthash[:revision]
72
+ question << "? "
73
+
56
74
  exit unless Constants::TERMINAL.agree(question)
57
75
  end
58
76
 
59
- Svn.branch(@project, @project.trunk, @project.branches("rel/#{@version.major_minor}"))
77
+ branch_options = {}
78
+ branch_options[:revision] = opthash[:revision] if opthash[:revision]
79
+ Svn.branch(@project, @project.trunk, @project.branches("rel/#{@version.major_minor}"), branch_options)
60
80
 
61
81
  if @version.macro.nil?
62
82
  question = "Tag release branch as "
@@ -70,9 +90,21 @@ module SC
70
90
  tag_release_branch unless @version.macro.nil?
71
91
 
72
92
  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))
93
+ checkout_location = @project.checkout(@project.branches("rel/#{@version.major_minor}"))
94
+ from_home = Path.relative_to_home(checkout_location)
95
+ Constants::TERMINAL.say("Checked out to: " + Constants::TERMINAL.color(from_home, :green))
96
+
97
+ if opthash[:lock_all]
98
+ Dir.chdir(checkout_location) do
99
+ externals = SvnExternals.new
100
+ locked = externals.unlocked.size
101
+ externals.lock
102
+
103
+ message = "Locked " + Constants::TERMINAL.color(locked.to_s, :red)
104
+ message += locked == 1 ? "external" : "externals"
105
+ Constants::TERMINAL.say(message)
106
+ end
107
+ end
76
108
  end
77
109
  end
78
110