| @@ -700,6 +700,8 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(metaPath + "/" + "metadata.yaml"); | Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(metaPath + "/" + "metadata.yaml"); | ||||
| ModelMetaVo oldModelVo = ConvertUtil.convertMapToObject(stringObjectMap, ModelMetaVo.class); | ModelMetaVo oldModelVo = ConvertUtil.convertMapToObject(stringObjectMap, ModelMetaVo.class); | ||||
| //检查是否存在本地重名分支,有的话干掉 | |||||
| dvcUtils.deleteLocalBranch(rootPath, branchName); | |||||
| // 创建本地分支 | // 创建本地分支 | ||||
| dvcUtils.createLocalBranchBasedOnMaster(rootPath, branchName); | dvcUtils.createLocalBranchBasedOnMaster(rootPath, branchName); | ||||
| //dvc checkout | //dvc checkout | ||||
| @@ -184,7 +184,8 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||||
| //部分信息在前面的版本里面,从那边取过来 | //部分信息在前面的版本里面,从那边取过来 | ||||
| Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(localPath + "/" + "dataset.yaml"); | Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(localPath + "/" + "dataset.yaml"); | ||||
| NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject(stringObjectMap, NewDatasetVo.class); | NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject(stringObjectMap, NewDatasetVo.class); | ||||
| //检查是否存在本地重名分支,有的话干掉 | |||||
| dvcUtils.deleteLocalBranch(localPath, branchName); | |||||
| // 创建本地分支 | // 创建本地分支 | ||||
| dvcUtils.createLocalBranchBasedOnMaster(localPath, branchName); | dvcUtils.createLocalBranchBasedOnMaster(localPath, branchName); | ||||
| @@ -258,6 +258,33 @@ public class DVCUtils { | |||||
| log.error("Error occurred while creating local branch", e); | log.error("Error occurred while creating local branch", e); | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * 删除本地分支 | |||||
| * | |||||
| * @param localPath 本地仓库路径 | |||||
| * @param branchName 要删除的分支名称 | |||||
| */ | |||||
| public void deleteLocalBranch(String localPath, String branchName) throws IOException, GitAPIException { | |||||
| FileRepositoryBuilder builder = new FileRepositoryBuilder(); | |||||
| Repository repository = builder.setGitDir(new File(localPath + "/.git")) | |||||
| .readEnvironment() | |||||
| .findGitDir() | |||||
| .build(); | |||||
| try (Git git = new Git(repository)) { | |||||
| // 获取所有本地分支 | |||||
| for (Ref ref : git.branchList().call()) { | |||||
| String refName = ref.getName(); | |||||
| if (refName.endsWith("/" + branchName)) { | |||||
| // 删除本地分支 | |||||
| git.branchDelete().setBranchNames(refName).setForce(true).call(); | |||||
| log.info("Deleted branch: " + branchName); | |||||
| return; | |||||
| } | |||||
| } | |||||
| log.info("Branch not found: " + branchName); | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * 基于 master 创建本地分支 | * 基于 master 创建本地分支 | ||||