Added update_repositories command line argument to refresh git repositories. And added recipe for Criterion.

This commit is contained in:
2023-08-05 18:01:31 +02:00
parent acffaa9928
commit 1988bcc99b
3 changed files with 53 additions and 2 deletions

View File

@@ -11,15 +11,23 @@ def cook(env: Environment, repo_name: str, remote_url: str, git_ref: str = "main
repo = Repo(repo_dir)
origin = repo.remotes['origin']
except GitError:
print(f'Initializing git repository for SDL at {repo_dir}.')
print(f'Initializing git repository at {repo_dir}.')
repo = Repo.init(repo_dir, bare=True)
origin = repo.create_remote('origin', remote_url)
worktree_dir = os.path.join(env['CLONE_DIR'], 'git', repo_name, hashlib.shake_128(git_ref.encode('utf-8')).hexdigest(6)) # TODO: commit hash would be better, right?
worktree_dir = os.path.join(env['CLONE_DIR'], 'git', repo_name, hashlib.shake_128(git_ref.encode('utf-8')).hexdigest(6)) # TODO: commit hash would be better, right? -> not if it's a branch!
if not os.path.exists(worktree_dir):
print(f'Checking out into {worktree_dir}.')
origin.fetch()
os.makedirs(worktree_dir)
repo.git.worktree('add', worktree_dir, git_ref)
elif env['UPDATE_REPOSITORIES']:
worktree_repo = Repo(worktree_dir)
if not worktree_repo.head.is_detached:
print(f'Updating git repository at {worktree_dir}')
worktree_origin = worktree_repo.remotes['origin']
worktree_origin.pull()
else:
print(f'Not updating git repository {worktree_dir} as it is not on a branch.')
return {
'checkout_root': worktree_dir
}