-
Notifications
You must be signed in to change notification settings - Fork 26
/
git-cms-sparse-checkout
executable file
·105 lines (100 loc) · 3.03 KB
/
git-cms-sparse-checkout
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
#!/bin/sh -e
# Includes in .git/info/sparse-checkout a list of the packages
# which are modified between TAG1 and TAG2
case `uname` in
Darwin) ECHO=echo ;;
*) ECHO="echo -e" ;;
esac
usage () {
echo "git cms-sparse-checkout [options] TAG1 TAG2"
echo
echo "Options:"
$ECHO "-h \tthis help message"
$ECHO
$ECHO "-d, --debug \tenable debug output"
exit $1
}
DEBUG=0
REF1=
REF2=
while [ "$#" != 0 ]; do
case "$1" in
-h | --help )
usage 0;;
-d|--debug)
DEBUG=1
shift
;;
--exclude-cvs-keywords)
REGEX='^([^$]+$|[^$]*[$][^$]*$|([^$]*[$])($|[^RAIDLNSH]|(R[^eC]|A[^u]|I[^d]|D[^a]|L[^o]|N[^a]|S[^o]|H[^e])|(Re[^v]|RC[^S]|Au[^t]|Id[^:]|Da[^t]|Lo[^g]|Na[^m]|So[^u]|He[^a])|(Rev[^i]|RCS[^f]|Aut[^h]|Dat[^e]|Log[^:]|Nam[^e]|Sou[^r]|Hea[^d])|(Revi[^s]|RCSf[^i]|Auth[^o]|Date[^:]|Name[^:]|Sour[^c]|Head[^e])|(Revis[^i]|RCSfi[^l]|Autho[^r]|Sourc[^e]|Heade[^r])|(Revisi[^o]|RCSfil[^e]|Author[^:]|Source[^:]|Header[^:])|(Revisio[^n]|RCSfile[^:])|(Revision[^:])))'
REGEX_OPT="-G"
shift
;;
-G)
REGEX_OPT="-G"
REGEX="$2"; shift ; shift
;;
-*)
echo Unknown option $1 ; usage 1 ;;
*)
if [ "$REF1" == "" ]; then
REF1="$1"
elif [ "$REF2" = "" ]; then
REF2="$1"
else
echo "Too many tags / branches specified." ; exit 1
fi
shift 1
;;
esac
done
BASH_FULL_VERSION=$((${BASH_VERSINFO[0]} * 10000 + ${BASH_VERSINFO[1]} * 100 + ${BASH_VERSINFO[2]}))
if (( BASH_FULL_VERSION >= 40100 )); then
# bash 4.1 or newer
if [ $DEBUG == 0 ]; then
# send debug messages to /dev/null
exec {debug}> /dev/null
else
# send debug messages to stderr
exec {debug}>&2
# pass the debug option to subcommands
DEBUG_OPT=-d
# enable shell tracing
set -x
fi
else
# bash 4.0 or older
debug=12
if [ $DEBUG == 0 ]; then
# send debug messages to /dev/null
exec 12> /dev/null
else
# send debug messages to stderr
exec 12>&2
# pass the debug option to subcommands
DEBUG_OPT=-d
# enable shell tracing
set -x
fi
fi
case `git --version` in
git\ version\ 1.7*)
# git 1.7.x does not support a leading slash in .gitignore and .git/info/sparse-checkout
LEADING_SLASH=
;;
*)
LEADING_SLASH=/
;;
esac
git config core.sparsecheckout true
INFO_DIR=`git rev-parse --show-toplevel`/.git/info/
touch $INFO_DIR/sparse-checkout
cp -f $INFO_DIR/sparse-checkout $INFO_DIR/sparse-checkout-new
for x in `git diff $REGEX_OPT $REGEX $REF1..$REF2 --name-only --no-renames | grep -v ".gitconfig" | cut -f1,2 -d/ | sort -u`; do
echo "$x" | sed -e "s|[/]*$|/|;s|^/*|${LEADING_SLASH}|" >> $INFO_DIR/sparse-checkout-new
done
for x in `git diff $REF1..$REF2 | grep '^old mode' -C 1 | grep '^diff --git' | sed -e 's|.* ||;s|b/||' | grep -v ".gitconfig" | cut -f1,2 -d/ | sort -u`; do
echo "$x" | sed -e "s|[/][/]*$|/|;s|^/*|${LEADING_SLASH}|" >> $INFO_DIR/sparse-checkout-new
done
cat $INFO_DIR/sparse-checkout-new | sort -u > $INFO_DIR/sparse-checkout
rm -f $INFO_DIR/sparse-checkout-new