summaryrefslogtreecommitdiff
path: root/cron/dotfiles_status
blob: 3fccb0a0b7168c79dd526d6623a4559ef8ece526 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

# check that the dotfiles repository is up-to-date and clean
# otherwise create the dirty stamp file

dotfiles_dir=~/.config/dotfiles
dirty_stamp=~/.local/var/dotfiles/dirty

[ -d "${dotfiles_dir}" ] || (echo "no dotfiles dir" && exit 1)

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 "${dirty_stamp}"
fi