diff options
author | Andrew Cady <d@jerkface.net> | 2021-10-06 18:15:05 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2021-10-06 18:15:05 -0400 |
commit | 183dbd37be9ebbaea201a29083ffdc61c859f56e (patch) | |
tree | 5d1376e83d1ed3758c89869ba5ae554010f5cfd1 | |
parent | b691b24ecc36d12f2f1e94c67a1108e3ca70e141 (diff) |
git-ll-remote: improve output greatly
-rwxr-xr-x | dot/local/bin/git-ll-remote | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/dot/local/bin/git-ll-remote b/dot/local/bin/git-ll-remote index 000e41d..a39ec3f 100755 --- a/dot/local/bin/git-ll-remote +++ b/dot/local/bin/git-ll-remote | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/bash |
2 | 2 | ||
3 | while [ $# -gt 0 ] | 3 | while [ $# -gt 0 ] |
4 | do | 4 | do |
@@ -20,12 +20,15 @@ done | |||
20 | 20 | ||
21 | remote=${1:-origin} | 21 | remote=${1:-origin} |
22 | 22 | ||
23 | SHOW=ahead | 23 | QUIET=y |
24 | [ "$OPT_a" ] && SHOW=all | 24 | SHOW=all |
25 | [ "$OPT_r" ] && SHOW=behind | 25 | [ "$OPT_a" ] && SHOW=ahead |
26 | [ "$OPT_A" ] && SHOW=all | ||
27 | [ "$OPT_b" ] && SHOW=behind | ||
26 | [ "$OPT_u" ] && SHOW=upto | 28 | [ "$OPT_u" ] && SHOW=upto |
27 | QUIET= | 29 | [ "$OPT_d" ] && SHOW=diverged |
28 | [ "$OPT_q" ] && QUIET=y | 30 | [ "$OPT_q" ] && QUIET=y |
31 | [ "$OPT_v" ] && QUIET= | ||
29 | [ "$OPT_n" ] && NS_ONLY=y | 32 | [ "$OPT_n" ] && NS_ONLY=y |
30 | [ "$OPT_N" ] && NS_ONLY= | 33 | [ "$OPT_N" ] && NS_ONLY= |
31 | 34 | ||
@@ -36,16 +39,27 @@ show_message() | |||
36 | 39 | ||
37 | show_all_message() | 40 | show_all_message() |
38 | { | 41 | { |
42 | return | ||
39 | cat >&2 <<EOF | 43 | cat >&2 <<EOF |
40 | Showing all remote branches: | 44 | Showing all remote branches: |
41 | 45 | ||
42 | EOF | 46 | EOF |
43 | } | 47 | } |
44 | 48 | ||
49 | show_diverged_message() | ||
50 | { | ||
51 | cat >&2 <<EOF | ||
52 | Showing remote branches that have commits ahead of yours | ||
53 | AND where you have commits ahead of theirs. | ||
54 | |||
55 | EOF | ||
56 | } | ||
57 | |||
45 | show_all_none_message() | 58 | show_all_none_message() |
46 | { | 59 | { |
47 | cat >&2 <<EOF | 60 | cat >&2 <<EOF |
48 | No remote branches. | 61 | No remote branches. |
62 | |||
49 | EOF | 63 | EOF |
50 | } | 64 | } |
51 | 65 | ||
@@ -138,37 +152,36 @@ verdict() | |||
138 | fi | 152 | fi |
139 | } | 153 | } |
140 | 154 | ||
141 | show_this_remote_branch() | ||
142 | { | ||
143 | local hash="$1" | ||
144 | case "$SHOW" in | ||
145 | all) VERDICT=$(verdict "$hash") ;; | ||
146 | behind) is_ancestor "$hash" HEAD ;; | ||
147 | ahead) is_ancestor HEAD "$hash" ;; | ||
148 | upto) is_same_ref HEAD "$hash" ;; | ||
149 | esac | ||
150 | } | ||
151 | |||
152 | handle_hash_ref() | 155 | handle_hash_ref() |
153 | { | 156 | { |
154 | local hash="$1" ref="$2" | 157 | local hash="$1" ref="$2" |
155 | git_fetch "$hash" "$ref" || exit | 158 | git_fetch "$hash" "$ref" || exit |
156 | 159 | ||
157 | if show_this_remote_branch "$hash" | 160 | VERDICT=$(verdict "$hash") |
161 | if [ "${SHOW%-*}" = all -o "$VERDICT" = "$SHOW" ] | ||
158 | then | 162 | then |
159 | if [ ! "$QUIET" -a "$listed" -eq 0 ] | 163 | if [ ! "$QUIET" -a "$listed" -eq 0 ] |
160 | then | 164 | then |
161 | show_message | 165 | show_message |
162 | fi | 166 | fi |
167 | more=$(git show -s "$hash" --pretty='%ar:%cn') || exit | ||
168 | IFS=: read when author <<< "$more" | ||
169 | subj=$(git show -s "$hash" --pretty='%s') | ||
170 | |||
171 | author_size=13 | ||
172 | author=${author:0:$author_size} | ||
163 | 173 | ||
164 | if [ "$SHOW" = all ] | 174 | subj_size=20 |
175 | subj_orig_size=${#subj} | ||
176 | subj=${subj:0:$subj_size} | ||
177 | if [ "$subj_orig_size" -ge "$subj_size" ] | ||
165 | then | 178 | then |
166 | >&2 printf 'remote: %s (%s)\n' "$ref" "$VERDICT" | 179 | # The length of the subject is allowed to be one longer only if it's truncated. |
167 | else | 180 | # The visual protrusion makes truncation unambiguous even in case literal "..." included in subject field. |
168 | >&2 printf 'remote: %s\n' "$ref" | 181 | subj=${subj%??}... |
169 | fi | 182 | fi |
170 | 183 | ||
171 | git show "$hash" | sed '/^$/q' | 184 | printf "%-42s %17s %-${author_size}s %-$((subj_size + 1))s %10s %s\n" "$hash" "$when" "$author" "$subj" "($VERDICT)" "$ref" |
172 | listed=$((listed + 1)) | 185 | listed=$((listed + 1)) |
173 | else | 186 | else |
174 | skipped=$((skipped + 1)) | 187 | skipped=$((skipped + 1)) |