Skip to content

Commit bcce8a9

Browse files
author
Amna Akram
authored
Update checkout
1 parent f40a0c8 commit bcce8a9

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

hooks/checkout

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fi
2121
SKIP_SSH_KEYSCAN_OPTION="$(plugin_read_config SKIP_SSH_KEYSCAN "false")"
2222
CLEAN_CHECKOUT_OPTION="$(plugin_read_config CLEAN_CHECKOUT "false")"
2323

24+
if [[ "${CLEAN_CHECKOUT_OPTION}" = "true" ]]; then
25+
echo "⚠️ WARNING: clean_checkout is enabled - this will destroy any local changes and reset the repository state"
26+
fi
27+
2428
if [[ -n "${BUILDKITE_REPO_SSH_HOST:-}" ]] && [[ "${SKIP_SSH_KEYSCAN_OPTION}" = "false" ]] ; then
2529
echo "Scanning SSH keys for remote git repository"
2630
[[ -d ~/.ssh ]] || mkdir -p ~/.ssh
@@ -45,15 +49,23 @@ fi
4549
# Enable clean checkout option to deal with corrupted repository states
4650
if [[ "${CLEAN_CHECKOUT_OPTION}" = "true" ]]; then
4751
echo "Clean checkout enabled - resetting repository state"
48-
# Reset any changes that might prevent checkout
49-
git reset --hard HEAD 2>/dev/null || true
50-
# Clean all untracked files and directories
51-
git clean -ffxdq
52-
# Reset sparse-checkout configuration
53-
git sparse-checkout disable 2>/dev/null || true
54-
else
55-
git clean -ffxdq
56-
fi
52+
# Remove index lock files
53+
find .git -name "*.lock" -delete 2>/dev/null || true
54+
# Reset index if corrupted
55+
if ! git status >/dev/null 2>&1; then
56+
rm -f .git/index 2>/dev/null || true
57+
fi
58+
# Disable sparse-checkout
59+
git sparse-checkout disable 2>/dev/null || true
60+
# Clean and reset
61+
git clean -ffxdq
62+
63+
if git rev-parse --verify HEAD >/dev/null 2>&1; then
64+
git reset --hard HEAD
65+
fi
66+
else
67+
git clean -ffxdq
68+
fi
5769

5870
FETCH_FLAGS=()
5971
if [[ -n "${BUILDKITE_GIT_FETCH_FLAGS:-}" ]]; then

0 commit comments

Comments
 (0)