原来的方法,执行git操作前会更改Django的工作目录;在有并发任务时,可能会因工作目录错乱而发生异常。
# os.chdir(self.git_folder)
gitCmd = 'git clone -b %s git@%s:%s.git' % (template_code_obj.git_branch,
self.downloadObj.git_host.replace("http://",""), template_code_obj.git_path)
# 将git仓库目录拉下来
os.system(gitCmd)
# git clone之后,会创建一个以项目名称命名的目录,进入这个目录,执行git pull
os.chdir(project_path)
# 将仓库文件拉下来
os.system("git pull")
# 拉取完成后立即回到主目录,避免影响其他操作
# 通过测试脚本下载项目会频繁出现下载失败,可能跟这个目录问题有关系
os.chdir(settings.BASE_DIR)
现在的设计,无需切换工作目录
gitCmd = 'git -C %s clone -b %s git@%s:%s.git' % (self.git_folder, template_code_obj.git_branch,
self.downloadObj.git_host.replace("http://",""), template_code_obj.git_path)
os.system(gitCmd)
gitCmd = 'git -C %s pull' % self.project_path
os.system(gitCmd)