Skip to content

Commit

Permalink
git-all: round off some sharp corners
Browse files Browse the repository at this point in the history
* Ensure that error output is treated as error output and sent to stdout
* Create die function for fatal errors
* Use for loop instead of subshell in stat_repos as in do_all_action
* Option parser now accepts multiple arguments on a single dash
* Fix flawed logic in main execution loop
  • Loading branch information
falconindy committed Jun 3, 2010
1 parent 5dc19c3 commit 7ddf511
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions git-all
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ usage() {
exit 1
}

die() {
local mesg=$1; shift
printf "\033[1;31m::\033[0m ${mesg}\n" "$@" >&2
}

msg() {
local mesg=$1; shift
printf " \033[1;32m==>\033[1;0m\033[1;1m ${mesg}\033[1;0m\n" "$@" >&2
Expand All @@ -42,21 +47,21 @@ repopass() {
}

repofail() {
printf "\033[1;0m\033[0;34m[\033[1;31mFAIL\033[0;34m] \033[0;36m %s\033[0m\n" "$1"
printf "\033[1;0m\033[0;34m[\033[1;31mFAIL\033[0;34m] \033[0;36m %s\033[0m\n" "$1" >&2
}

verify_execute() {
msg "Command to be executed: $*"
echo -ne "\033[1;33m::\033[0m"
read -N1 -p " Are you sure you want to do this? [y/N] " reply
echo;echo;
echo

[[ ! "$reply" =~ [Yy] ]] && exit 1
[[ ! "$reply" =~ [Yy] ]] && die "Operation aborted" && exit 1
}

validate_command() {
type -P $1 &> /dev/null || {
echo "Invalid command: '$1'";
die "Invalid command: '$1'";
exit 1;
}
}
Expand All @@ -77,16 +82,19 @@ do_all_action() {
}

stat_repos() {
while read repo; do
IFS=$'\n' read -r -d $'\0' -a repos < <(find "$REPOHOME" -type d -name '.git')

for repo in "${repos[@]}"; do
repo="${repo%/.git}"
cd "$repo"
[[ -n $(git status -s | grep -v "^??") ]] && echo "$repo"
done < <(find "$REPOHOME" -type d -name '.git')
done

exit
}

job_summary() {
echo
msg "Job Summary For $count Repos: $*"

if [[ ${#fail[@]} -eq 0 ]]; then
Expand All @@ -109,16 +117,16 @@ job_summary() {

while (( $# != 0 )); do
case $1 in
-S|--stat)
-*S|--stat)
stat_repos
;;
-h|--help)
-*h|--help)
usage
;;
-f|--force)
-*f|--force)
FORCE=1
;;
-v|--verbose)
-*v|--verbose)
VERBOSE=1
;;
(-*) usage
Expand All @@ -129,9 +137,12 @@ while (( $# != 0 )); do
shift
done

# shifted off all our args, no cmd given
[[ -z $1 ]] && usage

[[ $# -ne 0 ]] && ! (( FORCE )) && verify_execute "$*" && validate_command "$1"
# meat
(( FORCE )) || verify_execute "$*"
validate_command "$1"
do_all_action "$@"
job_summary "$@"

0 comments on commit 7ddf511

Please sign in to comment.