The shell-script is creating files for a Flyway delta release, which applies all changes for a new release into an Oracle database.
- "git checkout" new release-tag with all the new changes
- Check that returncode of the "git checkout" call is ok
- Retrieve a list of all files, which have changed between the releases
- Files, which have changed are basically copied to a new directory and receive a generated prefix for Flyway2
Later on those files can be easily applied with Flyway...
Problem that happened recently: Step 1 might fail due to a "fatal: Unable to create '.../.git/index.lock': File exists." error (Most likely due to a status update by SourceTree).
Unfortunately git's returncode is 0 in this case (meaning no error), which means the script does not notice, that the files were not updated in step 2 and goes on with steps 3 and 4 (but with wrong files).
In this example I try to circumvent the problem by waiting until the "index.lock" is removed, however this is not fail safe! There might be a index.lock created right after the while-loop is passed, but before the git checkout and I have the same problem again.
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"
Is there a possibilty to make sure the shell-script stops on a ".git/index.lock" error?