git+gerrit clone 脚本
2016-07-20 11:51
239 查看
使用gerrit作为code Review平台后,克隆代码的简易方法,写了个脚本,工作中常用到:
直接执行该脚本即可.
#!/usr/bin/env python # coding=utf-8 # for git clone helper # author: jason # import os, sys GERRIT_SERVER="192.168.1.187" GERRIT_LISTEN_PORT="29419" GIT_REPO_NAME="" SSH_CLONE_FULL_CMD="" GERRIT_HOOKS_CMD="" WHOAMI="" def hello(): print '\033[0;32;40m' #print 50*('*') print print '\tGerrit source code clone tools' print print 50*("*") print '\033[0m' def __exit(x): sys.exit(x) def error_color(): print '\033[0;31;40m' def normal_color(): print '\033[0m' def get_username(): global WHOAMI WHOAMI = os.popen('whoami').read().strip() def prep_git_repo(): global GIT_REPO_NAME GIT_REPO_NAME=raw_input("Please input the dest Git Repository:") if (len(GIT_REPO_NAME) <= 0): error_color() print "Invalid Git Repository, You entered NULL value!" normal_color() __exit(1) print("The dest Git Repo is %s") % GIT_REPO_NAME def prep_ssh_clone_str(): global SSH_CLONE_FULL_CMD global GIT_REPO_NAME global WHOAMI global GERRIT_SERVER global GERRIT_LISTEN_PORT SSH_CLONE_FULL_CMD = "git clone ssh://"+WHOAMI+"@"+GERRIT_SERVER+":"+GERRIT_LISTEN_PORT+"/"+GIT_REPO_NAME print SSH_CLONE_FULL_CMD def prep_gerrit_hooks(): global WHOAMI global GIT_REPO_NAME global GERRIT_HOOKS_CMD global GERRIT_LISTEN_PORT global GERRIT_SERVER GERRIT_HOOKS_CMD = "scp -p -P " + GERRIT_LISTEN_PORT + " " + WHOAMI+ "@" + GERRIT_SERVER + ":hooks/commit-msg " + GIT_REPO_NAME + "/.git/hooks/" print GERRIT_HOOKS_CMD def do_shell_cmd(CMD): os.system(CMD) def do_git_clone(): global GERRIT_HOOKS_CMD global SSH_CLONE_FULL_CMD get_username() prep_git_repo() prep_ssh_clone_str() prep_gerrit_hooks() do_shell_cmd(SSH_CLONE_FULL_CMD) do_shell_cmd(GERRIT_HOOKS_CMD) print '\033[0;32;40m' print "Git Clone done!" normal_color() if __name__ == "__main__": hello() do_git_clone() __exit(0)
直接执行该脚本即可.
相关文章推荐
- RPC failed; result=22, HTTP code = 411
- git更新已經刪除的文件
- 提取Git每次提交后Commit的文件
- GIT迁移服务器
- 分布式版本管理git入门指南使用资料汇总及文章推荐
- git终极指南:在实际开发中的应用
- 6 个托管 git 仓库的地方
- jquery的clone方法应用于textarea和select的bug修复
- JavaScript深度复制(deep clone)的实现方法
- Git远程操作详解
- 25个 Git 进阶技巧(翻译)
- 详解版本控制利器Git,SVN的异同以及适用范围
- git多账号登录问题解析
- 深入理解JavaScript中的对象复制(Object Clone)
- Ruby实现的删除已经合并的git分支脚本分享
- 在 Shell 提示符中显示 Git 分支名称的方法
- Git使用基础篇(一些常用命令和原理)
- git 使用及常用命令
- git eclipse 插件的安装
- Javascript对象Clone实例分析