1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
8 # Commit log for "foo" repository in test.git.tar
9 # master is the main branch
10 # b1 is a branch off of master
19 def self.included base
21 # Extract the test repository data into the default test
22 # environment's Rails.configuration.git_repositories_dir. (We
23 # don't use that config setting here, though: it doesn't seem
24 # worth the risk of stepping on a real git repo root.)
25 @tmpdir = Rails.root.join 'tmp', 'git'
26 FileUtils.mkdir_p @tmpdir
27 system("tar", "-xC", @tmpdir.to_s, "-f", "test/test.git.tar")
28 Rails.configuration.git_repositories_dir = "#{@tmpdir}/test"
30 # Initialize an empty internal git repo.
32 Rails.configuration.git_internal_dir =
33 Rails.root.join(@tmpdir, 'internal.git').to_s
34 FileUtils.mkdir_p intdir
35 IO.read("|git --git-dir #{intdir.shellescape} init")
40 FileUtils.remove_entry @tmpdir, true
41 FileUtils.remove_entry Commit.cache_dir_base, true
46 IO.read "|git --git-dir #{Rails.configuration.git_internal_dir.shellescape} log --format=format:%H -n1 #{tag.shellescape}"
49 # Intercept fetch_remote_repository and fetch from a specified url
50 # or local fixture instead of the remote url requested. fakeurl can
51 # be a url (probably starting with file:///) or the name of a
52 # fixture (as a symbol)
53 def fetch_remote_from_local_repo url, fakeurl
54 if fakeurl.is_a? Symbol
55 fakeurl = 'file://' + repositories(fakeurl).server_path
57 Commit.expects(:fetch_remote_repository).once.with do |gitdir, giturl|
59 Commit.unstub(:fetch_remote_repository)
60 Commit.fetch_remote_repository gitdir, fakeurl