20
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
95
96
97
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
|
# File 'lib/nixenvironment/scm.rb', line 20
def self.last_revision
scm_type = current
case scm_type
when SCM_SVN
puts 'SVN working copy detected'
current_revision = %x[ svnversion ]
current_monotonic_revision = current_revision
if Integer(current_revision)
working_copy_is_clean = 1
else
puts "Working copy is not clean because of svnversion returning #{current_revision}"
working_copy_is_clean = 0
end
when SCM_GIT
puts 'GIT working copy detected'
usedf = ENV['USE_DATEFORMAT']
unless !usedf.nil?
current_revision = %x[ git rev-parse HEAD ]
last_revision_in_repo = %x[ git rev-list --all -n 1 ]
current_monotonic_revision = %x[ git rev-list --all --count ]
if current_revision == last_revision_in_repo
current_monotonic_revision = current_monotonic_revision.succ
end
else
git_commit_timestamp = %x[ git show -s --format=%ct #{last_revision_in_repo} ]
git_result = Time.at(git_commit_timestamp.to_i)
year = "%02d" % git_result.year.to_s[2,2].to_i
month = "%02d" % git_result.month
day = "%02d" % git_result.day
hour = "%02d" % git_result.hour
min = "%02d" % git_result.min
sec = "%02d" % git_result.sec
current_monotonic_revision = " #{year}#{month}#{day}.#{hour}#{min}#{sec} "
current_revision = " #{year}#{month}#{day}.#{hour}#{min}#{sec} "
end
status = %x[ git status --porcelain ]
if status == ''
working_copy_is_clean = 1
else
lines_count = status.lines.count
if lines_count != 1
puts "Working copy is not clean because of status:\n#{status}"
puts
working_copy_is_clean = 0
else
wc_root = %[ git rev-parse --show-toplevel ]
modified_path = status[3..-1]
abs_modified_path = File.join(wc_root, modified_path)
if abs_modified_path == ENV['BUILD_ROOT']
working_copy_is_clean = 1
else
puts "Working copy is not clean because of status:\n#{status}"
puts
working_copy_is_clean = 0
end
end
end
when SCM_MERCURIAL
puts 'Mercurial working copy detected'
current_revision = %x[ hg id -i ]
current_monotonic_revision = %x[ hg id --num --rev tip ]
status = %x[ hg status ]
if status == ''
working_copy_is_clean = 1
else
lines_count = status.lines.count
if lines_count != 1
puts "Working copy is not clean because of status:\n#{status}"
puts
working_copy_is_clean = 0
else
wc_root = %[ hg root ]
modified_path = status[3..-1]
abs_modified_path = File.join(wc_root, modified_path)
if abs_modified_path == ENV['BUILD_ROOT']
working_copy_is_clean = 1
else
puts "Working copy is not clean because of status:\n#{status}"
puts
working_copy_is_clean = 0
end
end
end
else
puts 'warning: script must be run from working copy. Revision is undefined.'
current_revision = 'undefined'
current_monotonic_revision = 'undefined'
working_copy_is_clean = 0
end
return current_revision.strip!, current_monotonic_revision.strip!, working_copy_is_clean
end
|