diff options
Diffstat (limited to 'dot/local/bin/git-ll-remote')
-rwxr-xr-x | dot/local/bin/git-ll-remote | 111 |
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 | ||
28 | show_all_message() | 28 | show_all_message() |
29 | { | 29 | { |
30 | >&2 printf '%s\n' \ | 30 | cat >&2 <<EOF |
31 | 'Showing all remote branches:' \ | 31 | Showing all remote branches: |
32 | '' | ||
33 | 32 | ||
33 | EOF | ||
34 | } | 34 | } |
35 | 35 | ||
36 | show_normal_message() | 36 | show_all_none_message() |
37 | { | 37 | { |
38 | >&2 printf '%s\n' \ | 38 | cat >&2 <<EOF |
39 | 'Showing remote branches that have pushed onto your HEAD:' \ | 39 | No remote branches. |
40 | '' | 40 | EOF |
41 | } | 41 | } |
42 | 42 | ||
43 | show_reverse_message() | 43 | show_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)' \ | 46 | Showing remote branches that are ahead (they have pushed onto your HEAD): |
47 | 'because "-r" (reverse) was specified:' \ | 47 | |
48 | '' | 48 | EOF |
49 | } | ||
50 | |||
51 | show_ahead_none_message() | ||
52 | { | ||
53 | x=$(cat <<EOF) | ||
54 | No remote branches are ahead of your HEAD. %d remote branches were not listed. | ||
55 | EOF | ||
56 | printf "$x\n" "$1" >&2 | ||
57 | |||
58 | } | ||
59 | |||
60 | show_behind_message() | ||
61 | { | ||
62 | cat >&2 <<EOF | ||
63 | Showing remote branches that are behind (your HEAD has commits on top of | ||
64 | the remote branch): | ||
65 | |||
66 | EOF | ||
67 | } | ||
68 | |||
69 | show_behind_none_message() | ||
70 | { | ||
71 | x=$(cat <<EOF) | ||
72 | No remotes branches are behind your HEAD. %d other remote branches were not | ||
73 | listed. | ||
74 | EOF | ||
75 | printf "$x\n" "$1" >&2 | ||
76 | |||
77 | } | ||
78 | |||
79 | show_upto_message() | ||
80 | { | ||
81 | cat >&2 <<EOF | ||
82 | Showing remote branches that are even with your HEAD. | ||
83 | |||
84 | EOF | ||
85 | } | ||
86 | |||
87 | show_upto_none_message() | ||
88 | { | ||
89 | x=$(cat <<EOF) | ||
90 | No remote branches are even with your HEAD. %d other remote branches were not | ||
91 | listed. | ||
92 | EOF | ||
93 | printf "$x\n" "$1" >&2 | ||
49 | } | 94 | } |
50 | 95 | ||
96 | SHOW=ahead | ||
97 | [ "$OPT_a" ] && SHOW=all | ||
98 | [ "$OPT_r" ] && SHOW=behind | ||
99 | [ "$OPT_u" ] && SHOW=upto | ||
100 | |||
51 | show_message() | 101 | show_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 | ||
61 | git_fetch() | 106 | git_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 | ||
112 | is_same_ref() | ||
113 | { | ||
114 | [ "$1" = "$2 " ] || [ "$(git rev-parse "$1")" = "$(git rev-parse "$2")" ] | ||
115 | } | ||
116 | |||
67 | is_ancestor() | 117 | is_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 | ||
125 | show_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 | |||
77 | handle_hash_ref() | 136 | handle_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 | ||