shell脚本正在为Flyway delta版本创建文件,该版本将新版本的所有更改应用到Oracle数据库中。
- "git checkout"带有所有新更改的新发布标签
- 检查"gitcheckout"调用的returncode是否正常
- 检索在版本之间已更改的所有文件的列表
- 更改后的文件基本上被复制到一个新目录中,并接收生成的Flyway2前缀
以后这些文件可以很容易地应用于Flyway。。。
最近发生的问题:步骤1可能由于"致命:无法创建"…/.git/index.lock":文件存在。"错误而失败(很可能是由于SourceTree的状态更新(。
不幸的是,在这种情况下,git的返回代码是0(意味着没有错误(,这意味着脚本没有注意到文件在步骤2中被而不是更新,并继续执行步骤3和4(但使用了错误的文件(。
在这个例子中,我试图通过等待"index.lock"被删除来避免这个问题,但是这不是故障安全的!在while循环传递之后,但在git签出之前,可能会创建一个index.lock,我再次遇到同样的问题。
GIT="Path to Git.exe"
INDEXLOCK="Path to potential .git/index.lock"
#Unfortunately git checkout returns 0 (everything is ok), when it failed due to an existing index.lock
#The script would then commence, although the sources were not checkout correctly!
#Loop until index.lock does not exist anymore
while [ -f "$INDEXLOCK" ]
do
echo "Index.lock exists! Waiting until open git process is finished."
sleep 5
done
echo " "
echo "Trying to check out tag: $2"
$GIT checkout "$2" -q
if [ $? = 1 ]; then
echo "Error: Can't checkout tag: $2"
exit;
fi
echo "Check out finished"
是否有可能确保shell脚本在出现".git/index.lock"错误时停止?
捕获stdout成功。我能够通过在目录中放置一个index.lock来验证功能。
GIT="Path to Git.exe"
INDEXLOCK="Path to potential .git/index.lock"
#Unfortunately git checkout returns 0 (everything is ok), when it failed due to an existing index.lock
#The script would then commence, although the sources were not checkout correctly!
#Loop until index.lock does not exist anymore
while [ -f "$INDEXLOCK" ]
do
echo "Index.lock exists! Waiting until open git process is finished."
sleep 5
done
echo " "
echo "Trying to check out tag: $2"
OUTPUT=$($GIT checkout "$2" -q 2>&1)
RETURNCODE=$?
if [[ $OUTPUT == *"fatal: Unable to create"*".git/index.lock': File exists."* ]];
then
echo "Error: Can't checkout release tag '$2' due to index.lock"
exit;
elif [ $RETURNCODE = 1 ]; then
echo "Error: Can't checkout tag: $2"
exit;
fi
echo " "
echo "Check out attempt finished"