From 2ef00a0dd9ec218eece0fc0026a64b0c0b52db97 Mon Sep 17 00:00:00 2001 From: Ryan Hamilton Date: Mon, 4 Aug 2025 20:51:13 -0500 Subject: [PATCH] fix: enhance git pull handling in bootstrap script to manage local changes --- bootstrap.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 0aabd52..e8a1719 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -9,14 +9,27 @@ echo "Starting dotfiles bootstrap..." # Clone repo (new installs) or update for branch switching if [ -d "$DOTFILES_DIR/.git" ]; then echo "Updating existing dotfiles repo..." - git -C "$DOTFILES_DIR" pull --quiet + cd "$DOTFILES_DIR" + + # Handle local changes if they exist + if ! git diff-index --quiet HEAD --; then + echo "Local changes detected:" + echo "1) Discard 2) Stash 3) Abort" + read -p "Choice (1-3): " choice + case $choice in + 1) git reset --hard HEAD ;; + 2) git stash push -m "Bootstrap $(date +%Y%m%d-%H%M)" ;; + *) echo "Aborted. Check 'git status' in $DOTFILES_DIR"; exit 1 ;; + esac + fi + + git pull --quiet || { echo "Error: Failed to update repository"; exit 1; } else echo "Cloning dotfiles into $DOTFILES_DIR..." git clone "$DOTFILES_REPO" "$DOTFILES_DIR" + cd "$DOTFILES_DIR" fi -cd "$DOTFILES_DIR" - # Branch selection - allows choosing which version of dotfiles to install # - New installs: git clone defaults to 'main', but you can switch to any branch # - Existing installs: switch from current branch to a different one