summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdot/local/bin/git-ll-remote111
1 files changed, 82 insertions, 29 deletions
diff --git a/dot/local/bin/git-ll-remote b/dot/local/bin/git-ll-remote
index 3cc4130..aee13db 100755
--- a/dot/local/bin/git-ll-remote
+++ b/dot/local/bin/git-ll-remote
@@ -27,35 +27,80 @@ have_ref()
27 27
28show_all_message() 28show_all_message()
29{ 29{
30 >&2 printf '%s\n' \ 30 cat >&2 <<EOF
31 'Showing all remote branches:' \ 31Showing all remote branches:
32 ''
33 32
33EOF
34} 34}
35 35
36show_normal_message() 36show_all_none_message()
37{ 37{
38 >&2 printf '%s\n' \ 38 cat >&2 <<EOF
39 'Showing remote branches that have pushed onto your HEAD:' \ 39No remote branches.
40 '' 40EOF
41} 41}
42 42
43show_reverse_message() 43show_ahead_message()
44{ 44{
45 >&2 printf '%s\n' \ 45 cat >&2 <<EOF
46 'Showing branches unmerged on the REMOTE side (THEY need YOUR changes)' \ 46Showing remote branches that are ahead (they have pushed onto your HEAD):
47 'because "-r" (reverse) was specified:' \ 47
48 '' 48EOF
49}
50
51show_ahead_none_message()
52{
53 x=$(cat <<EOF)
54No remote branches are ahead of your HEAD. %d remote branches were not listed.
55EOF
56 printf "$x\n" "$1" >&2
57
58}
59
60show_behind_message()
61{
62 cat >&2 <<EOF
63Showing remote branches that are behind (your HEAD has commits on top of
64the remote branch):
65
66EOF
67}
68
69show_behind_none_message()
70{
71 x=$(cat <<EOF)
72No remotes branches are behind your HEAD. %d other remote branches were not
73listed.
74EOF
75 printf "$x\n" "$1" >&2
76
77}
78
79show_upto_message()
80{
81 cat >&2 <<EOF
82Showing remote branches that are even with your HEAD.
83
84EOF
85}
86
87show_upto_none_message()
88{
89x=$(cat <<EOF)
90No remote branches are even with your HEAD. %d other remote branches were not
91listed.
92EOF
93 printf "$x\n" "$1" >&2
49} 94}
50 95
96SHOW=ahead
97[ "$OPT_a" ] && SHOW=all
98[ "$OPT_r" ] && SHOW=behind
99[ "$OPT_u" ] && SHOW=upto
100
51show_message() 101show_message()
52{ 102{
53 if [ "$OPT_a" ] 103 show_${SHOW}_message
54 then show_all_message
55 elif [ "$OPT_r" ]
56 then show_reverse_message
57 else show_normal_message
58 fi
59} 104}
60 105
61git_fetch() 106git_fetch()
@@ -64,23 +109,36 @@ git_fetch()
64 have_ref "$hash" || git fetch "$remote" "$ref" 109 have_ref "$hash" || git fetch "$remote" "$ref"
65} 110}
66 111
112is_same_ref()
113{
114 [ "$1" = "$2 " ] || [ "$(git rev-parse "$1")" = "$(git rev-parse "$2")" ]
115}
116
67is_ancestor() 117is_ancestor()
68{ 118{
69 if [ "$1" = "$2 " ] 119 if is_same_ref "$1" "$2"
70 then false
71 elif [ "$(git rev-parse "$1")" = "$(git rev-parse "$2")" ]
72 then false 120 then false
73 else git merge-base --is-ancestor "$1" "$2" 121 else git merge-base --is-ancestor "$1" "$2"
74 fi 122 fi
75} 123}
76 124
125show_this_remote_branch()
126{
127 local hash="$1"
128 case "$SHOW" in
129 all) true ;;
130 behind) is_ancestor "$hash" HEAD ;;
131 ahead) is_ancestor HEAD "$hash" ;;
132 upto) is_same_ref HEAD "$hash" ;;
133 esac
134}
135
77handle_hash_ref() 136handle_hash_ref()
78{ 137{
79 local hash="$1" ref="$2" 138 local hash="$1" ref="$2"
80 git_fetch "$hash" "$ref" || exit 139 git_fetch "$hash" "$ref" || exit
81 140
82 [ "$OPT_r" ] && set -- "$hash" HEAD || set -- HEAD "$hash" 141 if show_this_remote_branch "$hash"
83 if [ "$OPT_a" ] || is_ancestor "$1" "$2"
84 then 142 then
85 if [ ! "$OPT_q" -a "$listed" -eq 0 ] 143 if [ ! "$OPT_q" -a "$listed" -eq 0 ]
86 then 144 then
@@ -108,12 +166,7 @@ finalize()
108{ 166{
109 if [ "$listed" -eq 0 ] 167 if [ "$listed" -eq 0 ]
110 then 168 then
111 if [ "$OPT_r" ] 169 show_${SHOW}_none_message "$skipped"
112 then
113 >&2 printf 'Already up-to-date. (No remotes are ancestors of your HEAD; %d remotes up-to-date.)\n' "$skipped"
114 else
115 >&2 printf 'Already up-to-date. (No remotes have pushed onto your HEAD; %d remotes up-to-date.)\n' "$skipped"
116 fi
117 fi 170 fi
118} 171}
119 172