ドライランがどのように失敗するか教えてください。エラーのある出力.txtはありますか?端末にエラーが表示されますか?
いずれの場合でも、事前コミットスクリプトの名前をpre-commit
とし、.git/hooks/
ディレクトリに保存する必要があります。
ドライランスクリプトがプリコミットスクリプトとは異なるパスにあるように見えるので、ここではスクリプトを見つけて実行する例を示します。
あなたはWindowsマシン上にあることをあなたのパスのバックスラッシュから想定しています。私はあなたのドライランスクリプトはgitがインストールされている同じプロジェクトに含まれていると仮定します。これを実際のフォルダに変更できます)。
#!/bin/sh
#Path of your python script
FILE_PATH=tools/run_tests.py/
#Get relative path of the root directory of the project
rdir=`git rev-parse --git-dir`
rel_path="$(dirname "$rdir")"
#Cd to that path and run the file.
cd $rel_path/$FILE_PATH
echo "Running dryrun script..."
python run_tests.py
#From that point on you need to handle the dry run error/s.
#For demonstrating purproses I'll asume that an output.txt file that holds
#the result is produced.
#Extract the result from the output file
final_res="tac output | grep -m 1 . | grep 'error'"
echo -e "--------Dry run result---------\n"${final_res}
#If a warning and/or error exists abort the commit
eval "$final_res" | while read -r line; do
if [ $line != "0" ]; then
echo -e "Dry run failed.\nAborting commit..."
exit 1
fi
done
今、あなたはgit commit -m
に、プリコミットスクリプトを発射するたびに予行演習ファイルを実行し、エラーがstaginエリアでファイルを保ち、発生した場合はコミット中止されます。
ありがとうございますkingJulian。返事にとても感謝しています。あなたの質問に - はい、outpul xmlが作成されます.1つのクリティカルテスト、0は合格、1は失敗などのステータスを持っています。またはいずれかの場合にコンソールログに "[エラー]"が表示される –
こんにちはkingJulian、複数のファイルをコミットするロジックを教えてください。 –
次に、xmlファイルを解析して、失敗したことを検索する必要があります。失敗した場合は、0以外の数字を前にして、コミットを中止する必要があります。 複数のファイルをコミットしたいときは、 'git add file1、file2、etc'でステージング領域に追加し、' git commit -m ""で1回コミットしてください。その後、プリコミットフックが正常に実行されます。 –
kingJulian