Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 120 lines (96 sloc) 2.503 kB
5216b5d @falconindy rewrite. Less sed, more find regex, more -s flags on git status
authored
1 #!/bin/bash
d667d81 @falconindy git-all: minor adjustments
authored
2 # Usage: git-all [-Sfhv] [command...]"
3 #
4 # -S Show repos which have uncommitted changes. If this"
5 # option is specified, all other options are ignored."
6 #
7 # -v print error output in job summary for failed jobs"
8 #
9 # Actions will be performed on $REPOHOME, which defaults to $HOME"
10 # if not specified."
11 #
255867a Initial commit
Dave Reisner authored
12
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
13 REPOHOME=${REPOHOME:-$HOME}
14 VERBOSE=0
d456230 @falconindy git-all: capture output of commands in associative array for later re…
authored
15
b597754 @falconindy git-all: major overhaul. i like where this is going. still needs work.
authored
16 count=0
17 declare -a fail
18 declare -a pass
d456230 @falconindy git-all: capture output of commands in associative array for later re…
authored
19 declare -A output
325d15f @falconindy git-all: Expand functionality to allow for arbitrary command executio…
authored
20
7ddf511 @falconindy git-all: round off some sharp corners
authored
21 die() {
22 local mesg=$1; shift
23 printf "\033[1;31m::\033[0m ${mesg}\n" "$@" >&2
24 }
25
325d15f @falconindy git-all: Expand functionality to allow for arbitrary command executio…
authored
26 msg() {
27 local mesg=$1; shift
d456230 @falconindy git-all: capture output of commands in associative array for later re…
authored
28 printf " \033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
325d15f @falconindy git-all: Expand functionality to allow for arbitrary command executio…
authored
29 }
30
b597754 @falconindy git-all: major overhaul. i like where this is going. still needs work.
authored
31 msg2() {
32 local mesg=$1; shift
d456230 @falconindy git-all: capture output of commands in associative array for later re…
authored
33 printf " \033[1;34m ->\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
b597754 @falconindy git-all: major overhaul. i like where this is going. still needs work.
authored
34 }
35
36 repopass() {
7d45b01 @falconindy git-all: muck with spacing on job summary
authored
37 printf " \033[1;0m\033[0;34m[\033[1;37mPASS\033[0;34m] \033[0;36m %s\033[0m\n" "$1"
b597754 @falconindy git-all: major overhaul. i like where this is going. still needs work.
authored
38 }
39
40 repofail() {
7d45b01 @falconindy git-all: muck with spacing on job summary
authored
41 printf " \033[1;0m\033[0;34m[\033[1;31mFAIL\033[0;34m] \033[0;36m %s\033[0m\n" "$1" >&2
b597754 @falconindy git-all: major overhaul. i like where this is going. still needs work.
authored
42 }
43
af97483 @falconindy git-all: use a bash implementation of readlink
authored
44 breadlink() {
45 local path="$1";
46
47 if [[ -d $path ]]; then
48 (
49 cd "$path"
50 pwd -P
51 )
52 else
a4726de @falconindy s/echo/printf/ -- and some extra juju to go with
authored
53 printf "%s\n" "$path"
af97483 @falconindy git-all: use a bash implementation of readlink
authored
54 fi
55 }
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
56 do_all_action() {
af97483 @falconindy git-all: use a bash implementation of readlink
authored
57 IFS=$'\n' read -r -d $'\0' -a repos < <(find "$REPOHOME" -type d -name '.git' 2>/dev/null)
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
58
d456230 @falconindy git-all: capture output of commands in associative array for later re…
authored
59 for repo in "${repos[@]}"; do
00a955b @falconindy git-all: call readlink on each path found in find
authored
60 (( ++count ))
af97483 @falconindy git-all: use a bash implementation of readlink
authored
61 local repo=$(breadlink ${repo%.git})
d456230 @falconindy git-all: capture output of commands in associative array for later re…
authored
62
cafb490 @falconindy git-all: simplify script. assume you're using a git command
authored
63 cd "$repo"
64 output[$repo]=$(git "$@" 2>&1) && pass=(${pass[@]} "$repo") || fail=(${fail[@]} "$repo")
d456230 @falconindy git-all: capture output of commands in associative array for later re…
authored
65 done
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
66 }
67
68 stat_repos() {
af97483 @falconindy git-all: use a bash implementation of readlink
authored
69 IFS=$'\n' read -r -d $'\0' -a repos < <(find "$REPOHOME" -type d -name '.git' 2>/dev/null)
7ddf511 @falconindy git-all: round off some sharp corners
authored
70
71 for repo in "${repos[@]}"; do
af97483 @falconindy git-all: use a bash implementation of readlink
authored
72 local repo=$(breadlink ${repo%.git})
73
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
74 cd "$repo"
a4726de @falconindy s/echo/printf/ -- and some extra juju to go with
authored
75 [[ -n $(git status -s | grep -v "^??") ]] && printf "%s\n" "$repo"
7ddf511 @falconindy git-all: round off some sharp corners
authored
76 done
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
77 }
78
79 job_summary() {
a4726de @falconindy s/echo/printf/ -- and some extra juju to go with
authored
80 printf "\n"
cafb490 @falconindy git-all: simplify script. assume you're using a git command
authored
81 msg "Job Summary For $count Repos: git $*"
b597754 @falconindy git-all: major overhaul. i like where this is going. still needs work.
authored
82
83 if [[ ${#fail[@]} -eq 0 ]]; then
84 msg2 "No errors were reported"
85 else
86 for repo in "${fail[@]}"; do
87 repofail "$repo"
a4726de @falconindy s/echo/printf/ -- and some extra juju to go with
authored
88 (( VERBOSE )) && { sed 's/^/ /' <<< "${output[$repo]}"; printf "\n"; } >&2
b597754 @falconindy git-all: major overhaul. i like where this is going. still needs work.
authored
89 done
90 fi
a4726de @falconindy s/echo/printf/ -- and some extra juju to go with
authored
91 printf "\n"
b597754 @falconindy git-all: major overhaul. i like where this is going. still needs work.
authored
92
93 for repo in "${pass[@]}"; do
94 repopass "$repo"
95 done
a4726de @falconindy s/echo/printf/ -- and some extra juju to go with
authored
96 printf "\n"
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
97 }
98
d667d81 @falconindy git-all: minor adjustments
authored
99 # sanity check
100 [[ ! -r "$REPOHOME" ]] && die "Invalid \$REPOHOME: $REPOHOME" exit 1
ca7a06f @falconindy git-all: check for the existance of $REPOHOME and cry appropriately i…
authored
101
cafb490 @falconindy git-all: simplify script. assume you're using a git command
authored
102 #while getopts :Sfv flag; do
103 while getopts :Sv flag; do
2ba3129 @falconindy git-all: man up. use getopts. ditch the longopts.
authored
104 case $flag in
cafb490 @falconindy git-all: simplify script. assume you're using a git command
authored
105 S) stat_repos; exit 0 ;;
106 v) VERBOSE=1 ;;
107 \?) die "invalid option -- '$OPTARG'" ;;
d6fc8d3 @falconindy git-all: ensure that getopts and usage output both go to stderr. redi…
authored
108 esac >&2
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
109 done
ae42a15 @falconindy git-all: call shift with OPTIND-1 rather than shifting OPTIND-1 times
authored
110
111 shift $(( OPTIND-1 ))
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
112
d667d81 @falconindy git-all: minor adjustments
authored
113 # check command line usage
cafb490 @falconindy git-all: simplify script. assume you're using a git command
authored
114 [[ $1 ]] || { sed -n '2,/^$/s/^# \?//p' "$0"; exit 1; }
d456230 @falconindy git-all: capture output of commands in associative array for later re…
authored
115
d667d81 @falconindy git-all: minor adjustments
authored
116 # main loop
dc04de5 @falconindy git-all: split off into separate functions and implement an argument …
authored
117 do_all_action "$@"
118 job_summary "$@"
119
Something went wrong with that request. Please try again.