11import os
22from typing import TYPE_CHECKING
33
4- from dvc .exceptions import MoveNotDataSourceError
54from dvc .repo .scm_context import scm_context
65
76from . import locked
@@ -38,7 +37,9 @@ def move(self: "Repo", from_path, to_path):
3837 """
3938 from dvc import dependency , output
4039 from dvc .dvcfile import DVC_FILE_SUFFIX
40+ from dvc .exceptions import MoveNotDataSourceError
4141 from dvc .stage import Stage
42+ from dvc .stage .exceptions import StageFileAlreadyExistsError
4243 from dvc_objects .fs .local import LocalFileSystem
4344
4445 from_out = output .loads_from (Stage (self ), [from_path ])[0 ]
@@ -64,16 +65,20 @@ def move(self: "Repo", from_path, to_path):
6465 )
6566 new_wdir = os .path .abspath (os .path .join (os .curdir , os .path .dirname (to_path )))
6667 to_path = os .path .relpath (to_path , new_wdir )
67- new_stage = self .stage .create (
68- single_stage = True ,
69- fname = new_fname ,
70- wdir = new_wdir ,
71- outs = [to_path ],
72- meta = stage .meta ,
73- frozen = stage .frozen ,
74- always_changed = stage .always_changed ,
75- desc = stage .desc ,
76- )
68+ try :
69+ new_stage = self .stage .create (
70+ single_stage = True ,
71+ fname = new_fname ,
72+ wdir = new_wdir ,
73+ outs = [to_path ],
74+ meta = stage .meta ,
75+ frozen = stage .frozen ,
76+ always_changed = stage .always_changed ,
77+ desc = stage .desc ,
78+ )
79+ except StageFileAlreadyExistsError :
80+ # reraise to remove `--force` hint
81+ raise StageFileAlreadyExistsError (f"{ new_fname !r} already exists" ) from None
7782 else :
7883 new_stage = stage
7984 to_path = os .path .relpath (to_path , stage .wdir )
0 commit comments