-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpushed
executable file
·73 lines (65 loc) · 1.92 KB
/
pushed
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
#!/usr/bin/env bash
dir="$(dirname $0)/ocaml"
if [[ ! -d $dir ]]; then
echo "Expect OCaml clone in $dir" >&2
exit 1
fi
cd "$dir"
if ! git rev-parse --verify origin/trunk &> /dev/null; then
echo 'Could not find origin/trunk' >&2
exit 1
fi
NO_REMOTE=()
PUSHED=()
OUT_OF_SYNC=()
while read -r branch; do
remote=${branch#* }
if [[ $remote = $branch ]]; then
case $branch in
backport-5.0|backport-4.*) continue;;
esac
NO_REMOTE+=("$branch")
else
branch=${branch% *}
case $branch,$remote in
backport-5.0,*|backport-4.*,*) continue;;
*,origin/*) ;;
*) continue;;
esac
if [[ $(git rev-parse "$branch") = $(git rev-parse "$remote") ]]; then
PUSHED+=("$branch to $remote")
else
our_timestamp="$(git log -1 --format=%cd --date=unix $branch)"
remote_timestamp="$(git log -1 --format=%cd --date=unix $remote)"
if [[ $our_timestamp -gt $remote_timestamp ]]; then
sync='\e[32mnewer'
head_colour=32
remote_colour=0
else
sync='\e[33molder'
head_colour=33
remote_colour=0
fi
sync="$sync\\e[0m (\\e[${head_colour}m$(date --date=@$our_timestamp '+%d-%b-%Y %H:%M:%S')\\e[0m vs \\e[${remote_colour}m$(date --date=@$remote_timestamp '+%d-%b-%Y %H:%M:%S')\\e[0m)"
OUT_OF_SYNC+=("$branch with $remote $(git for-each-ref --format='%(push:track)' refs/heads/$branch) - HEAD is $sync")
fi
fi
done < <(git branch --format='%(refname:lstrip=2) %(upstream:lstrip=2)')
if [[ ${#PUSHED[@]} -gt 0 ]]; then
echo -e "\e[32mUp-to-date\e[0m"
for branch in "${PUSHED[@]}"; do
echo " - $branch"
done
fi
if [[ ${#NO_REMOTE[@]} -gt 0 ]]; then
echo -e "\e[31mUntracked branches\e[0m"
for branch in "${NO_REMOTE[@]}"; do
echo " - $branch"
done
fi
if [[ ${#OUT_OF_SYNC[@]} -gt 0 ]]; then
echo -e "\e[33mOut-of-sync with origin\e[0m"
for branch in "${OUT_OF_SYNC[@]}"; do
echo -e " - $branch"
done
fi