我正在寻找Git中的实际git push
命令的别名,以便在提交给GitHub之前运行单元测试。
以下是我在config
.git/
文件
[alias]
push = !echo "custom push"
kk = !echo "hi" # => this works...
似乎无视推动。这可能吗?如果这是不可能的,还有其他选择吗?
答案 0 :(得分:1)
我没有创建别名,而是使用git的预提交钩子。
答案 1 :(得分:1)
由于与push命令冲突,您无法对推送进行别名,但您可以尝试使用“pre-push”挂钩,有关详细信息,请参阅以下patch。
另一种方法是在GitHub上使用post-receive挂钩,您可以将其配置为对集成服务器执行POST,该服务器将运行单元测试等,并批准或拒绝更改。但是,根据您的设置,这可能不切实际。
答案 2 :(得分:1)
我写这篇文章是为了打击git push
打印出我想要运行的但是没有运行它的讨厌!是的,它有原因(你不应该把每一块垃圾都推到遥控器上),但是我的遥控器是我的GitHub叉子,我可以忍受任何被推到那里的垃圾。
这是基于Eugene Kay's .bashrc
(我保留了cd
,但删除了which git
部分,这对我不起作用)。将其添加到.bashrc
或.zshrc
以品尝:
function git() {
# Path to the `git` binary
GIT="/usr/bin/git"
# Sanity check
if [ ! -f ${GIT} ]
then
echo "Error: git binary not found" >&2
return 255
fi
# Command to be executed
command=$1
# Remove command from $@ array
shift 1
# Check command against list of supported commands
case $command in
"cd")
cd $(git rev-parse --show-toplevel)/${1}
;;
"push")
if [ -z "$1" ]
then
$GIT push || $GIT push -u origin $($GIT rev-parse --abbrev-ref @)
else
$GIT ${command} "$@"
fi
;;
*)
# Execute the git binary
$GIT ${command} "$@"
;;
esac
# Return something
return $?
}