#!/bin/bash # check that the dotfiles repository is up-to-date and clean # otherwise create the dirty stamp file script_path=$(realpath "$0") script_dir=$(dirname "${script_path}") dotfiles_dir=$(realpath "${script_dir}/..") dirty_stamp=~/.local/var/dotfiles/dirty if [ ! -d "${dotfiles_dir}" ]; then echo "no dotfiles dir" exit 1 fi git -C "${dotfiles_dir}" fetch -q --all || (echo "error updating remote" && exit 1) count=$(git -C "${dotfiles_dir}" rev-list --left-right --count '@{upstream}'...HEAD 2>/dev/null | grep -v '^0\s0$') git -C "${dotfiles_dir}" diff --exit-code >/dev/null repo_dirty=$? if [[ -n "${count}" || $repo_dirty -ne 0 ]]; then touch "${dirty_stamp}" else rm -f "${dirty_stamp}" fi