aboutsummaryrefslogtreecommitdiffstats
path: root/archive/update-dots.sh
blob: 4ac97bec500a34be058261cf8cf5ef08f05269e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
# ==================================================
#  KoolDots (2026)
#  Project URL: https://github.com/LinuxBeginnings
#  License: GNU GPLv3
#  SPDX-License-Identifier: GPL-3.0-or-later
# ==================================================
set -euo pipefail
IFS=$'\n\t'

if [[ -t 1 ]]; then
  BOLD="$(tput bold || true)"
  DIM="$(tput dim || true)"
  RED="$(tput setaf 1 || true)"
  GREEN="$(tput setaf 2 || true)"
  YELLOW="$(tput setaf 3 || true)"
  BLUE="$(tput setaf 4 || true)"
  RESET="$(tput sgr0 || true)"
else
  BOLD=""; DIM=""; RED=""; GREEN=""; YELLOW=""; BLUE=""; RESET=""
fi

log() { printf "%b\n" "${BLUE}==>${RESET} $*"; }
ok() { printf "%b\n" "${GREEN}✔${RESET} $*"; }
warn() { printf "%b\n" "${YELLOW}⚠${RESET} $*"; }
err() { printf "%b\n" "${RED}✖${RESET} $*"; }

log "${BOLD}Hyprland-Dots updater${RESET}"

if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
  err "Not inside a git repository."
  exit 1
fi

branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$branch" == "HEAD" ]]; then
  warn "Detached HEAD state detected."
fi

log "Fetching remote updates..."
git fetch --tags --quiet

upstream=""
if git rev-parse --abbrev-ref --symbolic-full-name "@{u}" >/dev/null 2>&1; then
  upstream="$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}")"
else
  if git show-ref --verify --quiet "refs/remotes/origin/${branch}"; then
    upstream="origin/${branch}"
  fi
fi

if [[ -z "$upstream" ]]; then
  err "No upstream found for branch '${branch}'."
  exit 1
fi

log "Current branch: ${BOLD}${branch}${RESET}"
log "Upstream: ${BOLD}${upstream}${RESET}"

behind_count="$(git rev-list --count "HEAD..${upstream}")"
ahead_count="$(git rev-list --count "${upstream}..HEAD")"

if [[ "$behind_count" -eq 0 ]]; then
  ok "Already up to date with ${upstream}."
  if [[ "$ahead_count" -gt 0 ]]; then
    warn "Local branch is ahead by ${ahead_count} commit(s)."
  fi
  exit 0
fi

warn "Updates available: behind by ${behind_count} commit(s)."
read -r -p "Update now? [y/N] " reply
case "${reply:-}" in
  y|Y|yes|YES)
    log "Stashing local changes..."
    git stash -u

    log "Pulling latest changes from ${upstream}..."
    git pull

    ok "Update complete."
    printf "%b\n" "${DIM}Next: run ./copy.sh to upgrade the Hyprland dotfiles.${RESET}"
    ;;
  *)
    warn "Update cancelled."
    ;;
esac
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage