diff options
Diffstat (limited to 'dot')
-rwxr-xr-x | dot/local/bin/git-ll-remote | 111 |
1 files changed, 104 insertions, 7 deletions
diff --git a/dot/local/bin/git-ll-remote b/dot/local/bin/git-ll-remote index 4052a41..a0e689b 100755 --- a/dot/local/bin/git-ll-remote +++ b/dot/local/bin/git-ll-remote | |||
@@ -1,12 +1,109 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | while [ $# -gt 0 ] | ||
4 | do | ||
5 | case "$1" in | ||
6 | --) shift; break;; | ||
7 | -?) eval "OPT_${1#-}=y" | ||
8 | shift | ||
9 | ;; | ||
10 | --*=*) kv=${1#--} | ||
11 | k=${kv##=*} | ||
12 | v=${kv%*=} | ||
13 | eval "OPT_${k}=\$1" "$v" | ||
14 | shift | ||
15 | ;; | ||
16 | -*) exit 1;; | ||
17 | *) break;; | ||
18 | esac | ||
19 | done | ||
20 | |||
3 | remote=${1:-origin} | 21 | remote=${1:-origin} |
4 | 22 | ||
5 | git ls-remote $remote | | 23 | have_ref() |
24 | { | ||
25 | git rev-list --quiet "$1" 2>/dev/null | ||
26 | } | ||
27 | |||
28 | show_all_message() | ||
29 | { | ||
30 | >&2 printf '%s\n' \ | ||
31 | 'Showing all remote branches:' \ | ||
32 | '' | ||
33 | |||
34 | } | ||
35 | |||
36 | show_normal_message() | ||
37 | { | ||
38 | >&2 printf '%s\n' \ | ||
39 | 'Showing remote branches that have pushed onto your HEAD:' \ | ||
40 | '' | ||
41 | } | ||
42 | |||
43 | show_reverse_message() | ||
44 | { | ||
45 | >&2 printf '%s\n' \ | ||
46 | 'Showing branches unmerged on the REMOTE side (THEY need YOUR changes)' \ | ||
47 | 'because "-r" (reverse) was specified:' \ | ||
48 | '' | ||
49 | } | ||
50 | |||
51 | handle_hash_ref() | ||
52 | { | ||
53 | local hash="$1" ref="$2" | ||
54 | if ! have_ref $hash | ||
55 | then | ||
56 | git fetch $remote $ref; | ||
57 | fi | ||
58 | if [ -z "$OPT_r" ] | ||
59 | then | ||
60 | cmd="git merge-base --is-ancestor HEAD $hash" | ||
61 | else | ||
62 | cmd="git merge-base --is-ancestor $hash HEAD" | ||
63 | fi | ||
64 | if [ "$OPT_a" ] || $cmd | ||
65 | then | ||
66 | if ! [ "$OPT_q" ] | ||
67 | then | ||
68 | if [ "$OPT_a" ] | ||
69 | then show_all_message | ||
70 | elif [ "$OPT_r" -a "$listed" -eq 0 ] | ||
71 | then show_reverse_message | ||
72 | else show_normal_message | ||
73 | fi | ||
74 | fi | ||
75 | |||
76 | >&2 printf 'remote: %s\n' "$ref" | ||
77 | git show $hash | sed '/^$/q' | ||
78 | listed=$((listed + 1)) | ||
79 | else | ||
80 | skipped=$((skipped + 1)) | ||
81 | fi | ||
82 | } | ||
83 | |||
84 | read_hashes() | ||
85 | { | ||
86 | while read hash ref; do | ||
87 | case $ref in | ||
88 | refs/namespaces/*) handle_hash_ref "$hash" "$ref" ;; | ||
89 | esac | ||
90 | done | ||
91 | } | ||
92 | |||
93 | finalize() | ||
94 | { | ||
95 | if [ "$listed" -eq 0 ] | ||
96 | then | ||
97 | if [ "$OPT_r" ] | ||
98 | then | ||
99 | >&2 printf 'Already up-to-date. (No remotes are ancestors of your HEAD; %d remotes up-to-date.)\n' "$skipped" | ||
100 | else | ||
101 | >&2 printf 'Already up-to-date. (No remotes have pushed onto your HEAD; %d remotes up-to-date.)\n' "$skipped" | ||
102 | fi | ||
103 | fi | ||
104 | } | ||
105 | |||
106 | skipped=0 | ||
107 | listed=0 | ||
108 | git ls-remote $remote | (read_hashes && finalize) | ||
6 | 109 | ||
7 | while read hash ref; do | ||
8 | case $ref in refs/namespaces/*) | ||
9 | git fetch $remote $ref; | ||
10 | git show $hash | sed '/^$/q';; | ||
11 | esac | ||
12 | done | ||