Skip to content

Commit

Permalink
Revert "Enable forcing exp apply (unsaved files in the workspace)"
Browse files Browse the repository at this point in the history
This reverts commit 3661b89.
  • Loading branch information
pmrowla committed Oct 26, 2023
1 parent 4a0d56a commit d9b2e67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
19 changes: 13 additions & 6 deletions dvc/commands/experiments/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
from dvc.cli import completion
from dvc.cli.command import CmdBase
from dvc.cli.utils import append_doc_link
from dvc.ui import ui

logger = logging.getLogger(__name__)


class CmdExperimentsApply(CmdBase):
def run(self):
self.repo.experiments.apply(self.args.experiment, force=self.args.force)
if not self.args.force:
ui.write(
"The --no-force option is deprecated and will be removed in a future"
" DVC release. To revert the result of 'exp apply', run:\n"
"\n\tgit reset --hard\n"
"\tgit stash apply refs/exps/apply/stash\n"
)
self.repo.experiments.apply(self.args.experiment)

return 0

Expand All @@ -25,11 +33,10 @@ def add_parser(experiments_subparsers, parent_parser):
formatter_class=argparse.RawDescriptionHelpFormatter,
)
experiments_apply_parser.add_argument(
"-f",
"--force",
action="store_true",
default=False,
help="Do not prompt when removing working directory files.",
"--no-force",
action="store_false",
dest="force",
help="Fail if this command would overwrite conflicting changes.",
)
experiments_apply_parser.add_argument(
"experiment", help="Experiment to be applied."
Expand Down
14 changes: 1 addition & 13 deletions tests/unit/command/test_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,7 @@ def test_experiments_apply(dvc, scm, mocker):

assert cmd.run() == 0

m.assert_called_once_with(cmd.repo, "exp_rev", force=False)


def test_experiments_apply_force(dvc, scm, mocker):
cli_args = parse_args(["experiments", "apply", "exp_rev", "--force"])
assert cli_args.func == CmdExperimentsApply

cmd = cli_args.func(cli_args)
m = mocker.patch("dvc.repo.experiments.apply.apply", return_value={})

assert cmd.run() == 0

m.assert_called_once_with(cmd.repo, "exp_rev", force=True)
m.assert_called_once_with(cmd.repo, "exp_rev")


def test_experiments_diff(dvc, scm, mocker):
Expand Down

0 comments on commit d9b2e67

Please sign in to comment.