我想阻止调试函数var_dump, print_r, etc...被提交到repo,以便QA可以检查一些事情而不报告诸如"所有页面上都有大量文本!!"之类的错误.
我试过正则表达式(不是一个好主意......大概).
我也试过token_get_all但是由于某种原因,它会返回T_STRING每个调试函数,我想这会起作用,但它看起来很奇怪......
还有第三种更好的方法吗?
我试图使用git的预提交钩子.钩子如下所示:
#!/bin/bash
echo "fail"
exit 1
Run Code Online (Sandbox Code Playgroud)
因此,它总是会失败,即我的git提交应该失败.
如果我用git添加一些东西然后在命令行中提交它我很快就会失败并且我的提交失败了.
但是,如果我使用netbeans,我的预提交挂钩不会被执行.它似乎忽略了它.
我正在使用Ubuntu和Netbeans 7.1.预提交挂钩的权限是-rwxrwxrwx(为了测试目的,只需将其更改为777).
这怎么可能?
我正在尝试编写git pre-commit钩子脚本,它应该在修改文件的开头写入提交日期.我的问题是我无法将修改过的文件添加到以前的提交中.当我再次尝试调用git commit时,它会运行递归.如何编写脚本,在修改后的文件末尾添加修改时间?
我的代码:
#!/bin/bash
files_modified=`git diff-index --name-only HEAD`
for f in $files_modified; do
if [[ $f == *.groovy ]]; then
$line = $(head -1 f)
if [[ $line == "/%%*" ]];
then
sed -i 1d
fi
echo "/%% " + $(date +"%m_%d_%Y") + " %%\\" >> f
git add f
fi
done
git commit --amend #recursive
exit
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写服务器端预接收git挂钩来评估提交时的提交.
根据这里的答案,通过搜索git日志并使用'format:'过滤掉我想要的内容,这很容易实现.
我创建了以下预提交脚本.
#!/bin/bash
set -x #for debugging, TODO: remove
echo "parameters are" $@
echo "1 is " $1
#List of banned users
bannedusers=( root )
author_name=$(git show --pretty=oneline --pretty=format:%an | head -n1)
author_email=$(git show --pretty=oneline --pretty=format:%ae | head -n1)
committer_name=$(git show --pretty=oneline --pretty=format:%cn | head -n1)
committer_email=$(git show --pretty=oneline --pretty=format:%ce | head -n1)
commit_users=( "${author_name}" "${committer_name}" )
for acommituser in "${commit_users[@]}"
do
:
echo $acommituser #for debugging, TODO: remove
for abanneduser in "${bannedusers[@]}"
do
: …Run Code Online (Sandbox Code Playgroud) 我的情况是这样的:我在家里安装了Subversion服务器,我们也在我工作的公司使用Subversion.
在工作中,我们使用锁定/编辑/解锁模型(主要是因为我们正在从Visual SourceSafe转换,目前更容易).目前,这是通过在所有添加的文件上设置'needs-lock'属性来实现的(使用每个客户端计算机上的SVN客户端配置文件的auto-props部分).
但是,我不想将这个模型用于我的家庭SVN服务器(我更喜欢编辑/合并/提交工作方式),所以目前我从工作PC到家庭服务器提交任何东西后,我必须手动删除我添加的任何文件的needs-lock属性.
有没有办法设置SVN客户端只将此属性应用于提交给特定服务器的文件?或者我是以错误的方式去做的:我应该在工作服务器上使用钩子来添加这个属性而不是客户端吗?
非常感谢任何帮助或建议.
编辑:显然,你不能在服务器上这样做(或至少强烈建议你不这样做).
我需要实现一个SVN预提交钩子,它执行一个本身存储在SVN中的脚本.
我可以使用该svn cat命令将该脚本传递给Python解释器,如下所示:
svn cat file://$REPO/trunk/my_script.py | python - --argument1 --argument2
Run Code Online (Sandbox Code Playgroud)
但是,my_script.py它本身需要在STDIN上传输数据.
该数据不存储在文件中; 它存储在网络上.我宁愿不必将数据下载到临时文件,因为通常我可以将它传递给Python程序:
curl http://example.com/huge_file.txt | python my_script.py
Run Code Online (Sandbox Code Playgroud)
我不确定如何将这两种管道结合起来.
我们希望在我们的git存储库中执行推送的每个人在完成之前运行"grunt".我们通过在具有推前钩执行本.git/hooks/pre-push和写作npm install,并grunt在该文件中.
我们还有一个TFS存储库.我正在寻找在这里使用的类似逻辑.意思是,我们希望有一个排序的"门控签入"当有人试图检查的东西,这只会启动PowerShell和运行npm install,并grunt 在本地.
我们不希望TFS做任何其他事情(运行构建,运行测试等等(所有这些都在grunt任务中完成)).
这可能吗?谁知道怎么样?
我们有一个特定的要求,我们必须将所有到达的文件推送到某个分支.
我们计划通过git hooks专门实现commit-msg hook来实现这一点.
在这样做的同时,我们将分支克隆到临时位置(/ tmp /),然后在git commit-msg钩子中,尝试将到达的文件提交到某个分支.
但现在发生的是我们在/ tmp /中看到所有文件都被删除了.
粗体commit-msg脚本如下: -
#!/bin/bash
#
#!/usr/bin/env bash
#git config credential.helper store
REPOSRC="https://<USER>:<PASS>@<REPO_URL>"
LOCALREPO="<LOCAL_REPO_DIR>"
echo "Pulling code to temporarry location";
cd /tmp && git clone "${REPOSRC}" || (cd "${LOCALREPO}"; git pull;)
#here when I navigate to /tmp/<LOCALREPO> all files are listed as DELETED
git diff --cached --name-status | while read st file; do
echo "file == $file and status == $st";
if [ "$st" == "A" ]; then
cd "${LOCALREPO}" && …Run Code Online (Sandbox Code Playgroud) 如何获取包含环境变量导出的 bash 脚本?
env.sh
...
export VARIABLE=test
...
Run Code Online (Sandbox Code Playgroud)
test_file.py
...
os.environ['VARIABLE'] # Throws KeyError
...
Run Code Online (Sandbox Code Playgroud)
如何使用预提交运行env.sh来设置以下pytest钩子可以使用的环境?
- repo: local
hooks:
- id: tests
name: run tests
entry: pytest -v
language: system
types: [python]
Run Code Online (Sandbox Code Playgroud) 我在 Mac Mojave 上。我在 ~/.git-templates/hooks/pre-commit 创建了一个文件,我想从我提交的文件的行尾删除空格。我希望这能在我所有的项目中在全球范围内发生。
# A git hook script to find and fix trailing whitespace in your commits. Bypass
# it with the --no-verify option to git-commit.
# detect platform
platform="win"
uname_result=`uname`
if [[ "$uname_result" == "Linux" ]]; then
platform="linux"
elif [[ "$uname_result" == "Darwin" ]]; then
platform="mac"
fi
# change IFS to ignore filename's space in |for|
IFS="
"
# remove trailing whitespace in modified lines
for line in `git diff --check --cached | sed '/^[+-]/d'` ; …Run Code Online (Sandbox Code Playgroud) pre-commit-hook ×10
git ×6
bash ×3
svn ×3
commit ×2
githooks ×2
pre-commit ×2
debugging ×1
gruntjs ×1
hook ×1
netbeans ×1
php ×1
pipe ×1
properties ×1
pytest ×1
python ×1
python-3.x ×1
tfs ×1
whitespace ×1