#!/bin/bash# display current branch of every git repo in curent directoryGIT_REPOS=()MAX_LEN=0for dir in ./*/
dodir=${dir%*/}dir=${dir##*/}if[ -d $dir/.git ];thenGIT_REPOS+=($dir)if[${#dir} -gt $MAX_LEN];thenMAX_LEN=${#dir};fifidonePADDING=$(($MAX_LEN+5))for dir in ${GIT_REPOS[@]}doprintf"%-${PADDING}s %s\n""$dir""$(git -C $dir rev-parse --abbrev-ref HEAD)"done
#!/bin/bash# usage:# by default prints messages since $SINCE of author matching $AUTHOR pattern.# you can override these values from command line:# first argument would be interpret like "$1 days ago"# second one (if specified) - as an author's name patternAUTHOR="kovalenko"SINCE="13 days ago"if["$1" -gt 0];thenSINCE="$1 days ago"fiif[ -n "$2"];thenAUTHOR="$2"fiSHOW_MESSAGE="Showing changes since \"$SINCE\" of author \"$AUTHOR\""printf"\n$SHOW_MESSAGE\n\n"for dir in ./*/
dodir=${dir%*/}dir=${dir##*/}if[ -d $dir/.git ];thenecho$dir; git --no-pager -C $dir hist \ --pretty=format:'%C(auto)%h%C(reset) %C(bold green)%ad%C(reset) | %C(white)%s%C(reset)%C(auto)%d%C(reset) [%C(bold blue)%an%C(reset)]'\ --date=format:'%Y-%m-%d %H:%M'\ --color=always \ --graph \ --decorate \ --since="$SINCE"\ --regexp-ignore-case \ --author="$AUTHOR"\ --grep="$COMMIT_MSG"printf"\n\n\n"fidoneprintf"$SHOW_MESSAGE\n\n"
#!/bin/bash# Perform git pull in all git repositories in current directory.# If some chanes are not commited in a repo - they will be stashed, including untracked and indexed (cached) files.# After pull is done, the script attempts to pop the stash. In case of error it will be printed.# At the end of the script list of failded repos (if any) will be printed# list of repos which were updated with errorsFAILED_REPOS=()ROOT_DIR=$(pwd -P)# console colors, see http://stackoverflow.com/questions/4332478/read-the-current-text-color-in-a-xterm/4332530#4332530NORMAL=$(tput sgr0)RED=$(tput setaf 1)GREEN=$(tput setaf 2)YELLOW=$(tput setaf 3)BLUE=$(tput setaf 4)for dir in ./*/
do# get pure repo directory namedir=${dir%*/}dir=${dir##*/}if[ -d $dir/.git ];thenpushd$dir > /dev/null
printf"\nUpdating repo ${YELLOW}${dir}${NORMAL}\n"# I use "status --porcelain" instead of "diff --exit-code" because the first one tracks everything:# changed, untracked, indexed filesif[ -n "$(git status --porcelain)"];thenecho"Changes detected - stash them"DATE=`date +"%Y-%m-%d %H:%M:%S"`BRANCH=`git rev-parse --abbrev-ref HEAD`STASHED=true git stash save --include-untracked --no-keep-index "Before pull $DATE in branch $BRANCH"elseSTASHED=falsefi git pull
if[$? -ne 0];thenprintf"\n{$RED}Pull error in repo ${YELLOW}$dir${NORMAL}\n"FAILED_REPOS+=($dir);fiif["$STASHED"=true];thenecho"Try to pop stashed changes back" git stash pop --index
if[$? -ne 0];thenprintf"\n${RED}!!! Stash popping failded: apply the stash manually and then drop it !!!${NORMAL}\n"FAILED_REPOS+=($dir)fifiprintf"\n"popd > /dev/null
fidonecd$ROOT_DIR > /dev/null
if[${#FAILED_REPOS[@]} -eq 0];thenprintf"\n${GREEN}All updates done successfully${NORMAL}\n"elseprintf"\n${RED}!!!Some repos updating error:\n"printf'%s\n'"${FAILED_REPOS[@]}"printf"${NORMAL}"fi
#!/bin/bash# display stashes for every git repo in curent directoryfor dir in ./*/
dodir=${dir%*/}dir=${dir##*/}if[ -d $dir/.git ];thenecho$dir; git --no-pager -C $dir stash list
printf"\n"fidone
#!/bin/bash# display status of every git repo in curent directoryfor dir in ./*/
dodir=${dir%*/}dir=${dir##*/}if[ -d $dir/.git ];thenecho$dir; git -C $dir status
printf"\n"fidone
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.