git clone --depth=1
This commit is contained in:
parent
dc9a792ed8
commit
2ca09eacd6
|
@ -79,7 +79,7 @@ public class GameService {
|
|||
* @param tpiRepoName
|
||||
* Tpi版本库名称,需要这个参数的原因是,TPM的仓库名字和TPI的名字并不总是相同的
|
||||
*/
|
||||
public void gitClone(String tpiWorkSpace, String tpmGitURL, String remoteName, String tpiRepoName)
|
||||
public void gitClone(String tpiWorkSpace, String tpmGitURL, String remoteName, String tpiRepoName, String depth)
|
||||
throws GameException {
|
||||
logger.debug("tpiWorkSpace: {}, tpmGitURL: {}, remoteName: {}, tpiRepoName: {}", tpiWorkSpace, tpmGitURL,
|
||||
remoteName, tpiRepoName);
|
||||
|
@ -105,7 +105,7 @@ public class GameService {
|
|||
}
|
||||
|
||||
// 执行克隆操作
|
||||
String cmd = "cd " + tpiWorkSpace + " && git clone -o " + remoteName + " "+ tpmGitURL
|
||||
String cmd = "cd " + tpiWorkSpace + " && git clone -o " + remoteName + " " + depth + " " + tpmGitURL
|
||||
+ " && cd " + tpmRepoName + " && git config user.email educoder@163.com && git config user.name educoder";
|
||||
JSONObject result = ShellUtil.executeAndGetExitStatus(cmd, 3);
|
||||
|
||||
|
@ -136,26 +136,27 @@ public class GameService {
|
|||
String tpiID = path.substring(path.lastIndexOf("_") + 1);
|
||||
|
||||
// pull 操作之前,如果tpi本地版本库不存在,则克隆,主机名为origin
|
||||
int isRepoExist = ShellUtil.executeAndGetExitStatus("ls " + tpiRepoPath).getInteger("exitStatus");
|
||||
String cmd = "ls " + tpiRepoPath;
|
||||
int isRepoExist = ShellUtil.executeAndGetExitStatus(cmd).getInteger("exitStatus");
|
||||
if (isRepoExist != 0) {
|
||||
logger.warn("版本库不存在,先克隆! tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID);
|
||||
gitClone(path, tpiGitURL, "origin", tpiRepoName);
|
||||
gitClone(path, tpiGitURL, "origin", tpiRepoName, "--depth=1");
|
||||
}
|
||||
|
||||
// pull之前,先判断版本库的origin主机是否存在,若不存在,则先创建
|
||||
JSONObject remoteExist = ShellUtil
|
||||
.executeAndGetExitStatus("cd " + tpiRepoPath + " && git remote | grep ^origin$");
|
||||
cmd = "cd " + tpiRepoPath + " && git remote | grep ^origin$";
|
||||
JSONObject remoteExist = ShellUtil.executeAndGetExitStatus(cmd);
|
||||
if (remoteExist.getInteger("exitStatus") != 0) {
|
||||
if (remoteExist.getString("out").contains("fatal")) {
|
||||
logger.warn("版本库不完整,先进行init操作, tpiID: {}, tpiGitURL {}", tpiID, tpiGitURL);
|
||||
logger.warn("版本库不完整,先进行init操作, tpiID: {}, tpiGitURL: {}, 检查cmd: {}", tpiID, tpiGitURL, cmd);
|
||||
ShellUtil.execute("cd " + tpiRepoPath + " && git init");
|
||||
}
|
||||
|
||||
logger.warn("origin主机名不存在,先添加主机名及其git地址,remoteName: {}, tpiGitURL: {}, tpiID: {}", "origin", tpiGitURL, tpiID);
|
||||
JSONObject addRemote = ShellUtil
|
||||
.executeAndGetExitStatus("cd " + tpiRepoPath + " && git remote add origin " + tpiGitURL, 3);
|
||||
cmd = "cd " + tpiRepoPath + " && git remote add origin " + tpiGitURL;
|
||||
JSONObject addRemote = ShellUtil.executeAndGetExitStatus(cmd, 3);
|
||||
if (addRemote.getInteger("exitStatus") != 0) {
|
||||
logger.error("origin主机名不存在,添加主机名失败, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID);
|
||||
logger.error("origin主机名不存在,添加主机名失败, tpiGitURL: {}, tpiID: {}, cmd: {}", tpiGitURL, tpiID, cmd);
|
||||
throw new GameException("origin主机名不存在,无法完成pull操作,tpiID:" + tpiID);
|
||||
} else {
|
||||
logger.debug("origin主机名不存在,添加主机名成功, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID);
|
||||
|
@ -181,7 +182,7 @@ public class GameService {
|
|||
backupPullError(path, tpiRepoPath, tpiID);
|
||||
|
||||
// 重新clone
|
||||
gitClone(path, tpiGitURL, "origin", tpiRepoName);
|
||||
gitClone(path, tpiGitURL, "origin", tpiRepoName, "--depth=1");
|
||||
logger.debug("gitPull冲突,重新clone结束, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID);
|
||||
|
||||
} else {
|
||||
|
@ -234,17 +235,18 @@ public class GameService {
|
|||
public void gitPullFromTpm(String path, String tpmGitURL, String tpiRepoName, String tpiID) throws GameException {
|
||||
logger.debug("path: {}, tpmGitURL: {}, tpiRepoName: {}", path, tpmGitURL, tpiRepoName);
|
||||
|
||||
String tpiRepoPath = path + File.separator + tpiRepoName;
|
||||
|
||||
// pull 操作之前,如果本地版本库不存在,则克隆,主机名为remote_origin
|
||||
String cmd = "ls " + tpiRepoPath;
|
||||
int isRepoExist = ShellUtil.executeAndGetExitStatus(cmd).getInteger("exitStatus");
|
||||
if (isRepoExist != 0) {
|
||||
logger.warn("版本库不存在,先克隆! tpmGitURL: {}, tpiID: {}", tpmGitURL, tpiID);
|
||||
gitClone(path, tpmGitURL, "remote_origin", tpiRepoName);
|
||||
String tpiRepoPath = path + File.separator + tpiRepoName;
|
||||
try {
|
||||
FileUtils.forceDelete(new File(tpiRepoPath));
|
||||
logger.info("同步代码库先删除浅克隆,tpiID [{}] tpiRepoPath: {}", tpiID, tpiRepoPath);
|
||||
} catch (IOException e1) {
|
||||
logger.error("同步代码库先删除浅克隆,tpiID [{}] tpiRepoPath: {}, error: {}", tpiID, tpiRepoPath, e1.getMessage());
|
||||
}
|
||||
|
||||
cmd = "cd " + tpiRepoPath + " && git remote | grep ^remote_origin$";
|
||||
// pull 操作之前,如果本地版本库不存在,则克隆,主机名为remote_origin
|
||||
gitClone(path, tpmGitURL, "remote_origin", tpiRepoName, "");
|
||||
|
||||
String cmd = "cd " + tpiRepoPath + " && git remote | grep ^remote_origin$";
|
||||
JSONObject remoteExist = ShellUtil.executeAndGetExitStatus(cmd);
|
||||
if (remoteExist.getInteger("exitStatus") != 0) {
|
||||
if (remoteExist.getString("out").contains("fatal")) {
|
||||
|
@ -281,7 +283,7 @@ public class GameService {
|
|||
backupPullError(path, tpiRepoPath, tpiID);
|
||||
|
||||
// 重新clone
|
||||
gitClone(path, tpmGitURL, "remote_origin", tpiRepoName);
|
||||
gitClone(path, tpmGitURL, "remote_origin", tpiRepoName, "");
|
||||
logger.debug("gitPull冲突,重新clone结束, tpmGitURL: {}, tpiID: {}", tpmGitURL, tpiID);
|
||||
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,7 @@ public class CodeCloneJob implements Runnable {
|
|||
try {
|
||||
logger.info("下载tpi {}代码,tpmGitUrl {}", codeClone.getTpiID(), codeClone.getTpmGitURL());
|
||||
gameService.gitClone(codeClone.getTpiWorkSpace(), codeClone.getTpmGitURL(), codeClone.getRemoteName(),
|
||||
codeClone.getTpiRepoName());
|
||||
codeClone.getTpiRepoName(), "--depth=1");
|
||||
} catch (Throwable e) {
|
||||
logger.error("下载代码" + codeClone.getTpiID() + "出错", e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue