Skip to content

Commit 7f012b4

Browse files
committed
fixed
1 parent edc7d44 commit 7f012b4

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

paimon-core/src/main/java/org/apache/paimon/utils/BranchManager.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,32 @@ public static String getBranchPath(FileIO fileIO, Path tablePath, String branchN
105105
return tablePath.toString() + "/branch/" + BRANCH_PREFIX + branchName;
106106
}
107107

108+
public String defaultMainBranch() {
109+
Path path = new Path(tablePath, MAIN_BRANCH_FILE);
110+
try {
111+
if (fileIO.exists(path)) {
112+
String data = fileIO.readFileUtf8(path);
113+
if (!StringUtils.isBlank(data)) {
114+
return data;
115+
}
116+
}
117+
return DEFAULT_MAIN_BRANCH;
118+
} catch (IOException e) {
119+
throw new RuntimeException(e);
120+
}
121+
}
122+
108123
/** Return the path of a branch. */
109124
public Path branchPath(String branchName) {
110125
return new Path(getBranchPath(fileIO, tablePath, branchName));
111126
}
112127

113128
public void createBranch(String branchName, String tagName) {
129+
String mainBranch = defaultMainBranch();
114130
checkArgument(
115-
!branchName.equals(DEFAULT_MAIN_BRANCH),
131+
!branchName.equals(mainBranch),
116132
String.format(
117-
"Branch name '%s' is the default branch and cannot be used.",
118-
DEFAULT_MAIN_BRANCH));
133+
"Branch name '%s' is the default branch and cannot be used.", mainBranch));
119134
checkArgument(!StringUtils.isBlank(branchName), "Branch name '%s' is blank.", branchName);
120135
checkArgument(!branchExists(branchName), "Branch name '%s' already exists.", branchName);
121136
checkArgument(tagManager.tagExists(tagName), "Tag name '%s' not exists.", tagName);
@@ -161,6 +176,12 @@ public void deleteBranch(String branchName) {
161176

162177
/** Replace specify branch to main branch. */
163178
public void replaceBranch(String branchName) {
179+
String mainBranch = defaultMainBranch();
180+
checkArgument(
181+
!branchName.equals(mainBranch),
182+
String.format(
183+
"Branch name '%s' is the default main branch and cannot be replaced repeatedly.",
184+
mainBranch));
164185
checkArgument(!StringUtils.isBlank(branchName), "Branch name '%s' is blank.", branchName);
165186
checkArgument(branchExists(branchName), "Branch name '%s' not exists.", branchName);
166187
try {

0 commit comments

Comments
 (0)