2017-07-17 58 views
0

我有下面的代码,我想使用GitpYthon将我的分支中的更改推送到gerrit。使用Gitpython推refs/for/master和change-id问题

repo_path_new = repo_path+repo_name 
repo_obj = Repo(repo_path_new) 
os.chdir(repo_path_new) 
repo_obj.git.add(A=True) 
if commit_command_line(commit_message, repo_obj, repo_name): 
    repo_obj.git.push("origin", "HEAD:refs/for/master") 

它补充,并提交该文件(S),但是当我要推到裁判/为/主,我碰到一个问题:

remote: Processing changes: refs: 1, done 
remote: ERROR: [0f7c907] missing Change-Id in commit message footer 
remote: 
remote: Hint: To automatically insert Change-Id, install the hook: 
remote: gitdir=$(git rev-parse --git-dir); scp -p -P port 
[email protected]:hooks/commit-msg ${gitdir}/hooks/ 
remote: And then amend the commit: 
remote: git commit --amend 
remote: 
To ssh://url:port/repo-name 
! [remote rejected] HEAD -> refs/for/master ([0f7c907] missing Change-Id in commit message footer) 
error: failed to push some refs to 'ssh://url:port/repo-name'' 

请注意,我站在克隆回购。当然,我可以在git bash中手动安装git hook change-id。但由于这应该是自动完成的,我想知道是否有办法通过gitpython来做到这一点。

回答

0

您是手动克隆存储库还是通过gitpython完成的?请注意,您只需要安装一次commit-msg钩子(第一次克隆仓库),然后所有提交都会自动添加Change-Id。

如果通过SSH运行Access格里特:

$ gitdir=$(git rev-parse --git-dir); scp -p -P 29418 GERRIT-SERVER:hooks/commit-msg ${gitdir}/hooks 

如果您访问格里特throught HTTPS运行:

$ gitdir=$(git rev-parse --git-dir); curl --create-dirs -Lo ${gitdir}/hooks/commit-msg https://GERRIT-SERVER/tools/hooks/commit-msg 

可以执行它,你克隆库后,手动或您可以添加这gitpython。

+0

我手动克隆存储库。当我按照你所说的方式安装时,它会工作,但由于该脚本将在Go cd中运行(就像Jenkins一样),因此无法确定是否存在commit-msg挂钩。在我的代码中,我打电话给你第一个选项,它在gitdir上失败(无法找到它)。 – user535081

+0

您可以在克隆存储库之后并在执行gitpython脚本之前设置go-cd执行bash脚本(使用命令安装commit-msg挂钩)? –