fix: enhance git pull handling in bootstrap script to manage local changes
This commit is contained in:
19
bootstrap.sh
19
bootstrap.sh
@@ -9,13 +9,26 @@ 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"
|
||||
fi
|
||||
|
||||
cd "$DOTFILES_DIR"
|
||||
fi
|
||||
|
||||
# Branch selection - allows choosing which version of dotfiles to install
|
||||
# - New installs: git clone defaults to 'main', but you can switch to any branch
|
||||
|
||||
Reference in New Issue
Block a user