summaryrefslogtreecommitdiff
path: root/sib-status
blob: ef16810ec272c0bb7ab20d2a2f90f44a951d0795 (plain)
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
#!/usr/bin/env bash
# Copyright 2026 Hee-Suk Kim <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

head_refs=()
ancestor_refs=()

head_ref=$(sib git symbolic-ref -q HEAD 2>/dev/null || :)
head_hash=$(sib git rev-parse -q --verify HEAD 2>/dev/null || :)

printf 'SIB_DIR:      %s\n' "$SIB_DIR"
printf 'PLM_MODEL:    %s\n' "$PLM_MODEL"
printf 'PLM_ENDPOINT: %s\n' "$PLM_ENDPOINT"

printf '\n'
if [[ -z $head_hash ]]; then
    printf 'HEAD: (unborn)\n'
    exit
fi

head_short=$(sib git rev-parse --short "$head_hash")

# refs/conv/* pointing current HEAD
head_refs=()
while IFS= read -r line; do
    head_refs+=("$line")
done < <(
    sib git for-each-ref \
         --format='%(refname:strip=2)' \
         --points-at="$head_hash" \
         refs/conv/
)

if [[ -n $head_ref ]]; then
    printf 'HEAD: %s -> %s' "$head_ref" "$head_short"
else
    printf 'HEAD: %s' "$head_short"
fi

if ((${#head_refs[@]})); then
    printf ' ('

    separator=
    for ref in "${head_refs[@]}"; do
        printf '%s%s' "$separator" "$ref"
        separator=', '
    done
    printf ')'
fi

[[ -n $head_ref ]] || printf ' [detached]'
printf '\n'

# Refs on ancestor chain
while read -r object ref; do
    [[ $object == "$head_hash" ]] && continue
    ancestor_refs+=("$ref")
done < <(
    sib git for-each-ref \
         --format='%(objectname) %(refname)' \
         --merged="$head_hash" \
         refs/conv/
)

((${#ancestor_refs[@]})) || exit

printf '\nchain (HEAD -> root):\n'
if parent=$(sib git rev-parse -q --verify "$head_hash" 2>/dev/null); then
    sib git --no-pager log \
         --graph \
         --color=never \
         --decorate=full \
         --decorate-refs=HEAD \
         --decorate-refs='refs/conv/*' \
         --simplify-by-decoration \
         --format='%h %d' \
         "$parent"
fi