#!/bin/bash # # Purpose : coredesktop-dev deployed: show the deployed copy of CoreDesktop # (~/.local/share/coredesktop), or put back its tracked files so # update can pull again deployed_usage() { cat << EOF Usage: coredesktop-dev deployed [status|restore] status Branch, commit, how far behind upstream, and local changes (default) restore Undo local changes to tracked files, after asking. Untracked files are listed and left alone. EOF } cmd_deployed() { case "${1:-status}" in -h | --help) deployed_usage; return 0 ;; status | restore) ;; *) deployed_usage >&2; return 1 ;; esac git -C "$COREDESKTOP" rev-parse --git-dir &> /dev/null \ || die "CoreDesktop isn't installed in $COREDESKTOP." "deployed_${1:-status}" } deployed_status() { local behind changes echo "Deployed copy: $COREDESKTOP" echo "Branch: $(git -C "$COREDESKTOP" rev-parse --abbrev-ref HEAD)" echo "Commit: $(git -C "$COREDESKTOP" log -1 --format='%cd (%h) %s' --date=format:%Y.%m.%d)" if GIT_TERMINAL_PROMPT=0 timeout 30 git -C "$COREDESKTOP" fetch --quiet &> /dev/null \ && behind="$(git -C "$COREDESKTOP" rev-list --count 'HEAD..@{upstream}' 2> /dev/null)"; then echo "Behind: $behind commits (update pulls them)" else echo "Behind: unknown (couldn't reach upstream)" fi changes="$(git -C "$COREDESKTOP" status --porcelain --untracked-files=no)" if [ -z "$changes" ]; then echo "Changes: none" else echo "Changes: these stop update from pulling (coredesktop-dev deployed restore):" echo "$changes" | sed 's/^/ /' fi } deployed_restore() { local untracked if [ -z "$(git -C "$COREDESKTOP" status --porcelain --untracked-files=no)" ]; then echo "The deployed copy has no local changes." return 0 fi git -C "$COREDESKTOP" diff HEAD --stat untracked="$(git -C "$COREDESKTOP" ls-files --others --exclude-standard)" if [ -n "$untracked" ]; then echo echo "Untracked files, which are left alone:" echo "$untracked" | sed 's/^/ /' fi echo if ! confirm "Undo the changes above in $COREDESKTOP?"; then echo "Nothing changed." return 1 fi git -C "$COREDESKTOP" checkout HEAD -- . || return 1 if [ -n "$(git -C "$COREDESKTOP" status --porcelain --untracked-files=no)" ]; then echo "Restored, but some changes remain (new files added to git's index?):" git -C "$COREDESKTOP" status --short --untracked-files=no return 1 fi echo "Restored. update can pull again." }