每当我提交时,我都会担心我可能会错过依赖性,并且我正在寻找孤立测试我的git树的最简单方法,以确保GIT索引中的任何内容(“分阶段”)实际上会编译/运行他们自己的。

我的代码的依赖关系存在于文件系统中,从我进行的“ git add”和简单的编译和运行测试中,不能保证我检查的任何内容都会在干净的文件系统上查看树(或分阶段) 。

我可以有一个连续的构建,可以在提交后检查,但我宁愿在历史记录中不得不修补。因此,我想要一种创建一个孤立环境的方法,其中包括树木的结帐以及索引/舞台区域。

我考虑过的一件事是两次使用git藏匿处,即:

  1. 调用“ git stash”以将文件保存在索引中
  2. 以某种方式获取未跟踪的文件列表,“ git添加”所有这些文件,保存新的藏匿处
  3. 删除所有先前未跟踪的文件
  4. 恢复原始藏匿处
  5. 现在,我应该拥有一个干净的环境,该环境只有已经签名的代码和登台区域中的代码,我可以编译和测试。
  6. 完成后,我还原未跟踪的文件的藏匿处,然后解开跟踪,使我处于与我最初相同的位置。

(这些未跟踪的文件可能很有用,但不一定是我要签到存储库的东西 - 例如Eclipse Projects)。

不过,我感觉自己过度工程了一个简单的问题。

有帮助吗?

解决方案

安装此脚本(或类似的东西 - 我也被盗)作为预先承诺的钩子。它将索引复制到临时工作的DIR,并在那里运行一个构建。它将捕获您错过的文件。

我知道至少有一个或两个其他问题可以解决这个确切问题 - 测试/验证索引,而不是在预先承诺的挂钩中进行工作的DIR-但我现在似乎找不到它们。

(为了完整,我在我的回购中有此脚本为.git-hooks/pre-commit/test-thinex;那里还有其他几个脚本。挂钩/预签名。)

#!/bin/sh
#
# Via: http://github.com/jwiegley/git-scripts/blob/master/pre-commit.sh
#

if [ ! $(git rev-parse --symbolic-full-name HEAD) = refs/heads/master ]; then
    exit 0
fi

# These are the locations I keep my temporary source and build trees in
TMPDIR=$HOME/code/myproject-pre-commit
MIRROR=$HOME/code/myproject-pre-commit-mirror

# Exit with status 1 if any command below fails
set -e

# Checkout a copy of the current index into MIRROR
git checkout-index --prefix=$MIRROR/ -af

# Remove files from MIRROR which are no longer present in the index
git diff-index --cached --name-only --diff-filter=D -z HEAD | \
    (cd $MIRROR && xargs -0 rm -f --)

# Copy only _changed files_ from MIRROR to TMPDIR, without copying timestamps.
# This includes copying over new files, and deleting removed ones.  This way,
# "make check" will only rebuild what is necessary to validate the commit.
rsync -rlpgoDOc --delete --exclude-from=.git-hooks/excludes $MIRROR/ $TMPDIR/

# Everything else happens in the temporary build tree
cd $TMPDIR

nosetests

exit 0

这是我的实际.git/hooks/pre-commit:

#!/bin/bash

set -e
for hook in $(find .git-hooks/pre-commit -perm /u+x,g+x,o+x -type f -not -name '*~' 2>/dev/null)
do
  echo "@@ Running hook: $(basename $hook)"
  $hook "$@"
done

其他提示

git stash -u --keep-index 在测试之前,其次是 git stash pop 测试后。

设置忽略重要文件,只是删除那些不重要的文件 git clean -df

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top