Example #1
0
//从 .gitFakeSubmodule 中还原旧的fakeSubmoudle,并且将所有子项目都切换到该文件里面写的分支(使用reset切分支,保证不掉数据)
func (repo *Repository) MustFakeSubmoduleUpdate() {
	rootPath := repo.gitPath
	SubmoduleList := map[string]SubRepositoryInfo{}
	kmgJson.MustReadFile(filepath.Join(rootPath, ".gitFakeSubmodule"), &SubmoduleList)
	for repoPath, SubmoduleInfo := range SubmoduleList {
		repoRealPath := filepath.Join(rootPath, repoPath)
		//子项目存在?
		if !MustIsRepositoryAtPath(repoRealPath) {
			tmpPath := filepath.Join(repoRealPath, kmgRand.MustCryptoRandToHex(8))
			kmgFile.MustMkdir(tmpPath)
			MustGitClone(SubmoduleInfo.RemoteUrl, tmpPath)
			kmgFile.MustRename(filepath.Join(tmpPath, ".git"), filepath.Join(repoRealPath, ".git"))
			kmgFile.MustDelete(tmpPath)
		}
		//子项目的远程路径正确?
		subRepo := MustGetRepositoryFromPath(repoRealPath)
		if subRepo.MustGetRemoteUrl("origin") != SubmoduleInfo.RemoteUrl {
			subRepo.MustSetRemoteUrl("origin", SubmoduleInfo.RemoteUrl)
		}
		//子项目的版本号正确?
		if subRepo.MustGetHeadCommitId() != SubmoduleInfo.CommitId {
			subRepo.MustResetToCommitId(SubmoduleInfo.CommitId)
		}
	}
}
Example #2
0
func MustChangeToTmpPath() string {
	folder := "/tmp/kmg/" + kmgRand.MustCryptoRandToHex(6)
	MustMkdirAll(folder)
	err := os.Chdir(folder)
	if err != nil {
		panic(err)
	}
	return folder
}