diff --git a/containers/buildkite-windows/pre-checkout.bat b/containers/buildkite-windows/pre-checkout.bat index fad618c..ec23492 100644 --- a/containers/buildkite-windows/pre-checkout.bat +++ b/containers/buildkite-windows/pre-checkout.bat @@ -1,2 +1,2 @@ REM TODO: use powershell shell for hooks directly -powershell c:\scripts\pre-checkout.ps1 \ No newline at end of file +bash c:\scripts\pre-checkout.sh \ No newline at end of file diff --git a/containers/buildkite-windows/pre-checkout.sh b/containers/buildkite-windows/pre-checkout.sh new file mode 100644 index 0000000..aca9da0 --- /dev/null +++ b/containers/buildkite-windows/pre-checkout.sh @@ -0,0 +1,26 @@ +#/usr/bin/env bash + +echo "BUILDKITE_BUILD_CHECKOUT_PATH: $BUILDKITE_BUILD_CHECKOUT_PATH" +echo "BUILDKITE_BUILD_PATH: $BUILDKITE_BUILD_PATH" +echo "unlocking git" +pkill -f git.exe +rm -f "$BUILDKITE_BUILD_CHECKOUT_PATH/.git/index.lock" +echo 'running processes (before)' +ps aux | grep "$BUILDKITE_BUILD_CHECKOUT_PATH" +echo "unlocking $BUILDKITE_BUILD_CHECKOUT_PATH" +handle -nobanner "$BUILDKITE_BUILD_CHECKOUT_PATH" +powershell /c/scripts/unlock_path.ps1 "$BUILDKITE_BUILD_CHECKOUT_PATH" +echo 'running processes (after)' +ps aux | grep "$BUILDKITE_BUILD_CHECKOUT_PATH" + +echo "BUILDKITE_REPO: $BUILDKITE_REPO" +if [ -d "$BUILDKITE_BUILD_CHECKOUT_PATH" ]; then + cd "$BUILDKITE_BUILD_CHECKOUT_PATH" || exit + remoteUrl=$(git remote get-url origin) + echo "current remote URL: $remoteUrl" + if [ "$remoteUrl" != "$BUILDKITE_REPO" ]; then + echo "Remote URL does not match. Deleting and recreating the directory." + cd /c/ + rm -rf "$BUILDKITE_BUILD_CHECKOUT_PATH" + fi +fi \ No newline at end of file