48 lines
1.3 KiB
Bash
Executable File
48 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
BOLD='\033[1m'
|
|
GREEN='\033[32m'
|
|
BLUE='\033[34m'
|
|
RED='\033[31m'
|
|
NC='\033[0m'
|
|
|
|
dgit(){
|
|
git -C "$STOW_DIR/$DOTS_PACKAGE" $@
|
|
}
|
|
|
|
printf "%b" "${BOLD}${BLUE}Removing dotfile symlinks...$NC\n\n"
|
|
stow -D -d "$STOW_DIR" -t "$HOME" "$DOTS_PACKAGE" || printf "%b" "${RED}Failed to run stow!$NC\n"
|
|
|
|
printf "%b" "${BOLD}${BLUE}Stashing existing changes...$NC\n"
|
|
stash_result=$(dgit stash push)
|
|
needs_pop=1
|
|
if [ "$stash_result" = "No local changes to save" ]; then
|
|
needs_pop=0
|
|
fi
|
|
printf "\n"
|
|
|
|
printf "%b" "${BOLD}${BLUE}Pulling updates from dotfiles repo...$NC\n"
|
|
old_commit="$(dgit rev-parse HEAD)"
|
|
dgit pull origin main
|
|
dgit submodule update --remote --merge
|
|
printf "\n"
|
|
|
|
if [ $needs_pop -eq 1 ]; then
|
|
printf "%b" "${BOLD}${BLUE}Popping stashed changes...$NC\n"
|
|
dgit stash pop
|
|
fi
|
|
printf "\n"
|
|
|
|
unmerged_files=$(dgit diff --name-only --diff-filter=U)
|
|
if [ -n "$unmerged_files" ]; then
|
|
printf "%b" "${RED}The following files have merge conflicts after popping the stash:$NC\n\n"
|
|
printf "%s" "$unmerged_files\n\n"
|
|
printf "%s" "${BOLD}${BLUE}Reverting to previous commit...$NC"
|
|
dgit checkout "$old_commit"
|
|
fi
|
|
|
|
printf "%b" "${BOLD}${BLUE}Symlinking dotfiles...$NC\n\n"
|
|
stow -d "$STOW_DIR" -t "$HOME" "$DOTS_PACKAGE" || printf "%b" "${RED}Failed to run stow!$NC\n"
|
|
|
|
printf "%b" "${BOLD}${GREEN}Dotfiles synced successfully!$NC\n"
|