Git不在预提交钩子中使用分阶段源

时间:2017-10-11 13:01:16

标签: java git maven githooks

我在预提交挂钩中使用此脚本在我将更改推送到git之前进行一些检查。

#!/bin/bash
mvn clean compile -DskipTests &> $TEMP/cc.txt &
A=$!
wait $A
A=$?

if test "$A" != "0"
then
  cat $TEMP/cc.txt
  exit 1
fi

mvn javadoc:javadoc -T 8 &> $TEMP/jd.txt &
B=$!

mvn pmd:cpd-check &> $TEMP/pmd.txt &
C=$!

mvn org.jacoco:jacoco-maven-plugin:prepare-agent test org.jacoco:jacoco-maven-plugin:report -T 8 &> $TEMP/jcc.txt &
D=$!

mvn checkstyle:checkstyle -Dcheckstyle.config.location=https://XXXX &> $TEMP/cs.txt &
E=$!

wait $B
B=$?

wait $C
C=$?

wait $D
D=$?

wait $E
E=$?

mvn sonar:sonar -Dsonar.host.url=https://sonarcubeXXXX &> $TEMP/cq.txt &
F=$!
wait $F
F=$?

echo "compile $A, javadoc $B, pmd $C, jacoco $D, checkstyle $E, sonar $F"
if test "$A$B$C$D$E$F" != "000000"
then
  if test "$D" != "0"
  then
    cat $TEMP/jcc.txt
  fi

  if test "$F" != "0"
  then
    cat $TEMP/cq.txt
  fi
  exit 1
fi
exit 0

但只要pre-commit-hook正在运行(5分钟),我就无法工作并更改源文件。

我使用Sourcetree提交,sourcetree区分了分阶段和非分阶段文件。提交文件sourcetree时执行以下命令:

git -c diff.mnemonicprefix=false -c core.quotepath=false commit -q -F C:\Users\XXXX\AppData\Local\Temp\fbox5amv.k5f

问题:

如何访问预期的代码库(当前推送的内容+我已经上演并试图提交的内容)但不是在Sourcetree中没有进行的更改?

之前我使用过subversion-commit-hooks,它们是服务器端的,只能提取预期的代码库。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

由于没有其他答案,在提交(提交)之前,如果没有未进行的更改,可能无法访问staged + committed +推送的更改。

因此我不得不从预提交挂钩更改为post-commit挂钩并将脚本更改为:

#!/bin/bash
rm -rf ../committed
mkdir ../committed
cp -rf * ../committed/
cd ../committed
git stash save -u

mvn clean compile -DskipTests &> $TEMP/cc.txt &
(...)