Browse Source

加上干掉本地分支

dev-DXTZYK
fanshuai 1 year ago
parent
commit
aab43e7bf6
3 changed files with 31 additions and 1 deletions
  1. +2
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java
  2. +2
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java
  3. +27
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java

+ 2
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java View File

@@ -700,6 +700,8 @@ public class ModelsServiceImpl implements ModelsService {
Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(metaPath + "/" + "metadata.yaml");
ModelMetaVo oldModelVo = ConvertUtil.convertMapToObject(stringObjectMap, ModelMetaVo.class);

//检查是否存在本地重名分支,有的话干掉
dvcUtils.deleteLocalBranch(rootPath, branchName);
// 创建本地分支
dvcUtils.createLocalBranchBasedOnMaster(rootPath, branchName);
//dvc checkout


+ 2
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java View File

@@ -184,7 +184,8 @@ public class NewDatasetServiceImpl implements NewDatasetService {
//部分信息在前面的版本里面,从那边取过来
Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(localPath + "/" + "dataset.yaml");
NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject(stringObjectMap, NewDatasetVo.class);

//检查是否存在本地重名分支,有的话干掉
dvcUtils.deleteLocalBranch(localPath, branchName);
// 创建本地分支
dvcUtils.createLocalBranchBasedOnMaster(localPath, branchName);



+ 27
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java View File

@@ -258,6 +258,33 @@ public class DVCUtils {
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 创建本地分支


Loading…
Cancel
Save