-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitCheck
executable file
·57 lines (48 loc) · 2.41 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
49
50
51
52
53
54
55
56
57
#!/bin/bash
## -------------------------------------------------------------------
## Git Repo Checker 1.0.0
##
## This is free software: you are free to change and redistribute it.
## There is NO WARRANTY, to the extent permitted by law.
## -------------------------------------------------------------------
### Checks repos for situations that need attention
### Usage: gitCheck [options]
###
### -h, --help Show help options.
### -v, --version Print program version.
help=$(grep "^### " "$0" | cut -c 5-)
version=$(grep "^## " "$0" | cut -c 4-)
eval "$(docopts -A args -h "$help" -V "$version" : "$@")"
. $(dirname $0)/git-sh-prompt
. $(dirname $0)/scriptsConfig
cd $GITDIR
for FILE in `ls`; do
if [[ -d $FILE && -d $FILE/.git ]]; then
cd $FILE
if [[ $(git status 2>/dev/null) != *"working tree clean"* ]]; then
echo -e "\e[36m$FILE\e[m has \e[31muncommitted changes\e[m."
fi
if [[ -n $(git stash list) ]]; then
echo -e "\e[36m$FILE\e[m has \e[31munpopped stashes\e[m."
fi
for REMOTE in `git remote`; do
for BRANCH in `git branch | sed s/"*"//g`; do
if [[ -n $(git log $REMOTE/$BRANCH..$BRANCH) ]]; then
if [[ $(git ls-remote $REMOTE >/dev/null 2>&1; echo $?) = 0 ]]; then #Basically, if we can query the remote then...
if [[ $(git remote show $REMOTE | grep "Push URL:") != *"git://"* ]]; then #Check remote info after querying
echo -e "\e[36m$FILE\e[m needs \e[31m$BRANCH\e[m to be pushed to \e[31m$REMOTE\e[m." #And do stuff based on that
fi
else #And if we can't....
if [[ $(git remote show -n $REMOTE | grep "Push URL:") != *"git://"* ]]; then #Check the cached remote info
echo -e "\e[36m$FILE\e[m needs \e[31m$BRANCH\e[m to be pushed to \e[31m$REMOTE\e[m." #And do stuff based on that instead
fi
fi
fi
if [[ -n $(git log $BRANCH..$REMOTE/$BRANCH) ]]; then
echo -e "\e[36m$FILE\e[m needs \e[31m$BRANCH\e[m to be merged from \e[31m$REMOTE\e[m."
fi
done
done
cd ..
fi
done