Clone the source code of the branches during the build

This commit removes the shared git repository in the root directory:
instead, a 1-depth clone of the branch is done at the start of each
build, so the source code is guaranteed to be fresh.

This doesn't affect build times so much, because only the latest commit
is cloned, not the whole history.
parent c49b31b3
......@@ -75,7 +75,7 @@ def init_command(ctx, git_url):
error("root directory not empty")
root.mkdir(parents=True)
for dir in ("git", "branches"):
for dir in ("branches",):
(root / dir).mkdir()
with (root / "version").open("w") as f:
......@@ -83,6 +83,7 @@ def init_command(ctx, git_url):
with (root / "config.json").open("w") as f:
content = {
"git-url": git_url,
"gitlab-url": "http://code.ubuntu-it.org",
"gitlab-project": "ubuntu-it-web/www",
"gitlab-token": "abcdefghi",
......@@ -101,8 +102,6 @@ def init_command(ctx, git_url):
json.dump(content, f, indent=4)
f.write("\n")
subprocess.call(["git", "clone", git_url, str(root / "git"), "--bare"])
@cli.command("run")
@click.option("-p", "--port", help="The port for the frontend application",
......
......@@ -206,7 +206,7 @@ class Branch:
shutil.rmtree(str(branch))
branch.mkdir()
git_dir = str(self.manager.root / "git")
git_url = self.manager.config["git-url"]
build_dir = branch / "build"
log_file = branch / "build.log"
......@@ -227,19 +227,16 @@ class Branch:
# Update the bare git repository and checkout the branch
subprocess.call([
"git", "--git-dir", git_dir, "fetch", "origin"
], stdout=log_file.open("a"), stderr=subprocess.STDOUT)
subprocess.call([
"git", "--git-dir", git_dir, "--work-tree", str(build_dir),
"checkout", "-f", self.name,
"git", "clone", "--depth", "1", "--branch", self.name, git_url,
str(build_dir),
], stdout=log_file.open("a"), stderr=subprocess.STDOUT)
# Get the commit of the branch
commit_file = branch / "commit"
subprocess.call(
["git", "--git-dir", git_dir, "rev-parse", self.name],
stdout=commit_file.open("w"), stderr=log_file.open("a"),
)
subprocess.call([
"git", "--git-dir", str(build_dir / ".git"), "rev-parse",
self.name
], stdout=commit_file.open("w"), stderr=log_file.open("a"))
# Copy and load the configuration file
if not (build_dir / "managetests.json").exists():
......
......@@ -17,7 +17,7 @@
import pathlib
ROOT_DIR_VERSION = "1"
ROOT_DIR_VERSION = "2"
def is_root_valid(path):
......@@ -27,7 +27,7 @@ def is_root_valid(path):
if not (path.exists() and path.is_dir()):
return False
required_dirs = ["git", "branches"]
required_dirs = ["branches"]
required_files = ["config.json", "details.json", "version"]
for dir in required_dirs:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment