Class: RSCM::Monotone

Inherits:
Base show all
Defined in:
lib/rscm/scm/monotone.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#checkout_dir

Instance Method Summary collapse

Methods inherited from Base

#==, #checkout, #checkout_commandline, classes, #edit, register, #to_yaml_properties, #update_commandline

Constructor Details

#initialize(branch = nil, key = nil, passphrase = nil, keys_file = nil, server = nil, central_checkout_dir = nil) ⇒ Monotone

Returns a new instance of Monotone.



27
28
29
30
31
32
33
34
# File 'lib/rscm/scm/monotone.rb', line 27

def initialize(branch=nil, key=nil, passphrase=nil, keys_file=nil, server=nil, central_checkout_dir=nil)
  @branch = branch
  @key = key
  @passphrase = passphrase
  @keys_file = keys_file
  @server = server
  @central_checkout_dir = File.expand_path(central_checkout_dir) unless central_checkout_dir.nil?
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



13
14
15
# File 'lib/rscm/scm/monotone.rb', line 13

def branch
  @branch
end

#db_fileObject

Returns the value of attribute db_file.



10
11
12
# File 'lib/rscm/scm/monotone.rb', line 10

def db_file
  @db_file
end

#keyObject

Returns the value of attribute key.



16
17
18
# File 'lib/rscm/scm/monotone.rb', line 16

def key
  @key
end

#keys_fileObject

Returns the value of attribute keys_file.



22
23
24
# File 'lib/rscm/scm/monotone.rb', line 22

def keys_file
  @keys_file
end

#passphraseObject

Returns the value of attribute passphrase.



19
20
21
# File 'lib/rscm/scm/monotone.rb', line 19

def passphrase
  @passphrase
end

#serverObject

Returns the value of attribute server.



25
26
27
# File 'lib/rscm/scm/monotone.rb', line 25

def server
  @server
end

Instance Method Details

#add(relative_filename) ⇒ Object



36
37
38
39
40
41
# File 'lib/rscm/scm/monotone.rb', line 36

def add(relative_filename)
  db = db(@checkout_dir)
  with_working_dir(@checkout_dir) do
    monotone("add #{relative_filename}", db)
  end
end

#can_create_central?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/rscm/scm/monotone.rb', line 50

def can_create_central?
  @server == "localhost" && !@central_checkout_dir.nil?
end

#central_exists?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rscm/scm/monotone.rb', line 54

def central_exists?
  @central_checkout_dir && @serve_pid
end

#checked_out?Boolean

Returns:

  • (Boolean)


121
122
123
124
# File 'lib/rscm/scm/monotone.rb', line 121

def checked_out?
  mt = File.expand_path("#{@checkout_dir}/MT")
  File.exists?(mt)
end

#commit(message) ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'lib/rscm/scm/monotone.rb', line 147

def commit(message)
  commit_in_dir(message, @checkout_dir)
  with_working_dir(@checkout_dir) do
    monotone("push #{@server} #{@branch}") do |io|
      io.puts(@passphrase)
      io.close_write
      io.read
    end
  end
end

#create_centralObject



58
59
60
61
62
63
64
65
# File 'lib/rscm/scm/monotone.rb', line 58

def create_central
  init(@central_checkout_dir)
  # create empty working copy
  dir = PathConverter.filepath_to_nativepath(@central_checkout_dir, false)
  # set up a working copy
  monotone("setup #{dir}")
  start_serve
end

#destroy_centralObject



102
103
104
105
106
107
# File 'lib/rscm/scm/monotone.rb', line 102

def destroy_central
  stop_serve
  FileUtils.rm_rf(@central_checkout_dir) if File.exist?(@central_checkout_dir)
  FileUtils.rm(db(@central_checkout_dir)) if File.exist?(db(@central_checkout_dir))
  puts "Destroyed Monotone server"
end

#diff(change, &block) ⇒ Object



183
184
185
186
187
188
189
190
# File 'lib/rscm/scm/monotone.rb', line 183

