mirror of
https://git.yoctoproject.org/poky-contrib
synced 2025-05-09 16:12:14 +08:00

This adds SPDX license headers in place of the wide assortment of things currently in our script headers. We default to GPL-2.0-only except for the oeqa code where it was clearly submitted and marked as MIT on the most part or some scripts which had the "or later" GPL versioning. The patch also drops other obsolete bits of file headers where they were encoountered such as editor modelines, obsolete maintainer information or the phrase "All rights reserved" which is now obsolete and not required in copyright headers (in this case its actually confusing for licensing as all rights were not reserved). More work is needed for OE-Core but this takes care of the bulk of the scripts and meta/lib directories. The top level LICENSE files are tweaked to match the new structure and the SPDX naming. (From OE-Core rev: f8c9c511b5f1b7dbd45b77f345cb6c048ae6763e) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
#
|
|
# Copyright (C) 2016 Intel Corporation
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
#
|
|
"""Git repository interactions"""
|
|
import os
|
|
|
|
from oeqa.utils.commands import runCmd
|
|
|
|
|
|
class GitError(Exception):
|
|
"""Git error handling"""
|
|
pass
|
|
|
|
class GitRepo(object):
|
|
"""Class representing a Git repository clone"""
|
|
def __init__(self, path, is_topdir=False):
|
|
git_dir = self._run_git_cmd_at(['rev-parse', '--git-dir'], path)
|
|
git_dir = git_dir if os.path.isabs(git_dir) else os.path.join(path, git_dir)
|
|
self.git_dir = os.path.realpath(git_dir)
|
|
|
|
if self._run_git_cmd_at(['rev-parse', '--is-bare-repository'], path) == 'true':
|
|
self.bare = True
|
|
self.top_dir = self.git_dir
|
|
else:
|
|
self.bare = False
|
|
self.top_dir = self._run_git_cmd_at(['rev-parse', '--show-toplevel'],
|
|
path)
|
|
realpath = os.path.realpath(path)
|
|
if is_topdir and realpath != self.top_dir:
|
|
raise GitError("{} is not a Git top directory".format(realpath))
|
|
|
|
@staticmethod
|
|
def _run_git_cmd_at(git_args, cwd, **kwargs):
|
|
"""Run git command at a specified directory"""
|
|
git_cmd = 'git ' if isinstance(git_args, str) else ['git']
|
|
git_cmd += git_args
|
|
ret = runCmd(git_cmd, ignore_status=True, cwd=cwd, **kwargs)
|
|
if ret.status:
|
|
cmd_str = git_cmd if isinstance(git_cmd, str) \
|
|
else ' '.join(git_cmd)
|
|
raise GitError("'{}' failed with exit code {}: {}".format(
|
|
cmd_str, ret.status, ret.output))
|
|
return ret.output.strip()
|
|
|
|
@staticmethod
|
|
def init(path, bare=False):
|
|
"""Initialize a new Git repository"""
|
|
cmd = ['init']
|
|
if bare:
|
|
cmd.append('--bare')
|
|
GitRepo._run_git_cmd_at(cmd, cwd=path)
|
|
return GitRepo(path, is_topdir=True)
|
|
|
|
def run_cmd(self, git_args, env_update=None):
|
|
"""Run Git command"""
|
|
env = None
|
|
if env_update:
|
|
env = os.environ.copy()
|
|
env.update(env_update)
|
|
return self._run_git_cmd_at(git_args, self.top_dir, env=env)
|
|
|
|
def rev_parse(self, revision):
|
|
"""Do git rev-parse"""
|
|
try:
|
|
return self.run_cmd(['rev-parse', '--verify', revision])
|
|
except GitError:
|
|
# Revision does not exist
|
|
return None
|
|
|
|
def get_current_branch(self):
|
|
"""Get current branch"""
|
|
try:
|
|
# Strip 11 chars, i.e. 'refs/heads' from the beginning
|
|
return self.run_cmd(['symbolic-ref', 'HEAD'])[11:]
|
|
except GitError:
|
|
return None
|
|
|
|
|