-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.sh
116 lines (101 loc) · 2.42 KB
/
lib.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
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
move_files() {
basefile="$1"
targetfile="$2"
if test -f "${basefile}" || test -d "${basefile}"
then
mv "${basefile}" "${targetfile}"
fi
}
# exchange files
exchange_files() {
basefile="$1"
append_old="$2"
append_new="$3"
move_files "${basefile}" "${basefile}_${append_old}"
move_files "${basefile}_${append_new}" "${basefile}"
}
# move git dependent files
move_git_files() {
gitfile="$1"
append=`echo "${GITTWO_DIRNAME}" | sed -e 's/\.//g'`
exchange_files "${gitfile}" "git1" "${append}"
}
# move back the git dependent files:
move_git_files_back() {
gitfile="$1"
append=`echo "${GITTWO_DIRNAME}" | sed -e 's/\.//g'`
exchange_files "${gitfile}" "${append}" "git1"
}
create_exclude() {
gitcmd="$1"
gitdir="$2"
append="$3"
# exclude git files in git two:
echo "/${GITTWO_DIRNAME}" >${gitdir}/info/exclude
echo "/.git2_is_active" >>${gitdir}/info/exclude
if test -f "${gitdir}/info/exclude-extra"
then
cat "${gitdir}/info/exclude-extra" \
>>${gitdir}/info/exclude
fi
"${gitcmd}" ls-files 2>/dev/null | \
sed -e "s/.gitignore/.gitignore_${append}/g" | \
sed -e "s/.gitattributes/.gitattributes_${append}/g" | \
sed -e 's|^|/|' \
>>${gitdir}/info/exclude
}
git2_setup() {
if test "x${GITTWO_ACTIVE}" = "x0"
then
if test -d "${GITTWO_DIR}"
then
# block for other git2 instances:
touch -- "${GITTWO_BASE}.git2_is_active"
create_exclude git "${GITTWO_DIR}" "git1"
# move git dependent files
move_git_files "${GITTWO_BASE}.gitignore"
move_git_files "${GITTWO_BASE}.gitattributes"
else
GITTWO_ACTIVE=1
fi
fi
}
git2_cleanup() {
if test "x${GITTWO_ACTIVE}" = "x0"
then
GITTWO_ACTIVE=1
# move back the git dependent files:
move_git_files_back "${GITTWO_BASE}.gitignore"
move_git_files_back "${GITTWO_BASE}.gitattributes"
rm -- "${GITTWO_BASE}.git2_is_active"
fi
}
git2_search_base_dir() {
# find gittwo base dir:
GITTWO_BASE=""
ldir=
while test \! -d "${ldir}${GITTWO_DIRNAME}"
do
ldir="${ldir}../"
cd "${ldir}" >/dev/null
GITTWO_BASE="`pwd`"
cd - >/dev/null
if test "x${GITTWO_BASE}" = "x/" && \
test \! -d "/${GITTWO_DIRNAME}"
then
#echo "warning: Not a git repository (or any of
# the parent directories): ${GITTWO_DIRNAME}"
GITTWO_BASE=""
break
else
GITTWO_BASE="${GITTWO_BASE}/"
fi
done
export GITTWO_BASE
export GITTWO_DIRNAME
export GITTWO_DIR="${GITTWO_BASE}${GITTWO_DIRNAME}"
}
if test -z "${GITTWO_DIRNAME}"
then
GITTWO_DIRNAME=.git2
fi