diff --git a/lib/wit/common.py b/lib/wit/common.py index f5ccd9a..0c206be 100755 --- a/lib/wit/common.py +++ b/lib/wit/common.py @@ -18,7 +18,7 @@ def print_errors(errors): for err in errors: log.info("--- ERROR ---") - log.info(err) + log.info(str(err)) class WitUserError(Exception): diff --git a/lib/wit/main.py b/lib/wit/main.py index 7724b44..93d4bd6 100644 --- a/lib/wit/main.py +++ b/lib/wit/main.py @@ -78,7 +78,9 @@ def main() -> None: update_dep_parser.add_argument('pkg', metavar='pkg[::revision]', type=parse_dependency_tag) subparsers.add_parser('status', help='show status of workspace') - subparsers.add_parser('update', help='update git repos') + + update_parser = subparsers.add_parser('update', help='update git repos') + update_parser.add_argument('--force', action='store_true', help='checkout regardless of errors') inspect_parser = subparsers.add_parser('inspect', help='inspect lockfile') inspect_group = inspect_parser.add_mutually_exclusive_group() @@ -358,10 +360,15 @@ def status(ws, args) -> None: def update(ws, args) -> None: packages, errors = ws.resolve(download=True) - if len(errors) == 0: - ws.checkout(packages) - else: + + # the errors assume the repos are still in .wit + if len(errors) > 0: print_errors(errors) + + if len(errors) == 0 or ('force' in args and args.force): + ws.checkout(packages) + + if len(errors) > 0: sys.exit(1) diff --git a/t/wit_ancestry_force.t b/t/wit_ancestry_force.t new file mode 100755 index 0000000..fe41fe9 --- /dev/null +++ b/t/wit_ancestry_force.t @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +. $(dirname $0)/regress_util.sh + +prereq "on" + +make_repo 'xyz' + +cd xyz +touch zero +git add -A +git commit -m "xyz:0" + +git checkout -b branch_a +touch testa +git add -A +git commit -m "xyz:a" +xyz_commit_a=$(git rev-parse HEAD) + +git checkout master + +git checkout -b branch_b +touch testb +git add -A +git commit -m "xyz:b" +xyz_commit_b=$(git rev-parse HEAD) +cd .. + +make_repo 'foo' +cat << EOF | jq . > foo/wit-manifest.json +[ + { "commit": "$xyz_commit_b", "name": "xyz", "source": "$PWD/xyz" } +] +EOF +git -C foo add -A +git -C foo commit -m "add xyz:2" +foo_commit=$(git -C foo rev-parse HEAD) + +# Set up repo foo +make_repo 'bar' +cat << EOF | jq . > bar/wit-manifest.json +[ + { "commit": "$xyz_commit_a", "name": "xyz", "source": "$PWD/xyz" } +] +EOF +git -C bar add -A +git -C bar commit -m "add xyz:1" + +prereq "off" + +# Now create a workspace from main_repo +wit init myws -a $PWD/foo -a $PWD/bar + +check "wit init should fail with AncestryError" [ $? -ne 0 ] + +cd myws +wit update +check "wit update should fail with AncestryError" [ $? -ne 0 ] + +ls foo || ls bar || ls xyz +check "repos should not be checked out" [ $? -ne 0 ] + +wit update --force +check "wit update --force should return non-zero exit code" [ $? -ne 0 ] + +ls foo && ls bar && ls xyz +check "repos should be checked out" [ $? -eq 0 ] + +report +finish