-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit_remote_update.sh
executable file
·54 lines (47 loc) · 1.03 KB
/
git_remote_update.sh
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
#!/bin/bash
IGNORED_FILES="$HOME/Developer/Bash/.git_check_ignore"
ifs_newline() {
IFS=$'\n'
}
ifs_old() {
IFS=$OLD_IFS
}
DIR=$(pwd)
OLD_IFS=$IFS
ifs_newline
for d in `find ~ -regex ".*/\.git" 2>/dev/null`; do
cd "$d/.."
CURR_DIR=$(pwd)
if grep -Fxq "$CURR_DIR" $IGNORED_FILES ; then
continue
fi
echo "Checking ${CURR_DIR}"
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @ @{u})
STATUS=$(git status --porcelain | cut -c1-2 | uniq)
if [ $LOCAL = $REMOTE ] ; then
if [ -z "${STATUS}" ] ; then
echo "${CURR_DIR}: everything up to date"
else
STATUS_STRING=""
if [[ $STATUS == *"M"* ]] ; then
STATUS_STRING="${STATUS_STRING}modified "
fi
if [[ $STATUS == *"??"* ]] ; then
STATUS_STRING="${STATUS_STRING}untracked "
fi
echo "${CURR_DIR}: ${STATUS_STRING}"
fi
else
if [ $LOCAL = $BASE ] ; then
echo "${CURR_DIR}: need to pull"
elif [ $REMOTE = $BASE ] ; then
echo "${CURR_DIR}: need to push"
else
echo "${CURR_DIR}: diverged"
fi
fi
done
ifs_old
cd $DIR