繁体   English   中英

为什么我不能运行从另一个Shell脚本推送到git的shell脚本?

[英]Why can't I run this shell-script pushing to git from another shell script?

我在运行shell脚本时遇到问题,该脚本基本上将目录中的更改从另一个脚本提交到远程git-repository。 “超级脚本”正在以超级用户权限运行,并且我的超级用户主目录中的〜/ .ssh /处生成了所需的ssh密钥。 同样,独立运行内部脚本也可以正常工作,并推送到远程存储库。

这是运行超级脚本时遇到的错误:

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 326 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: GitLab: You are not allowed to push code to protected branches on this project.
To git@url.goes.here:groupspace/projectspace.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@url.goes.here:groupspace/projectspace.git'

我用这行代码调用内部脚本,保存其退出状态以进行进一步处理

SUCCESS = $(bash /path/to/push-config.sh)

这是push-config.sh的内容

#!/bin/bash
# 
stamp=$(date +"%Y-%m-%d %T")

git add .
git commit -m "Config $stamp"

if [ $? -eq 0 ]
then
  git push -u origin master
  if [ $? -eq 0 ]
  then
    echo "Successfully pushed config to repo."
    exit 0
  else
    echo "Failure while pushing to repo."
    exit 1
  fi
else
  exit 1
fi

任何帮助表示赞赏,在此先感谢。

由于您对git pre-receive挂钩不满意,因此该挂钩会验证您是否在上标或运行上标的环境中未正确设置的内容。

对运行上标和内部脚本时创建的提交进行比较。 确保它们相同。

接下来,确保两次推送的git环境相同。 这样,我的意思是git用户变量应该相同,并且您当前的工作目录应该与存储库匹配。

如果您确实检查了预接收挂钩验证的内容,则调试起来会更容易。

超级用户具有自己的主目录。 我希望您在自己的主文件夹中有ssh密钥(如您所述, ~/.ssh )。 将ssh密钥添加到root用户的主目录中的.ssh文件夹中,或参阅在Git上执行shell命令时如何指定专用SSH密钥?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM