简体   繁体   English

使 shell 命令在 git hook 中可用

[英]make shell commands available in git hook

The goal is to make some set of commands available to the user after they clone/checkout repo.目标是在用户克隆/签出存储库后向用户提供一些命令集。

the git hook file git 钩子文件

#!/bin/sh
echo $PWD/dev-commands.sh
source $PWD/dev-commands.sh

the command I want to make available after the git hook names dev-commands.sh我想在 git hook 名称 dev-commands.sh 之后提供的命令

#!/bin/sh
function greet() {
  echo Hello
}

this does not seem to make the command available.这似乎没有使命令可用。 if I run source dev-commands.sh in the directory manually it does make the greet commands availble..如果我在目录中运行源dev-commands.sh手动它确实让greet命令availble的..

any tips?有小费吗?

Sourced functions are available in the shell that sourced them, not its parent shells.源函数在提供它们的 shell 中可用,而不是它的父 shell。 That's why when you write a shell script, it can use its own functions without worrying about interfering with what its invoker's commands mean.这就是为什么当您编写 shell 脚本时,它可以使用自己的函数而不必担心干扰其调用者的命令的含义。

( doit() { echo hi; }; doit ); doit

for instance, will say hi and then very probably complain -bash: doit: command not found or an equivalent message because the parens were there to put doit into a subshell, which has its own environment, just like git hooks.例如,会hi ,然后很可能会抱怨-bash: doit: command not found或等效消息,因为括号在那里将doit放入具有自己环境的子外壳中,就像 git hooks 一样。

Altering someone's shell namespace on the fly without their active cooperation can and will be accurately described as malware.在没有他们积极合作的情况下动态更改某人的 shell 命名空间可以并且将被准确地描述为恶意软件。

Include a setup command they can source if they want.包括他们可以根据需要获取的设置命令。

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

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