tests: adjust create_repo() to keep working on newer git

On the git v2.32.0 that's currently running on the Arch Linux install
I use for day to day development, I'm getting errors when I run tox.

This is because the test cases assume that newly created repositories
have 'master' branches, which isn't true in general anymore unless you
ask for it explicitly.

To keep things working for now, add a kwarg to the create_repo()
helper that preserves the old way of doing things by forcing a master
branch to exist.

Use 'git init --initial-branch' for this if that's available, but
otherwise just fall back on 'git checkout -b' for older versions of
Git to keep things consistent.

Since git itself is moving away from an assumption of a default branch
named 'master', we're going to need to do the same thing in west when
it comes to the default project revision. But that's a problem for
another day; for now let's just keep things duct taped together with
existing assumptions, since revisiting that will require a manifest
schema change.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-07-23 15:44:57 -07:00 committed by Marti Bolivar
parent 39e1ffdcf0
commit 6d42388f20
1 changed files with 12 additions and 3 deletions

View File

@ -295,11 +295,20 @@ def create_workspace(workspace_dir, and_git=True):
if and_git: if and_git:
create_repo(mp) create_repo(mp)
def create_repo(path): def create_repo(path, initial_branch='master'):
# Initializes a Git repository in 'path', and adds an initial commit to it # Initializes a Git repository in 'path', and adds an initial
# commit to it in a new branch 'initial_branch'. We're currently
# keeping the old default initial branch to keep assumptions made
# elsewhere in the test code working with newer versions of git.
path = os.fspath(path) path = os.fspath(path)
subprocess.check_call([GIT, 'init', path]) if GIT_INIT_HAS_BRANCH:
subprocess.check_call([GIT, 'init', '--initial-branch', initial_branch,
path])
else:
subprocess.check_call([GIT, 'init', path])
subprocess.check_call([GIT, 'checkout', '-b', initial_branch],
cwd=path)
config_repo(path) config_repo(path)
add_commit(path, 'initial') add_commit(path, 'initial')