autobuild 1.8.3 → 1.9.0.b1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Manifest.txt +16 -7
- data/Rakefile +2 -0
- data/lib/autobuild/config.rb +21 -6
- data/lib/autobuild/configurable.rb +2 -2
- data/lib/autobuild/environment.rb +52 -27
- data/lib/autobuild/exceptions.rb +48 -22
- data/lib/autobuild/import/archive.rb +37 -16
- data/lib/autobuild/import/cvs.rb +26 -28
- data/lib/autobuild/import/darcs.rb +9 -8
- data/lib/autobuild/import/git.rb +324 -217
- data/lib/autobuild/import/hg.rb +6 -9
- data/lib/autobuild/import/svn.rb +190 -47
- data/lib/autobuild/importer.rb +80 -35
- data/lib/autobuild/package.rb +16 -35
- data/lib/autobuild/packages/autotools.rb +8 -8
- data/lib/autobuild/packages/cmake.rb +18 -12
- data/lib/autobuild/packages/genom.rb +1 -1
- data/lib/autobuild/packages/gnumake.rb +11 -12
- data/lib/autobuild/packages/orogen.rb +1 -1
- data/lib/autobuild/packages/ruby.rb +9 -5
- data/lib/autobuild/reporting.rb +10 -6
- data/lib/autobuild/subcommand.rb +110 -50
- data/lib/autobuild/test.rb +104 -0
- data/lib/autobuild/timestamps.rb +3 -3
- data/lib/autobuild/tools.rb +1 -1
- data/lib/autobuild/utility.rb +22 -10
- data/lib/autobuild/version.rb +1 -1
- data/test/data/gitrepo-with-extra-commit-and-tag.tar +0 -0
- data/test/data/gitrepo.tar +0 -0
- data/test/data/gitrepo/test +0 -0
- data/test/data/gitrepo/test2 +0 -0
- data/test/data/gitrepo/test3 +0 -0
- data/test/data/svnroot.tar +0 -0
- data/test/import/test_cvs.rb +51 -0
- data/test/import/test_git.rb +364 -0
- data/test/import/test_svn.rb +144 -0
- data/test/import/test_tar.rb +76 -0
- data/test/suite.rb +7 -0
- data/test/test_config.rb +1 -5
- data/test/test_environment.rb +88 -0
- data/test/test_reporting.rb +2 -14
- data/test/test_subcommand.rb +7 -22
- metadata +17 -14
- data/test/test_import_cvs.rb +0 -59
- data/test/test_import_svn.rb +0 -56
- data/test/test_import_tar.rb +0 -83
- data/test/tools.rb +0 -44
@@ -0,0 +1,104 @@
|
|
1
|
+
# simplecov must be loaded FIRST. Only the files required after it gets loaded
|
2
|
+
# will be profiled !!!
|
3
|
+
if ENV['TEST_ENABLE_COVERAGE'] == '1'
|
4
|
+
begin
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start
|
7
|
+
rescue LoadError
|
8
|
+
require 'autobuild'
|
9
|
+
Autobuild.warn "coverage is disabled because the 'simplecov' gem cannot be loaded"
|
10
|
+
rescue Exception => e
|
11
|
+
require 'autobuild'
|
12
|
+
Autobuild.warn "coverage is disabled: #{e.message}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'minitest/autorun'
|
17
|
+
require 'autobuild'
|
18
|
+
require 'tmpdir'
|
19
|
+
require 'erb'
|
20
|
+
require 'fileutils'
|
21
|
+
## Uncomment this to enable flexmock
|
22
|
+
require 'flexmock/test_unit'
|
23
|
+
require 'minitest/spec'
|
24
|
+
|
25
|
+
if ENV['TEST_ENABLE_PRY'] != '0'
|
26
|
+
begin
|
27
|
+
require 'pry'
|
28
|
+
rescue Exception
|
29
|
+
Autobuild.warn "debugging is disabled because the 'pry' gem cannot be loaded"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Autobuild
|
34
|
+
# This module is the common setup for all tests
|
35
|
+
#
|
36
|
+
# It should be included in the toplevel describe blocks
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# require 'autobuild/test'
|
40
|
+
# describe Autobuild do
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
module SelfTest
|
44
|
+
if defined? FlexMock
|
45
|
+
include FlexMock::ArgumentTypes
|
46
|
+
include FlexMock::MockContainer
|
47
|
+
end
|
48
|
+
|
49
|
+
def setup
|
50
|
+
@tempdir = File.join(Dir.tmpdir, "/autobuild-test-#{Process.uid}")
|
51
|
+
FileUtils.mkdir_p(@tempdir, :mode => 0700)
|
52
|
+
Autobuild.logdir = "#{tempdir}/log"
|
53
|
+
FileUtils.mkdir_p Autobuild.logdir
|
54
|
+
Autobuild.silent = true
|
55
|
+
# Setup code for all the tests
|
56
|
+
end
|
57
|
+
|
58
|
+
def teardown
|
59
|
+
Autobuild.silent = false
|
60
|
+
if defined? FlexMock
|
61
|
+
flexmock_teardown
|
62
|
+
end
|
63
|
+
super
|
64
|
+
|
65
|
+
Autobuild::Package.clear
|
66
|
+
|
67
|
+
if @tempdir
|
68
|
+
FileUtils.rm_rf @tempdir
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def data_dir
|
73
|
+
File.join(File.dirname(__FILE__), '..', '..', 'test', 'data')
|
74
|
+
end
|
75
|
+
|
76
|
+
attr_reader :tempdir
|
77
|
+
|
78
|
+
def build_config(bind, template)
|
79
|
+
eval "basedir = '#{self.tempdir}'", bind
|
80
|
+
ryml = File.open(File.join(data_dir, "#{template}.ryml")) { |f| f.readlines }.join('')
|
81
|
+
result = ERB.new(ryml).result(bind)
|
82
|
+
|
83
|
+
yml = File.join(tempdir, "#{template}.yml")
|
84
|
+
File.open(yml, 'w+') { |f| f.write(result) }
|
85
|
+
|
86
|
+
return yml
|
87
|
+
end
|
88
|
+
|
89
|
+
def untar(file)
|
90
|
+
file = File.expand_path(file, data_dir)
|
91
|
+
dir = self.tempdir
|
92
|
+
Dir.chdir(dir) do
|
93
|
+
system("tar xf #{file}")
|
94
|
+
end
|
95
|
+
|
96
|
+
dir
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Minitest::Test
|
102
|
+
include Autobuild::SelfTest
|
103
|
+
end
|
104
|
+
|
data/lib/autobuild/timestamps.rb
CHANGED
@@ -81,7 +81,7 @@ module Autobuild
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.get_stamp(stampfile)
|
84
|
-
return Time.at(0) if !File.
|
84
|
+
return Time.at(0) if !File.exist?(stampfile)
|
85
85
|
return File.mtime(stampfile)
|
86
86
|
end
|
87
87
|
|
@@ -99,9 +99,9 @@ module Autobuild
|
|
99
99
|
def self.touch_stamp(stampfile)
|
100
100
|
Autobuild.message "Touching #{stampfile}" if Autobuild.debug
|
101
101
|
dir = File.dirname(stampfile)
|
102
|
-
if File.
|
102
|
+
if File.exist?(dir) && !File.directory?(dir)
|
103
103
|
raise "#{dir} exists and is not a directory"
|
104
|
-
elsif !File.
|
104
|
+
elsif !File.exist?(dir)
|
105
105
|
FileUtils.mkdir_p dir
|
106
106
|
end
|
107
107
|
FileUtils.touch(stampfile)
|
data/lib/autobuild/tools.rb
CHANGED
data/lib/autobuild/utility.rb
CHANGED
@@ -14,8 +14,11 @@ module Autobuild
|
|
14
14
|
def initialize(name, package)
|
15
15
|
@name = name
|
16
16
|
@package = package
|
17
|
-
@
|
17
|
+
@available = true
|
18
|
+
@enabled = true
|
18
19
|
@source_ref_dir = nil
|
20
|
+
@source_dir = nil
|
21
|
+
@target_dir = nil
|
19
22
|
end
|
20
23
|
|
21
24
|
# Directory in which the utility will generate some files The
|
@@ -108,19 +111,28 @@ module Autobuild
|
|
108
111
|
# This will return true only if a task has been by calling {task} _and_
|
109
112
|
# the utility has not been explicitly disabled by setting the {enabled}
|
110
113
|
# attribute to false
|
114
|
+
#
|
115
|
+
# @return [Boolean]
|
116
|
+
def available?
|
117
|
+
@available && (source_dir && @task)
|
118
|
+
end
|
119
|
+
|
120
|
+
# True if this utility should be executed
|
121
|
+
#
|
122
|
+
# @return [Boolean]
|
111
123
|
def enabled?
|
112
|
-
|
113
|
-
return false
|
114
|
-
else
|
115
|
-
return source_dir && @task
|
116
|
-
end
|
124
|
+
@enabled && available?
|
117
125
|
end
|
118
126
|
|
119
|
-
# Allows to
|
120
|
-
#
|
127
|
+
# Allows to override the utility's availability (i.e. whether this
|
128
|
+
# utility is available on the underlying package) regardless of whether
|
129
|
+
# {task} got called or not
|
121
130
|
#
|
122
|
-
# This is mainly used
|
123
|
-
#
|
131
|
+
# This is mainly used to fine-tune packages whose base type enables the
|
132
|
+
# utility (e.g. testing) but the actual package does not have it
|
133
|
+
attr_writer :available
|
134
|
+
|
135
|
+
# Allows to disable the utility regardless of the value of {available?}
|
124
136
|
attr_writer :enabled
|
125
137
|
|
126
138
|
def install
|
data/lib/autobuild/version.rb
CHANGED
Binary file
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
data/test/data/svnroot.tar
CHANGED
Binary file
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'autobuild/test'
|
2
|
+
|
3
|
+
class TC_CVSImport < Minitest::Test
|
4
|
+
include Autobuild
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
Autobuild.logdir = "#{tempdir}/log"
|
9
|
+
FileUtils.mkdir_p(Autobuild.logdir)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_cvs
|
13
|
+
Autobuild.verbose = true
|
14
|
+
untar('cvsroot.tar')
|
15
|
+
cvsroot = File.join(tempdir, 'cvsroot')
|
16
|
+
pkg_cvs = Package.new 'cvs'
|
17
|
+
pkg_cvs.srcdir = File.join(tempdir, 'cvs')
|
18
|
+
|
19
|
+
# Make a checkout
|
20
|
+
importer = Autobuild.cvs(cvsroot, module: 'cvs')
|
21
|
+
importer.import(pkg_cvs)
|
22
|
+
assert( File.exists?(File.join(pkg_cvs.srcdir, 'test')) )
|
23
|
+
|
24
|
+
# Make an update
|
25
|
+
importer.import(pkg_cvs)
|
26
|
+
|
27
|
+
# Make an update fail because the repository does not exist anymore
|
28
|
+
FileUtils.rm_rf cvsroot
|
29
|
+
assert_raises(Autobuild::SubcommandFailed) { importer.import pkg_cvs }
|
30
|
+
|
31
|
+
# Make a checkout fail because the repository does not exist anymore
|
32
|
+
FileUtils.rm_rf pkg_cvs.srcdir
|
33
|
+
assert_raises(Autobuild::SubcommandFailed) { importer.import pkg_cvs }
|
34
|
+
|
35
|
+
# Recreate the repository, and make a checkout fail because the
|
36
|
+
# WC is not a CVS WC
|
37
|
+
untar('cvsroot.tar')
|
38
|
+
FileUtils.mkdir pkg_cvs.srcdir
|
39
|
+
assert_raises(Autobuild::ConfigException) { importer.import pkg_cvs }
|
40
|
+
|
41
|
+
# Create two repositories, and make the update fail because the
|
42
|
+
# WC is of the wrong source
|
43
|
+
FileUtils.rm_rf pkg_cvs.srcdir
|
44
|
+
importer.import(pkg_cvs)
|
45
|
+
FileUtils.mv cvsroot, "#{cvsroot}.2"
|
46
|
+
importer = Autobuild.cvs("#{cvsroot}.2", module: 'cvs')
|
47
|
+
assert_raises(Autobuild::ConfigException) { importer.import pkg_cvs }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
@@ -0,0 +1,364 @@
|
|
1
|
+
require 'autobuild/test'
|
2
|
+
|
3
|
+
describe Autobuild::Git do
|
4
|
+
attr_reader :pkg, :importer, :gitrepo
|
5
|
+
before do
|
6
|
+
untar('gitrepo.tar')
|
7
|
+
@gitrepo = File.join(tempdir, 'gitrepo.git')
|
8
|
+
@pkg = Autobuild::Package.new 'test'
|
9
|
+
pkg.srcdir = File.join(tempdir, 'git')
|
10
|
+
@importer = Autobuild.git(gitrepo)
|
11
|
+
pkg.importer = importer
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#initialize" do
|
15
|
+
it "allows passing the branch as second argument for backward-compatibility way" do
|
16
|
+
Autobuild.silent = true
|
17
|
+
importer = Autobuild::Git.new('repo', 'branch', tag: 'test')
|
18
|
+
assert_equal 'branch', importer.branch
|
19
|
+
end
|
20
|
+
it "raises ConfigException if the branch parameter and the branch options are both given" do
|
21
|
+
Autobuild.silent = true
|
22
|
+
assert_raises(Autobuild::ConfigException) do
|
23
|
+
Autobuild::Git.new('repo', 'branch', branch: 'another')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "version_compare" do
|
29
|
+
it "should return -1 if the actual version is greater" do
|
30
|
+
assert_equal(-1, Autobuild::Git.compare_versions([2, 1, 0], [2, 0, 1]))
|
31
|
+
end
|
32
|
+
it "should return 0 if the versions are equal" do
|
33
|
+
assert_equal(0, Autobuild::Git.compare_versions([2, 1, 0], [2, 1, 0]))
|
34
|
+
end
|
35
|
+
it "should return 1 if the required version is greater" do
|
36
|
+
assert_equal(1, Autobuild::Git.compare_versions([2, 0, 1], [2, 1, 0]))
|
37
|
+
assert_equal(1, Autobuild::Git.compare_versions([1, 9, 1], [2, 1, 0]))
|
38
|
+
end
|
39
|
+
it "should fill missing version parts with zeros" do
|
40
|
+
assert_equal(-1, Autobuild::Git.compare_versions([2, 1], [2, 0, 1]))
|
41
|
+
assert_equal(-1, Autobuild::Git.compare_versions([2, 1, 0], [2, 0]))
|
42
|
+
assert_equal(0, Autobuild::Git.compare_versions([2, 1], [2, 1, 0]))
|
43
|
+
assert_equal(0, Autobuild::Git.compare_versions([2, 1, 0], [2, 1]))
|
44
|
+
assert_equal(1, Autobuild::Git.compare_versions([2, 1], [2, 1, 1]))
|
45
|
+
assert_equal(1, Autobuild::Git.compare_versions([2, 1, 1], [2, 2]))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "at_least_version" do
|
50
|
+
Autobuild::Git.stub :version, [1,9,1] do
|
51
|
+
it "should be true if required version is smaller" do
|
52
|
+
assert_equal( true, Autobuild::Git.at_least_version( 1,8,1 ) )
|
53
|
+
end
|
54
|
+
it "should be false if required version is greater" do
|
55
|
+
assert_equal( false, Autobuild::Git.at_least_version( 50,0,1 ) )
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#has_commit?" do
|
61
|
+
before do
|
62
|
+
importer.import(pkg)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns true if the specified name resolves to a commit" do
|
66
|
+
assert importer.has_commit?(pkg, importer.rev_parse(pkg, 'HEAD'))
|
67
|
+
end
|
68
|
+
it "returns true if the specified commit is present locally" do
|
69
|
+
assert importer.has_commit?(pkg, importer.rev_parse(pkg, '8b09cb0febae222b31e2ee55f839c1e00dc7edc4'))
|
70
|
+
end
|
71
|
+
it "returns false if the specified name does not resolve to an object" do
|
72
|
+
assert !importer.has_commit?(pkg, 'blabla')
|
73
|
+
end
|
74
|
+
it "returns false if the specified commit is not present locally" do
|
75
|
+
assert !importer.has_commit?(pkg, '1ddb20665622279700770be09f9a291b37c9b631')
|
76
|
+
end
|
77
|
+
it "raises for any other error" do
|
78
|
+
flexmock(Autobuild::Subprocess).should_receive(:run).
|
79
|
+
and_raise(Autobuild::SubcommandFailed.new('test', 'test', 'bla', 200))
|
80
|
+
assert_raises(Autobuild::SubcommandFailed) do
|
81
|
+
importer.has_commit?(pkg, 'master')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#has_branch?" do
|
87
|
+
before do
|
88
|
+
importer.import(pkg)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns true if the branch exists" do
|
92
|
+
assert importer.has_branch?(pkg, 'master')
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns false if the branch does not exist" do
|
96
|
+
assert !importer.has_branch?(pkg, 'does_not_exist')
|
97
|
+
end
|
98
|
+
|
99
|
+
it "raises for any other error" do
|
100
|
+
flexmock(Autobuild::Subprocess).should_receive(:run).
|
101
|
+
and_raise(Autobuild::SubcommandFailed.new('test', 'test', 'bla', 200))
|
102
|
+
assert_raises(Autobuild::SubcommandFailed) do
|
103
|
+
importer.has_branch?(pkg, 'master')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#detached_head?" do
|
109
|
+
before do
|
110
|
+
importer.import(pkg)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns true if HEAD is detached" do
|
114
|
+
importer.run_git(pkg, 'checkout', 'master~1')
|
115
|
+
assert importer.detached_head?(pkg)
|
116
|
+
end
|
117
|
+
it "returns false if HEAD is pointing to a branch" do
|
118
|
+
assert !importer.detached_head?(pkg)
|
119
|
+
end
|
120
|
+
it "raises for any other error" do
|
121
|
+
flexmock(Autobuild::Subprocess).should_receive(:run).
|
122
|
+
and_raise(Autobuild::SubcommandFailed.new('test', 'test', 'bla', 200))
|
123
|
+
assert_raises(Autobuild::SubcommandFailed) do
|
124
|
+
importer.detached_head?(pkg)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#current_branch" do
|
130
|
+
before do
|
131
|
+
importer.import(pkg)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns the current branch name" do
|
135
|
+
importer.run_git(pkg, 'checkout', '-b', 'test')
|
136
|
+
assert_equal 'refs/heads/test', importer.current_branch(pkg)
|
137
|
+
end
|
138
|
+
it "returns nil if the head is detached" do
|
139
|
+
importer.run_git(pkg, 'checkout', 'master~1')
|
140
|
+
assert importer.current_branch(pkg).nil?
|
141
|
+
end
|
142
|
+
it "raises for any other error" do
|
143
|
+
flexmock(Autobuild::Subprocess).should_receive(:run).
|
144
|
+
and_raise(Autobuild::SubcommandFailed.new('test', 'test', 'bla', 200))
|
145
|
+
assert_raises(Autobuild::SubcommandFailed) do
|
146
|
+
importer.current_branch(pkg)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "#rev_parse" do
|
152
|
+
it "raises PackageException if the name does not exist" do
|
153
|
+
importer.import(pkg)
|
154
|
+
assert_raises(Autobuild::PackageException) do
|
155
|
+
importer.rev_parse(pkg, 'does_not_exist')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#show" do
|
161
|
+
it "returns the content of a path at a commit" do
|
162
|
+
importer.import(pkg)
|
163
|
+
File.open(File.join(tempdir, 'git', 'test'), 'a') do |io|
|
164
|
+
io.puts "newline"
|
165
|
+
end
|
166
|
+
head = importer.rev_parse(pkg, 'HEAD')
|
167
|
+
importer.run_git(pkg, 'commit', '-a', '-m', 'test commit')
|
168
|
+
assert_equal '', importer.show(pkg, head, 'test')
|
169
|
+
assert_equal 'newline', importer.show(pkg, 'HEAD', 'test')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe ".has_uncommitted_changes?" do
|
174
|
+
before do
|
175
|
+
importer.import(pkg)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "returns true if some files is modified" do
|
179
|
+
File.open(File.join(tempdir, 'git', 'test'), 'a') do |io|
|
180
|
+
io.puts "newline"
|
181
|
+
end
|
182
|
+
assert Autobuild::Git.has_uncommitted_changes?(pkg)
|
183
|
+
end
|
184
|
+
it "returns true if some files is modified and staged" do
|
185
|
+
file = File.join(tempdir, 'git', 'test')
|
186
|
+
File.open(file, 'a') { |io| io.puts "newline" }
|
187
|
+
importer.run_git(pkg, 'add', file)
|
188
|
+
assert Autobuild::Git.has_uncommitted_changes?(pkg)
|
189
|
+
end
|
190
|
+
it "returns true if a new file is added" do
|
191
|
+
newfile = File.join(tempdir, 'git', 'blabla')
|
192
|
+
FileUtils.touch newfile
|
193
|
+
importer.run_git(pkg, 'add', newfile)
|
194
|
+
assert Autobuild::Git.has_uncommitted_changes?(pkg)
|
195
|
+
end
|
196
|
+
it "returns true if a file has been removed" do
|
197
|
+
FileUtils.rm_f File.join(tempdir, 'git', 'test')
|
198
|
+
assert Autobuild::Git.has_uncommitted_changes?(pkg)
|
199
|
+
end
|
200
|
+
it "returns true if a file has been removed and staged" do
|
201
|
+
delfile = File.join(tempdir, 'git', 'test')
|
202
|
+
FileUtils.rm_f delfile
|
203
|
+
importer.run_git(pkg, 'rm', delfile)
|
204
|
+
assert Autobuild::Git.has_uncommitted_changes?(pkg)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "update" do
|
209
|
+
def self.common_commit_and_tag_behaviour
|
210
|
+
|
211
|
+
it "does not access the repository if the target is already merged and reset is false" do
|
212
|
+
importer.import(pkg)
|
213
|
+
|
214
|
+
# We relocate to a non-existing repository to ensure that it
|
215
|
+
# does not try to access it
|
216
|
+
importer.relocate('/does/not/exist')
|
217
|
+
pin_importer(1)
|
218
|
+
importer.import(pkg, reset: false)
|
219
|
+
assert_on_commit 0
|
220
|
+
end
|
221
|
+
it "does not access the repository if the target is already HEAD and reset is true" do
|
222
|
+
importer.import(pkg)
|
223
|
+
pin_importer(0)
|
224
|
+
importer.relocate('/does/not/exist')
|
225
|
+
importer.import(pkg, reset: true)
|
226
|
+
assert_on_commit 0
|
227
|
+
end
|
228
|
+
it "does not access the remote repository if the commit is present locally" do
|
229
|
+
pin_importer(1)
|
230
|
+
importer.import(pkg)
|
231
|
+
pin_importer(0)
|
232
|
+
importer.relocate('/does/not/exist')
|
233
|
+
importer.import(pkg, reset: false)
|
234
|
+
assert_on_commit 0
|
235
|
+
end
|
236
|
+
it "attempts to merge the target commit if it is not present in HEAD" do
|
237
|
+
pin_importer(1)
|
238
|
+
importer.import(pkg)
|
239
|
+
pin_importer(0)
|
240
|
+
importer.import(pkg, reset: false)
|
241
|
+
assert_on_commit 0
|
242
|
+
end
|
243
|
+
it "resets if reset is true" do
|
244
|
+
importer.import(pkg)
|
245
|
+
pin_importer(1)
|
246
|
+
importer.import(pkg, reset: true)
|
247
|
+
assert_on_commit 1
|
248
|
+
end
|
249
|
+
it "refuses to reset if some commits are present locally but not in the remote branch" do
|
250
|
+
importer.import(pkg)
|
251
|
+
File.open(File.join(tempdir, 'git', 'test3'), 'w') do |io|
|
252
|
+
io.puts "test"
|
253
|
+
end
|
254
|
+
importer.run_git(pkg, 'add', 'test3')
|
255
|
+
importer.run_git(pkg, 'commit', '-a', '-m', 'third commit')
|
256
|
+
current_head = importer.rev_parse(pkg, 'HEAD')
|
257
|
+
pin_importer(1)
|
258
|
+
assert_raises(Autobuild::ImporterCannotReset) do
|
259
|
+
importer.import(pkg, reset: true)
|
260
|
+
end
|
261
|
+
assert_equal current_head, importer.rev_parse(pkg, 'HEAD')
|
262
|
+
end
|
263
|
+
it "creates the local branch at the specified commit if the branch does not exist" do
|
264
|
+
importer.import(pkg)
|
265
|
+
head = importer.rev_parse(pkg, 'HEAD')
|
266
|
+
importer.local_branch = 'local'
|
267
|
+
importer.import(pkg)
|
268
|
+
assert_equal 'refs/heads/local', importer.current_branch(pkg)
|
269
|
+
assert_equal head, importer.rev_parse(pkg, 'HEAD')
|
270
|
+
end
|
271
|
+
|
272
|
+
it "acts on local_branch" do
|
273
|
+
importer.import(pkg)
|
274
|
+
head = importer.rev_parse(pkg, 'HEAD')
|
275
|
+
importer.run_git(pkg, 'reset', '--hard', 'master~1')
|
276
|
+
importer.run_git(pkg, 'branch', 'local')
|
277
|
+
importer.local_branch = 'local'
|
278
|
+
importer.import(pkg)
|
279
|
+
assert_equal 'refs/heads/local', importer.current_branch(pkg)
|
280
|
+
assert_equal head, importer.rev_parse(pkg, 'refs/remotes/autobuild/master')
|
281
|
+
end
|
282
|
+
|
283
|
+
it "refuses to update if the local and remote branches have diverged" do
|
284
|
+
importer.import(pkg)
|
285
|
+
importer.run_git(pkg, 'reset', '--hard', 'master~1')
|
286
|
+
File.open(File.join(tempdir, 'git', 'test'), 'a') do |io|
|
287
|
+
io.puts "test"
|
288
|
+
end
|
289
|
+
importer.run_git(pkg, 'commit', '-a', '-m', 'a fork commit')
|
290
|
+
assert_raises(Autobuild::PackageException) do
|
291
|
+
importer.import(pkg)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
describe "with a specific commit given" do
|
296
|
+
def assert_on_commit(id)
|
297
|
+
assert_equal commits[id], importer.rev_parse(pkg, 'HEAD')
|
298
|
+
end
|
299
|
+
def commits
|
300
|
+
if !@commits
|
301
|
+
importer = Autobuild.git(gitrepo)
|
302
|
+
pkg = Autobuild::Package.new 'commits'
|
303
|
+
pkg.srcdir = gitrepo
|
304
|
+
pkg.importer = importer
|
305
|
+
@commits = [
|
306
|
+
importer.rev_parse(pkg, 'HEAD'),
|
307
|
+
importer.rev_parse(pkg, 'HEAD~1')]
|
308
|
+
end
|
309
|
+
@commits
|
310
|
+
end
|
311
|
+
|
312
|
+
def pin_importer(id, options = Hash.new)
|
313
|
+
importer.relocate(importer.repository, options.merge(commit: commits[id]))
|
314
|
+
end
|
315
|
+
|
316
|
+
it "fetches from the remote repository if the commit is not present locally" do
|
317
|
+
untar('gitrepo-with-extra-commit-and-tag.tar')
|
318
|
+
importer.import(pkg)
|
319
|
+
extra_repo = File.join(tempdir, 'gitrepo-with-extra-commit-and-tag.git')
|
320
|
+
importer.relocate(extra_repo, commit: '1ddb20665622279700770be09f9a291b37c9b631')
|
321
|
+
importer.import(pkg, reset: false)
|
322
|
+
assert_equal '1ddb20665622279700770be09f9a291b37c9b631', importer.rev_parse(pkg, 'HEAD')
|
323
|
+
end
|
324
|
+
|
325
|
+
common_commit_and_tag_behaviour
|
326
|
+
end
|
327
|
+
describe "with a specific tag given" do
|
328
|
+
attr_reader :commits
|
329
|
+
|
330
|
+
before do
|
331
|
+
importer = Autobuild.git(gitrepo)
|
332
|
+
pkg = Autobuild::Package.new 'commits'
|
333
|
+
pkg.srcdir = gitrepo
|
334
|
+
pkg.importer = importer
|
335
|
+
importer.run_git_bare(pkg, 'tag', "tag0", "HEAD")
|
336
|
+
importer.run_git_bare(pkg, 'tag', "tag1", "HEAD~1")
|
337
|
+
@commits = [
|
338
|
+
importer.rev_parse(pkg, 'HEAD'),
|
339
|
+
importer.rev_parse(pkg, 'HEAD~1')]
|
340
|
+
end
|
341
|
+
|
342
|
+
def assert_on_commit(id)
|
343
|
+
assert_equal commits[id], importer.rev_parse(pkg, 'HEAD')
|
344
|
+
end
|
345
|
+
|
346
|
+
def pin_importer(id, options = Hash.new)
|
347
|
+
importer.relocate(importer.repository, options.merge(tag: "tag#{id}"))
|
348
|
+
end
|
349
|
+
|
350
|
+
it "fetches from the remote repository if the commit is not present locally" do
|
351
|
+
untar('gitrepo-with-extra-commit-and-tag.tar')
|
352
|
+
importer.import(pkg)
|
353
|
+
extra_repo = File.join(tempdir, 'gitrepo-with-extra-commit-and-tag.git')
|
354
|
+
importer.relocate(extra_repo, tag: 'third_commit')
|
355
|
+
importer.import(pkg, reset: false)
|
356
|
+
tag_id = importer.rev_parse(pkg, 'third_commit')
|
357
|
+
assert_equal tag_id, importer.rev_parse(pkg, 'HEAD')
|
358
|
+
end
|
359
|
+
|
360
|
+
common_commit_and_tag_behaviour
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|