-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-ls
executable file
·127 lines (113 loc) · 2.72 KB
/
git-ls
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
# scan all subdirectories under .
#
# fetch git-utils (git-outgoing & git-incomint)
# from https://github.com/ddollar/git-utils.git
#
#
TMP_ST=/tmp/gitit.st.$$
TMP_FROM=/tmp/gitit.from.$$
TMP_TO=/tmp/gitit.to.$$
FETCH=no
PULL=no
VERBOSE=no
DEBUG=no
CWD=`pwd`
trap "cd $CWD; rm -f $TMP_ST $TMP_FROM $TMP_TO; exit" SIGHUP SIGINT SIGTERM
args=`getopt fpvd $*`
if [ $? != 0 ]; then
echo "usage: get-ls [-fpvd] [dir .. ]"
exit 2
fi
set -- $args
for i; do
case "$i" in
-f)
FETCH=yes
shift;;
-p)
PULL=yes
shift;;
-v)
VERBOSE=yes
shift;;
-d)
DEBUG=yes
shift;;
--)
shift; break;;
esac
done
DIR_LIST="$*"
if [ -z "$DIR_LIST" ]; then
DIR_LIST=`ls`
DIR_LIST=". $DIR_LIST"
fi
for rep in $DIR_LIST
do
cd $CWD
if [ -d $rep -a -d $rep/.git ]
then
if [ "$rep" == "." ]; then
rep=`basename $CWD`
else
cd $rep
fi
if [ $VERBOSE == "yes" ]; then
echo "git-ls: directory $rep"
fi
git status --short -uno > $TMP_ST
CURRENT_BRANCH=$(git branch &>/dev/null; if [ $? -eq 0 ]; then echo "$(git branch | grep '^*' |sed s/\*\ //)"; fi)
if [ "${CURRENT_BRANCH}" != "" ]; then
TARGET="" # fixme pass a special target|branch?
if [ "${TARGET}" == "" ]; then
TRACKING_REPOSITORY="$(git config branch.${CURRENT_BRANCH}.remote)"
# there is a tracking repository
if [ "${TRACKING_REPOSITORY}" != "" ]; then
REMOTE_REPOSITORY="${TRACKING_REPOSITORY}"
REMOTE_BRANCH="$(git config branch.${CURRENT_BRANCH}.merge | sed -e 's#^[^/]*/[^/]*/##')"
TARGET="${REMOTE_REPOSITORY}/${REMOTE_BRANCH}"
else
echo "warning: no remote branch tracking set up"
fi
fi
if [ $FETCH == "yes" ]; then
git remote update -p
fi
git log -n 5 ..${TARGET} | sed -n -e "s/Date: \(.*\)/\1/p" -e "s/Author: \(.*\)/\1/p" | sed -n 'N;s/\n/,/p' > $TMP_FROM
git log -n 5 ${TARGET}.. | sed -n -e "s/Date: \(.*\)/\1/p" -e "s/Author: \(.*\)/\1/p" | sed -n 'N;s/\n/,/p' > $TMP_TO
fi
if [ -s $TMP_ST -o -s $TMP_FROM -o -s $TMP_TO ]; then
status=""
if [ -s $TMP_ST ]; then
if cat $TMP_ST | grep -v "^[ ]." > /dev/null; then
status="COMMIT $status"
fi
if cat $TMP_ST | grep -v "^.[ ]" > /dev/null; then
status="ADD $status"
fi
# cat $TMP_ST
fi
if [ -s $TMP_FROM ]; then
if [ $PULL == "yes" ]; then
# FIXME: this is a bit simplistic, but practical
git pull
status="PULLED $status"
else
status="MERGE $status"
fi
# echo "From: ${TARGET}"
# cat $TMP_FROM
fi
if [ -s $TMP_TO ]; then
status="PUSH $status"
# echo "To: ${TARGET}"
# cat $TMP_TO
fi
echo "$rep: $status"
fi
fi
done
rm -f $TMP_ST
rm -f $TMP_FROM
rm -f $TMP_TO