diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2017-09-29 16:56:20 +1300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-11-11 12:14:27 +0000 |
commit | fe85a2a8b4adb9671ad308e75fc3d1f2c5e08916 (patch) | |
tree | 788a3b438f73f23dd7d09fdb94e9a020d42014a1 | |
parent | d5ffd41a93b7ccacca9ab997d9918920485c27a9 (diff) | |
download | poky-fe85a2a8b4adb9671ad308e75fc3d1f2c5e08916.tar.gz |
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.
(From OE-Core rev: bfebd18982c0c82ef2da63ec8f22175c93b2e308)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | scripts/lib/devtool/__init__.py | 17 | ||||
-rw-r--r-- | scripts/lib/devtool/standard.py | 17 |
2 files changed, 32 insertions, 2 deletions
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): | |||
350 | 'If you prefer not to reset and re-try, you can change ' | 350 | 'If you prefer not to reset and re-try, you can change ' |
351 | 'the version after %s succeeds using "devtool rename" ' | 351 | 'the version after %s succeeds using "devtool rename" ' |
352 | 'with -V/--version.' % (ver, operation)) | 352 | 'with -V/--version.' % (ver, operation)) |
353 | |||
354 | def check_git_repo_dirty(repodir): | ||
355 | """Check if a git repository is clean or not""" | ||
356 | stdout, _ = bb.process.run('git status --porcelain', cwd=repodir) | ||
357 | return stdout | ||
358 | |||
359 | def check_git_repo_op(srctree, ignoredirs=None): | ||
360 | """Check if a git repository is in the middle of a rebase""" | ||
361 | stdout, _ = bb.process.run('git rev-parse --show-toplevel', cwd=srctree) | ||
362 | topleveldir = stdout.strip() | ||
363 | if ignoredirs and topleveldir in ignoredirs: | ||
364 | return | ||
365 | gitdir = os.path.join(topleveldir, '.git') | ||
366 | if os.path.exists(os.path.join(gitdir, 'rebase-merge')): | ||
367 | raise DevtoolError("Source tree %s appears to be in the middle of a rebase - please resolve this first" % srctree) | ||
368 | if os.path.exists(os.path.join(gitdir, 'rebase-apply')): | ||
369 | raise DevtoolError("Source tree %s appears to be in the middle of 'git am' or 'git apply' - please resolve this first" % srctree) | ||
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py index 9bd2d8613d..7fee304572 100644 --- a/scripts/lib/devtool/standard.py +++ b/scripts/lib/devtool/standard.py | |||
@@ -30,7 +30,7 @@ import errno | |||
30 | import glob | 30 | import glob |
31 | import filecmp | 31 | import filecmp |
32 | from collections import OrderedDict | 32 | from collections import OrderedDict |
33 | from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, use_external_build, setup_git_repo, recipe_to_append, get_bbclassextend_targets, update_unlockedsigs, check_prerelease_version, DevtoolError | 33 | from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, use_external_build, setup_git_repo, recipe_to_append, get_bbclassextend_targets, update_unlockedsigs, check_prerelease_version, check_git_repo_dirty, check_git_repo_op, DevtoolError |
34 | from devtool import parse_recipe | 34 | from devtool import parse_recipe |
35 | 35 | ||
36 | logger = logging.getLogger('devtool') | 36 | logger = logging.getLogger('devtool') |
@@ -1675,6 +1675,18 @@ def finish(args, config, basepath, workspace): | |||
1675 | 1675 | ||
1676 | check_workspace_recipe(workspace, args.recipename) | 1676 | check_workspace_recipe(workspace, args.recipename) |
1677 | 1677 | ||
1678 | # Grab the equivalent of COREBASE without having to initialise tinfoil | ||
1679 | corebasedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')) | ||
1680 | |||
1681 | srctree = workspace[args.recipename]['srctree'] | ||
1682 | check_git_repo_op(srctree, [corebasedir]) | ||
1683 | dirty = check_git_repo_dirty(srctree) | ||
1684 | if dirty: | ||
1685 | if args.force: | ||
1686 | logger.warning('Source tree is not clean, continuing as requested by -f/--force') | ||
1687 | else: | ||
1688 | raise DevtoolError('Source tree is not clean:\n\n%s\nEnsure you have committed your changes or use -f/--force if you are sure there\'s nothing that needs to be committed' % dirty) | ||
1689 | |||
1678 | no_clean = False | 1690 | no_clean = False |
1679 | tinfoil = setup_tinfoil(basepath=basepath, tracking=True) | 1691 | tinfoil = setup_tinfoil(basepath=basepath, tracking=True) |
1680 | try: | 1692 | try: |
@@ -1867,10 +1879,11 @@ def register_commands(subparsers, context): | |||
1867 | parser_reset.set_defaults(func=reset) | 1879 | parser_reset.set_defaults(func=reset) |
1868 | 1880 | ||
1869 | parser_finish = subparsers.add_parser('finish', help='Finish working on a recipe in your workspace', | 1881 | parser_finish = subparsers.add_parser('finish', help='Finish working on a recipe in your workspace', |
1870 | description='Pushes any committed changes to the specified recipe to the specified layer and removes it from your workspace. Roughly equivalent to an update-recipe followed by reset, except the update-recipe step will do the "right thing" depending on the recipe and the destination layer specified.', | 1882 | description='Pushes any committed changes to the specified recipe to the specified layer and removes it from your workspace. Roughly equivalent to an update-recipe followed by reset, except the update-recipe step will do the "right thing" depending on the recipe and the destination layer specified. Note that your changes must have been committed to the git repository in order to be recognised.', |
1871 | group='working', order=-100) | 1883 | group='working', order=-100) |
1872 | parser_finish.add_argument('recipename', help='Recipe to finish') | 1884 | parser_finish.add_argument('recipename', help='Recipe to finish') |
1873 | parser_finish.add_argument('destination', help='Layer/path to put recipe into. Can be the name of a layer configured in your bblayers.conf, the path to the base of a layer, or a partial path inside a layer. %(prog)s will attempt to complete the path based on the layer\'s structure.') | 1885 | parser_finish.add_argument('destination', help='Layer/path to put recipe into. Can be the name of a layer configured in your bblayers.conf, the path to the base of a layer, or a partial path inside a layer. %(prog)s will attempt to complete the path based on the layer\'s structure.') |
1874 | parser_finish.add_argument('--mode', '-m', choices=['patch', 'srcrev', 'auto'], default='auto', help='Update mode (where %(metavar)s is %(choices)s; default is %(default)s)', metavar='MODE') | 1886 | parser_finish.add_argument('--mode', '-m', choices=['patch', 'srcrev', 'auto'], default='auto', help='Update mode (where %(metavar)s is %(choices)s; default is %(default)s)', metavar='MODE') |
1875 | parser_finish.add_argument('--initial-rev', help='Override starting revision for patches') | 1887 | parser_finish.add_argument('--initial-rev', help='Override starting revision for patches') |
1888 | parser_finish.add_argument('--force', '-f', action="store_true", help='Force continuing even if there are uncommitted changes in the source tree repository') | ||
1876 | parser_finish.set_defaults(func=finish) | 1889 | parser_finish.set_defaults(func=finish) |