From bfebd18982c0c82ef2da63ec8f22175c93b2e308 Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Fri, 29 Sep 2017 16:56:20 +1300 Subject: devtool: finish: ensure repository is clean before proceeding If the git repository for a recipe in the workspace has uncommitted changes in it then it's possible that the user has forgotten to commit something, so check and exit if there are any. Provide a -f/--force option to continue in the case where the uncommitted changes aren't needed. Separately, if the repository is in the middle of a rebase or git am / apply then error out (without the opportunity to force) since the user really needs to sort this out before finishing. Signed-off-by: Paul Eggleton Signed-off-by: Ross Burton --- scripts/lib/devtool/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'scripts/lib/devtool/__init__.py') diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py index 20ab83f83d..07d774dfb7 100644 --- a/scripts/lib/devtool/__init__.py +++ b/scripts/lib/devtool/__init__.py @@ -350,3 +350,20 @@ def check_prerelease_version(ver, operation): 'If you prefer not to reset and re-try, you can change ' 'the version after %s succeeds using "devtool rename" ' 'with -V/--version.' % (ver, operation)) + +def check_git_repo_dirty(repodir): + """Check if a git repository is clean or not""" + stdout, _ = bb.process.run('git status --porcelain', cwd=repodir) + return stdout + +def check_git_repo_op(srctree, ignoredirs=None): + """Check if a git repository is in the middle of a rebase""" + stdout, _ = bb.process.run('git rev-parse --show-toplevel', cwd=srctree) + topleveldir = stdout.strip() + if ignoredirs and topleveldir in ignoredirs: + return + gitdir = os.path.join(topleveldir, '.git') + if os.path.exists(os.path.join(gitdir, 'rebase-merge')): + raise DevtoolError("Source tree %s appears to be in the middle of a rebase - please resolve this first" % srctree) + if os.path.exists(os.path.join(gitdir, 'rebase-apply')): + raise DevtoolError("Source tree %s appears to be in the middle of 'git am' or 'git apply' - please resolve this first" % srctree) -- cgit v1.2.3