def diff(change, &block)
  checkout(change.revision)
  with_working_dir(@checkout_dir) do
    monotone("diff --revision=#{change.previous_native_revision_identifier} #{change.path}") do |stdout|
      yield stdout
    end
  end
end

#import_central(dir, message) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/rscm/scm/monotone.rb', line 113

def import_central(dir, message)
  FileUtils.cp_r(Dir["#{dir}/*"], @central_checkout_dir)
  with_working_dir(@central_checkout_dir) do
    monotone("add .")
    commit_in_dir(message, @central_checkout_dir)
  end
end

#install_trigger(trigger_command, install_dir) ⇒ Object



163
164
165
166
167
168
169
170
171
# File 'lib/rscm/scm/monotone.rb', line 163

def install_trigger(trigger_command, install_dir)
  stop_serve
  if (WINDOWS)
    install_win_trigger(trigger_comand, install_dir)
  else
    install_unix_trigger(trigger_command, install_dir)
  end
  start_serve
end

#move(relative_src, relative_dest) ⇒ Object



43
44
45
46
47
48
# File 'lib/rscm/scm/monotone.rb', line 43

def move(relative_src, relative_dest)
  with_working_dir(@checkout_dir) do
    monotone("rename #{relative_src} #{relative_dest}", db)
    FileUtils.mv(relative_src, relative_dest)
  end
end

#revisions(from_identifier, to_identifier = Time.infinity) ⇒ Object



137
138
139
140
141
142
143
144
145
# File 'lib/rscm/scm/monotone.rb', line 137

def revisions(from_identifier, to_identifier=Time.infinity)
  checkout(to_identifier)
  to_identifier = Time.infinity if to_identifier.nil?
  with_working_dir(checkout_dir) do
    monotone("log") do |stdout|
      MonotoneLogParser.new.parse_revisions(stdout, from_identifier, to_identifier)
    end
  end
end

#start_serveObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rscm/scm/monotone.rb', line 67

def start_serve
  mode = File::CREAT|File::WRONLY
  if File.exist?(rcfile)
    mode = File::APPEND|File::WRONLY
  end

  begin
    File.open(rcfile, mode) do |file|
      file.puts("function get_netsync_anonymous_read_permitted(collection)")
      file.puts("  return true")
      file.puts("end")
    end
  rescue => e
    puts e.message
    puts e.backtrace.join("\n")
    raise "Didn't have permission to write to #{rcfile}."
  end

  @serve_pid = fork do
    #Signal.trap("HUP") { puts "Monotone server shutting down..."; exit }
    monotone("serve --rcfile=\"#{rcfile}\" #{@server} #{@branch}", db(@central_checkout_dir)) do |io|
      puts "PASSPHRASE: #{@passphrase}"
      io.puts(@passphrase)
      io.close_write
    end
  end
  Process.detach(@serve_pid)
end

#stop_serveObject



96
97
98
99
100
# File 'lib/rscm/scm/monotone.rb', line 96

def stop_serve
  Process.kill("HUP", @serve_pid) if @serve_pid
  Process.waitpid2(@serve_pid) if @serve_pid
  @serve_pid = nil
end

#supports_trigger?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/rscm/scm/monotone.rb', line 158

def supports_trigger?
  true
end

#transactional?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/rscm/scm/monotone.rb', line 109

def transactional?
  true
end

#trigger_installed?(trigger_command, install_dir) ⇒ Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/rscm/scm/monotone.rb', line 173

def trigger_installed?(trigger_command, install_dir)
  File.exist?(rcfile)
end

#uninstall_trigger(trigger_command, install_dir) ⇒ Object



177
178
179
180
181
# File 'lib/rscm/scm/monotone.rb', line 177

def uninstall_trigger(trigger_command, install_dir)
  stop_serve
  File.delete(rcfile)
  start_serve
end

#uptodate?(identifier = nil) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
129
130
131
132
133
134
135
# File 'lib/rscm/scm/monotone.rb', line 126

def uptodate?(identifier=nil)
  if (!checked_out?)
    false
  else
    pull

    rev = identifier ? identifier : head_revision
    local_revision == rev
  end
end