Class: Piston::Svn::Revision
Defined Under Namespace
Classes: InvalidRevision, RepositoryMoved, UuidChanged
Instance Attribute Summary
Attributes inherited from Revision
#dir, #recalled_values, #repository, #revision
Instance Method Summary
collapse
Methods inherited from Revision
#copy_from, #copy_to, #initialize, #inspect, #logger, logger, #to_s, #url
Instance Method Details
#checkout_to(dir) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/piston/svn/revision.rb', line 23
def checkout_to(dir)
super
answer = svn(:checkout, "--revision", revision, repository.url, dir)
if answer =~ /Checked out revision (\d+)[.]/ then
if revision == "HEAD" then
@revision = $1.to_i
elsif revision.to_i != $1.to_i then
raise InvalidRevision, "Did not get the revision I wanted to checkout. Subversion checked out #{$1}, I wanted #{revision}"
end
else
raise InvalidRevision, "Could not checkout revision #{revision} from #{repository.url} to #{dir}\n#{answer}"
end
end
|
#client ⇒ Object
11
12
13
|
# File 'lib/piston/svn/revision.rb', line 11
def client
@client ||= Piston::Svn::Client.instance
end
|
#each ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/piston/svn/revision.rb', line 64
def each
raise ArgumentError, "Revision #{revision} of #{repository.url} was never checked out -- can't iterate over files" unless @dir
svn(:ls, "--recursive", @dir).split("\n").each do |relpath|
next if relpath =~ %r{/$}
next if relpath == '.piston.yml'
yield relpath.chomp
end
end
|
#exclude_for_diff ⇒ Object
94
95
96
|
# File 'lib/piston/svn/revision.rb', line 94
def exclude_for_diff
Piston::Svn::EXCLUDE
end
|
#name ⇒ Object
19
20
21
|
# File 'lib/piston/svn/revision.rb', line 19
def name
"r#{revision}"
end
|
#recalled_uuid ⇒ Object
82
83
84
|
# File 'lib/piston/svn/revision.rb', line 82
def recalled_uuid
recalled_values[Piston::Svn::UUID]
end
|
#remember_values ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/piston/svn/revision.rb', line 56
def remember_values
str = svn(:info, "--revision", revision, repository.url)
raise Failed, "Could not get 'svn info' from #{repository.url} at revision #{revision}" if str.nil? || str.chomp.strip.empty?
info = YAML.load(str)
{ Piston::Svn::UUID => info["Repository UUID"],
Piston::Svn::REMOTE_REV => info["Revision"]}
end
|
#remotely_modified ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/piston/svn/revision.rb', line 86
def remotely_modified
logger.debug {"Get last revision in #{repository.url}"}
data = svn(:info, repository.url)
info = YAML.load(data)
latest_revision = info["Last Changed Rev"].to_i
revision < latest_revision
end
|
#resolve! ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/piston/svn/revision.rb', line 98
def resolve!
logger.debug {"Resolving #{@revision} to it's real value"}
return if @revision.to_i == @revision && !@revision.blank?
data = YAML.load(svn(:info, repository.url))
@revision = data["Last Changed Rev"].to_i
logger.debug {"Resolved #{@revision}"}
@revision
end
|
#svn(*args) ⇒ Object
15
16
17
|
# File 'lib/piston/svn/revision.rb', line 15
def svn(*args)
client.svn(*args)
end
|
#update_to(revision) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/piston/svn/revision.rb', line 37
def update_to(revision)
raise ArgumentError, "Revision #{self.revision} of #{repository.url} was never checked out -- can't update" unless @dir
answer = svn(:update, "--revision", revision, @dir)
if answer =~ /(Updated to|At) revision (\d+)[.]/ then
if revision == "HEAD" then
@revision = $2.to_i
elsif revision != $2.to_i then
raise InvalidRevision, "Did not get the revision I wanted to update. Subversion update to #{$1}, I wanted #{revision}"
end
else
raise InvalidRevision, "Could not update #{@dir} to revision #{revision} from #{repository.url}\n#{answer}"
end
added = relative_paths(answer.scan(/^A\s+(.*)$/).flatten)
deleted = relative_paths(answer.scan(/^D\s+(.*)$/).flatten)
renamed = []
[added, deleted, renamed]
end
|
#validate! ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/piston/svn/revision.rb', line 74
def validate!
data = svn(:info, "--revision", revision, repository.url)
info = YAML.load(data)
actual_uuid = info["Repository UUID"]
raise RepositoryMoved, "Repository at #{repository.url} does not exist anymore:\n#{data}" if actual_uuid.blank?
raise UuidChanged, "Expected repository at #{repository.url} to have UUID #{recalled_uuid} but found #{actual_uuid}" if recalled_uuid != actual_uuid
end
|