Skip to content

Commit

Permalink
Merge pull request #37 from rock-core/fix_submodule_handling
Browse files Browse the repository at this point in the history
Fix submodule handling
  • Loading branch information
doudou authored Aug 17, 2017
2 parents cd26a79 + eda8e55 commit 180e217
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/autobuild/import/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,10 @@ def update(package, options = Hash.new)
else
merge_if_simple(package, target_commit)
end

if with_submodules?
run_git(package, "submodule", "update", '--init')
end
end

# @api private
Expand Down Expand Up @@ -1095,8 +1099,8 @@ def relocate(repository, options = Hash.new)
@local_branch = local_branch
@remote_branch = remote_branch
end
@tag = options[:tag] || @tag
@commit = options[:commit] || @commit
@tag = options.fetch(:tag, @tag)
@commit = options.fetch(:commit, @commit)

@repository = repository.to_str
@repository_id = options[:repository_id] ||
Expand Down
11 changes: 11 additions & 0 deletions test/data/git-expand-tar
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/sh -e

gitrepo=$1
if ! test -f $gitrepo.tar; then
echo "$gitrepo.tar does not exist"
exit 1
fi

rm -rf $gitrepo $gitrepo.git
tar xf $gitrepo.tar
git clone $gitrepo.git $gitrepo
11 changes: 11 additions & 0 deletions test/data/git-make-tar
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/sh -e

gitrepo=$1
if ! test -d $gitrepo; then
echo "$gitrepo does not exist"
exit 1
fi

rm -rf $gitrepo.git $gitrepo.tar
git clone --bare $gitrepo $gitrepo.git
tar cf $gitrepo.tar $gitrepo.git
Binary file added test/data/gitrepo-submodule-child.tar
Binary file not shown.
Binary file added test/data/gitrepo-submodule-master.tar
Binary file not shown.
81 changes: 80 additions & 1 deletion test/import/test_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Autobuild::Git do
attr_reader :pkg, :importer, :gitrepo
before do
untar('gitrepo.tar')
tempdir = untar('gitrepo.tar')
@gitrepo = File.join(tempdir, 'gitrepo.git')
@pkg = Autobuild::Package.new 'test'
pkg.srcdir = File.join(tempdir, 'git')
Expand Down Expand Up @@ -504,5 +504,84 @@ def pin_importer(id, options = Hash.new)
common_commit_and_tag_behaviour
end
end

describe "submodule handling" do
before do
@master_root_commit = '8fc7584'
tempdir = untar 'gitrepo-submodule-master.tar'
untar 'gitrepo-submodule-child.tar'
srcdir = File.join(tempdir, 'gitrepo-submodule-master')
@pkg = Autobuild::Package.new 'submodule_test'
pkg.srcdir = srcdir
@importer = Autobuild.git("#{srcdir}.git", with_submodules: true)
pkg.importer = importer
end

describe "checkout" do
it "checkouts submodules" do
import
assert_checkout_file_exist 'child', '.git'
assert_equal "Commit 1\n", checkout_read('child', 'FILE')
end
it "checkouts submodules at the state of the tag/commit pin" do
import commit: @master_root_commit
assert_equal "Commit 0\n", checkout_read('child', 'FILE')
end
end

describe "update" do
it "updates submodules" do
import commit: @master_root_commit
import commit: nil
assert_equal "Commit 1\n", checkout_read('child', 'FILE')
end
it "initializes new submodules" do
import commit: @master_root_commit
FileUtils.rm_rf checkout_path('commit1_submodule')
import commit: nil
assert_equal "Commit 1\n", checkout_read('commit1_submodule', 'FILE')
end
end

describe "reset" do
it "resets submodules" do
import
force_reset commit: @master_root_commit
assert_equal "Commit 0\n", checkout_read('child', 'FILE')
end
it "initializes new submodules" do
import
refute_checkout_file_exist 'commit0_submodule'
force_reset commit: @master_root_commit
assert_equal "Commit 1\n", checkout_read('commit0_submodule', 'FILE')
end
end
end

def assert_checkout_file_exist(*file)
assert File.exist?(checkout_path(*file))
end
def refute_checkout_file_exist(*file)
refute File.exist?(checkout_path(*file))
end
def checkout_path(*file)
File.join(pkg.srcdir, *file)
end
def checkout_read(*file)
File.read(checkout_path(*file))
end
def force_reset(**options)
if !options.empty?
importer.relocate(importer.repository, **options)
end
importer.import(pkg, reset: :force)
end

def import(**options)
if !options.empty?
importer.relocate(importer.repository, **options)
end
importer.import(pkg)
end
end

0 comments on commit 180e217

Please sign in to comment.