Angelos Evripiotis pushed to branch aevri/safe_noninteractive at BuildStream / buildstream
Commits:
-
67d8742e
by Angelos Evripiotis at 2018-11-28T07:53:05Z
2 changed files:
Changes:
... | ... | @@ -769,12 +769,12 @@ def workspace_close(app, remove_dir, all_, assume_yes, elements): |
769 | 769 |
if remove_dir and not assume_yes and app.context.prompt_workspace_close_remove_dir:
|
770 | 770 |
if app.interactive:
|
771 | 771 |
if not click.confirm('This will remove all your changes, are you sure?'):
|
772 |
- click.echo('Aborting', err=True)
|
|
773 |
- sys.exit(-1)
|
|
772 |
+ raise AppError("User aborted")
|
|
774 | 773 |
else:
|
775 |
- click.echo("Aborted destructive non-interactive action.", err=True)
|
|
776 |
- click.echo("Please use the '--assume-yes' option to override.", err=True)
|
|
777 |
- sys.exit(-1)
|
|
774 |
+ raise AppError(
|
|
775 |
+ "Aborted destructive non-interactive action.",
|
|
776 |
+ detail="Please use the '--assume-yes' option to override.",
|
|
777 |
+ reason='aborted-destructive-non-interactive-non-confirmed')
|
|
778 | 778 |
|
779 | 779 |
for element_name in elements:
|
780 | 780 |
app.stream.workspace_close(element_name, remove_dir=remove_dir)
|
... | ... | @@ -810,12 +810,12 @@ def workspace_reset(app, soft, track_, all_, assume_yes, elements): |
810 | 810 |
if not soft and not assume_yes and app.context.prompt_workspace_reset_hard:
|
811 | 811 |
if app.interactive:
|
812 | 812 |
if not click.confirm('This will remove all your changes, are you sure?'):
|
813 |
- click.echo('Aborting', err=True)
|
|
814 |
- sys.exit(-1)
|
|
813 |
+ raise AppError("User aborted")
|
|
815 | 814 |
else:
|
816 |
- click.echo("Aborted destructive non-interactive action.", err=True)
|
|
817 |
- click.echo("Please use the '--assume-yes' option to override.", err=True)
|
|
818 |
- sys.exit(-1)
|
|
815 |
+ raise AppError(
|
|
816 |
+ "Aborted destructive non-interactive action.",
|
|
817 |
+ detail="Please use the '--assume-yes' option to override.",
|
|
818 |
+ reason='aborted-destructive-non-interactive-non-confirmed')
|
|
819 | 819 |
|
820 | 820 |
if all_:
|
821 | 821 |
elements = tuple(element_name for element_name, _ in app.context.get_workspaces().list())
|
... | ... | @@ -22,6 +22,7 @@ |
22 | 22 |
# Jonathan Maw <jonathan maw codethink co uk>
|
23 | 23 |
# Richard Maw <richard maw codethink co uk>
|
24 | 24 |
# William Salmon <will salmon codethink co uk>
|
25 |
+# Angelos Evripiotis <jevripiotis bloomberg net>
|
|
25 | 26 |
#
|
26 | 27 |
|
27 | 28 |
import os
|
... | ... | @@ -519,6 +520,44 @@ def test_close_all(cli, tmpdir, datafiles): |
519 | 520 |
assert not os.path.exists(workspace_beta)
|
520 | 521 |
|
521 | 522 |
|
523 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
524 |
+@pytest.mark.parametrize("scenario", [
|
|
525 |
+ {'assume_yes': True, 'no_prompt': True},
|
|
526 |
+ {'assume_yes': False, 'no_prompt': True},
|
|
527 |
+ # Covered by test_close: {'assume_yes': True, 'no_prompt': False},
|
|
528 |
+ {'assume_yes': False, 'no_prompt': False},
|
|
529 |
+])
|
|
530 |
+def test_close_remove_dir_prompt(cli, tmpdir, datafiles, scenario):
|
|
531 |
+ |
|
532 |
+ assume_yes, no_prompt = scenario['assume_yes'], scenario['no_prompt']
|
|
533 |
+ |
|
534 |
+ element_name, project, workspace = open_workspace(
|
|
535 |
+ cli, tmpdir, datafiles, 'git', track=False)
|
|
536 |
+ |
|
537 |
+ workspace_args = [
|
|
538 |
+ 'workspace', 'close', '--remove-dir', element_name
|
|
539 |
+ ]
|
|
540 |
+ |
|
541 |
+ if assume_yes:
|
|
542 |
+ workspace_args.append('--assume-yes')
|
|
543 |
+ |
|
544 |
+ if no_prompt:
|
|
545 |
+ cli.configure(
|
|
546 |
+ {'prompt': {'really-workspace-close-remove-dir': 'yes'}}
|
|
547 |
+ )
|
|
548 |
+ |
|
549 |
+ result = cli.run(project=project, args=workspace_args)
|
|
550 |
+ |
|
551 |
+ if assume_yes or no_prompt:
|
|
552 |
+ result.assert_success()
|
|
553 |
+ assert not os.path.exists(workspace)
|
|
554 |
+ else:
|
|
555 |
+ result.assert_main_error(
|
|
556 |
+ ErrorDomain.APP,
|
|
557 |
+ 'aborted-destructive-non-interactive-non-confirmed')
|
|
558 |
+ assert os.path.exists(workspace)
|
|
559 |
+ |
|
560 |
+ |
|
522 | 561 |
@pytest.mark.datafiles(DATA_DIR)
|
523 | 562 |
def test_reset(cli, tmpdir, datafiles):
|
524 | 563 |
# Open the workspace
|
... | ... | @@ -592,6 +631,48 @@ def test_reset_all(cli, tmpdir, datafiles): |
592 | 631 |
assert not os.path.exists(os.path.join(workspace_beta, 'etc', 'pony.conf'))
|
593 | 632 |
|
594 | 633 |
|
634 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
635 |
+@pytest.mark.parametrize("scenario", [
|
|
636 |
+ {'assume_yes': True, 'no_prompt': True},
|
|
637 |
+ {'assume_yes': False, 'no_prompt': True},
|
|
638 |
+ # Covered by test_reset: {'assume_yes': True, 'no_prompt': False},
|
|
639 |
+ {'assume_yes': False, 'no_prompt': False},
|
|
640 |
+])
|
|
641 |
+def test_reset_prompt(cli, tmpdir, datafiles, scenario):
|
|
642 |
+ |
|
643 |
+ assume_yes, no_prompt = scenario['assume_yes'], scenario['no_prompt']
|
|
644 |
+ |
|
645 |
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, 'git', False)
|
|
646 |
+ |
|
647 |
+ # Make a change to revert.
|
|
648 |
+ os.makedirs(os.path.join(workspace, 'etc'))
|
|
649 |
+ with open(os.path.join(workspace, 'etc', 'pony.conf'), 'w') as f:
|
|
650 |
+ f.write("PONY='pink'")
|
|
651 |
+ |
|
652 |
+ workspace_args = [
|
|
653 |
+ 'workspace', 'reset', element_name
|
|
654 |
+ ]
|
|
655 |
+ |
|
656 |
+ if assume_yes:
|
|
657 |
+ workspace_args.append('--assume-yes')
|
|
658 |
+ |
|
659 |
+ if no_prompt:
|
|
660 |
+ cli.configure(
|
|
661 |
+ {'prompt': {'really-workspace-reset-hard': 'yes'}}
|
|
662 |
+ )
|
|
663 |
+ |
|
664 |
+ result = cli.run(project=project, args=workspace_args)
|
|
665 |
+ |
|
666 |
+ if assume_yes or no_prompt:
|
|
667 |
+ result.assert_success()
|
|
668 |
+ assert not os.path.exists(os.path.join(workspace, 'etc', 'pony.conf'))
|
|
669 |
+ else:
|
|
670 |
+ result.assert_main_error(
|
|
671 |
+ ErrorDomain.APP,
|
|
672 |
+ 'aborted-destructive-non-interactive-non-confirmed')
|
|
673 |
+ assert os.path.exists(os.path.join(workspace, 'etc', 'pony.conf'))
|
|
674 |
+ |
|
675 |
+ |
|
595 | 676 |
@pytest.mark.datafiles(DATA_DIR)
|
596 | 677 |
def test_list(cli, tmpdir, datafiles):
|
597 | 678 |
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, 'git', False)
|