Class: Corundum::Monotone
- Inherits:
-
VersionControl
- Object
- Mattock::TaskLib
- TaskLib
- VersionControl
- Corundum::Monotone
- Defined in:
- lib/corundum/version_control/monotone.rb
Instance Method Summary collapse
- #base_revision ⇒ Object
- #define ⇒ Object
- #guess_branch ⇒ Object
- #mtn_automate(cmd, *args) ⇒ Object
- #parse_basic_io(string) ⇒ Object
- #parse_certs(string) ⇒ Object
- #resolve_configuration ⇒ Object
- #stanzas(first_item, items) ⇒ Object
Methods inherited from VersionControl
Instance Method Details
#base_revision ⇒ Object
72 73 74 |
# File 'lib/corundum/version_control/monotone.rb', line 72 def base_revision mtn_automate("get_base_revision_id").chomp end |
#define ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/corundum/version_control/monotone.rb', line 98 def define super in_namespace do task :on_branch do branches = parse_certs(mtn_automate("certs", base_revision))["branch"] || [] unless branches.include?(branch) fail "Not on branch #{branch}" end end task :not_tagged do items = parse_basic_io(mtn_automate("tags", branch)) = items.find{|pair| pair[0] == "tag" && pair[1] == tag} unless .nil? fail "Tag #{tag} already exists in branch #{branch}" end end task :workspace_committed => :on_branch do items = parse_basic_io(mtn_automate("inventory")) changed = items.find{|pair| pair[0] == "changes"} unless changed.nil? fail "Uncommitted changes exist in workspace" end end task :gemspec_files_added => :on_branch do items = stanzas("path", parse_basic_io(mtn_automate("inventory"))) items.delete_if{|item| item["status"] == "unknown"} known_paths = items.each_with_object({}) do |item, hash| hash[item["path"]] = true end files = gemspec_files.dup files.delete_if{|path| known_paths[path]} unless files.empty? fail "Gemspec files not in version control: #{files.join(" ")}" end end task :tag => :on_branch do mtn_automate("cert", base_revision, "tag", tag) end task :sync do mtn_automate("sync") end task :check_in => [:sync] end end |
#guess_branch ⇒ Object
76 77 78 79 80 81 |
# File 'lib/corundum/version_control/monotone.rb', line 76 def guess_branch puts "Guessing branch - configure Monotone > branch" certs = parse_certs(mtn_automate("certs", base_revision)) puts " Guessed: #{certs["branch"].first}" certs["branch"].first end |
#mtn_automate(cmd, *args) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/corundum/version_control/monotone.rb', line 13 def mtn_automate(cmd, *args) result = Mattock::CommandLine.new("mtn", "automate", cmd) do |cmd| cmd. += args end.run result.must_succeed! result.stdout end |
#parse_basic_io(string) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/corundum/version_control/monotone.rb', line 21 def parse_basic_io(string) items = [] scanner = StringScanner.new(string) scanner.scan(/\s*/m) until scanner.eos? do symbol = scanner.scan(/[a-z_]*/) scanner.scan(/\s*/) value = "" case scanner.scan(/["\[]/) when '"' while (value += scanner.scan(/[^"]*/)) =~ /\\$/ end scanner.scan(/"/) when '[' value = scanner.scan(/[^\]]*/) scanner.scan(/]/) else raise "Improperly formatted basic_io: \ \n Got: #{items.inspect} + #{symbol}\ \n Rest:\ \n #{scanner.rest}" end items << [symbol, value] scanner.scan(/\s*/m) end return items end |
#parse_certs(string) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/corundum/version_control/monotone.rb', line 50 def parse_certs(string) items = parse_basic_io(string) pair = [] hash = Hash.new do |h,k| h[k] = [] end items.each do |name, value| case name when "name" pair[0] = value when "value" pair[1] = value when "trust" if value == "trusted" hash[pair[0]] << pair[1] end pair = [] end end hash end |
#resolve_configuration ⇒ Object
9 10 11 |
# File 'lib/corundum/version_control/monotone.rb', line 9 def resolve_configuration @branch ||= guess_branch end |
#stanzas(first_item, items) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/corundum/version_control/monotone.rb', line 85 def stanzas(first_item, items) stanzas = [] current_stanza = {} items.each do |name, value| if name == first_item current_stanza = {} stanzas << current_stanza end current_stanza[name] = value end return stanzas end |