🔨 perf(server): Git 仓库地址不正确相关提示更准确

This commit is contained in:
小吾立 2024-04-12 19:06:47 +08:00
parent d11dff24ca
commit fa9c8e7516
2 changed files with 28 additions and 0 deletions

View File

@ -1,5 +1,14 @@
# 🚀 版本日志
## 2.11.4.1
### 🐞 解决BUG、优化功能
1. 【server】优化 构建相关页面无法正常打开
2. 【server】优化 Git 仓库地址不正确相关提示更准确(感谢@易自玉)
------
## 2.11.4.0
### 🐣 新增功能

View File

@ -13,6 +13,7 @@ import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.comparator.VersionComparator;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Tuple;
@ -26,6 +27,9 @@ import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@ -450,6 +454,21 @@ public class JGitUtil {
*/
public static void checkTransportException(Exception ex, File gitFile, PrintWriter printWriter) throws Exception {
println(printWriter, "");
Throwable causedBy = ExceptionUtil.getCausedBy(ex, NotSupportedException.class);
if (causedBy != null) {
println(printWriter, "当前地址可能不是 git 仓库地址:" + causedBy.getMessage());
throw new IllegalStateException("当前地址可能不是 git 仓库地址:" + causedBy.getMessage(), ex);
}
causedBy = ExceptionUtil.getCausedBy(ex, NoRemoteRepositoryException.class);
if (causedBy != null) {
println(printWriter, "当前地址远程不存在仓库:" + causedBy.getMessage());
throw new IllegalStateException("当前地址远程不存在仓库:" + causedBy.getMessage(), ex);
}
causedBy = ExceptionUtil.getCausedBy(ex, RepositoryNotFoundException.class);
if (causedBy != null) {
println(printWriter, "当前地址不存在仓库:" + causedBy.getMessage());
throw new IllegalStateException("当前地址不存在仓库:" + causedBy.getMessage(), ex);
}
if (ex instanceof TransportException) {
String msg = ex.getMessage();
if (StrUtil.containsAny(msg, JGitText.get().notAuthorized, JGitText.get().authenticationNotSupported)) {