/
.gitcheck
executable file
·48 lines (39 loc) · 1.46 KB
/
.gitcheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
## gitcheck:
## Check all git repositories in subdirectories, and list the ones with changes
## Modified from: https://astrofloyd.wordpress.com/2013/02/10/gitcheck-check-all-your-git-repositories-for-changes/
# Initialise counters:
let count_all=0
let count_changed=0
let count_unchanged=0
# Find git repos and loop over them:
for repo in `find ~ -not \( -path ~/Library -prune \) -type d -name ".git"`
do
let count_all=${count_all}+1
dir="$(dirname "$repo")"
builtin cd "${dir}"
git fetch origin &> /dev/null
# how far ahead of github is local
temp=$(git rev-list HEAD...origin/master --count)
# were there additions to the repo
temp2=$(git status -s | wc -l)
# how far ahead of local is github
temp3=$(git log HEAD..origin/master --oneline | wc -l)
# set blue to display repo location below
blue=$(tput setaf 33)
# if repository is ahead of/behind github (needs push or pull) or has changes, display repo and any files that need to be added
if [ $temp -ne 0 ] || [ $temp2 -ne 0 ] || [ $temp3 -ne 0 ]; then
echo -e "\n\n [${blue} ${dir}"
# git branch -vvra
git status --short --branch
let count_changed=${count_changed}+1
else
let count_unchanged=${count_unchanged}+1
fi
# cd back:
builtin cd - &> /dev/null
done
# Report status and exit:
echo -ne "\n\n${count_all} git repositories found: "
echo -ne "${count_changed} have changes, "
echo -ne "${count_unchanged} are unchanged.\n\n"