Module: SVN

Defined in:
lib/svn.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.passwordObject

Returns the value of attribute password


7
8
9
# File 'lib/svn.rb', line 7

def password
  @password
end

.pathObject

Returns the value of attribute path


7
8
9
# File 'lib/svn.rb', line 7

def path
  @path
end

.usernameObject

Returns the value of attribute username


7
8
9
# File 'lib/svn.rb', line 7

def username
  @username
end

Class Method Details

.add(path) ⇒ Object

Adds the given path to the working copy


25
26
27
# File 'lib/svn.rb', line 25

def self.add(path)
  SVN.execute("add #{path}")
end

.add_allObject

Adds all new or modified files to the working copy


30
31
32
# File 'lib/svn.rb', line 30

def self.add_all
  SVN.status.each { |file| add = SVN.add(file[1]) if file[0] == '?' }
end

.add_and_commit_all(message = nil) ⇒ Object

Add all new or modified files to the working copy and commits changes An optional commit message can be passed if required


36
37
38
39
# File 'lib/svn.rb', line 36

def self.add_and_commit_all(message=nil)
  SVN.add_all
  SVN.commit message
end

.authentication_detailsObject

Returns a string to be passed into commands containing authentication options Requires setting of username and password via attr_accessor methods


12
13
14
# File 'lib/svn.rb', line 12

def self.authentication_details
  "--username #{@username} --password #{@password}"
end

.commit(message = nil) ⇒ Object

Commits all changes, and returns the new revision number An optional commit message can be passed if required


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/svn.rb', line 43

def self.commit(message=nil)
  if message.nil?
    action = SVN.execute("commit")
  else
    action = SVN.execute("commit -m '#{message}'")
  end
  if action.split(/\n/).last =~ /Committed revision (\d+)\./
    return $1
  else
    return nil
  end
end

.delete(file) ⇒ Object

Delete a file based on a given path


77
78
79
# File 'lib/svn.rb', line 77

def self.delete(file)
  SVN.execute("delete #{file}")
end

.diff(revision_1, revision_2, file = nil) ⇒ Object

Returns a diff of two commits based on their respective revision numbers (first and second arguments) and a repository path (third argument)


58
59
60
61
62
63
64
# File 'lib/svn.rb', line 58

def self.diff(revision_1,revision_2,file=nil)
  if file.nil?
    SVN.execute("diff -r #{revision_1}:#{revision_2}")
  else
    SVN.execute("diff -r #{revision_1}:#{revision_2} #{file}")
  end
end

.get(file, revision) ⇒ Object

Retrieve a file based on it's path and commit revision number


67
68
69
# File 'lib/svn.rb', line 67

def self.get(file,revision)
  SVN.execute("cat -r #{revision} #{file}")
end

.rename(old_filename, new_filename) ⇒ Object

Rename a file based on the given current and new filenames


72
73
74
# File 'lib/svn.rb', line 72

def self.rename(old_filename, new_filename)
  SVN.execute("rename #{old_filename} #{new_filename}")
end

.statusObject

Returns an array representing the current status of any new or modified files


17
18
19
20
21
22
# File 'lib/svn.rb', line 17

def self.status
  SVN.execute("status").split(/\n/).map do |file|
    file =~ /(\?|\!|\~|\*|\+|A|C|D|I|M|S|X)\s*([\w\W]*)/
    [$1, $2]
  end
end