-
Notifications
You must be signed in to change notification settings - Fork 10
/
eneboo-git-mergetool
executable file
·198 lines (165 loc) · 6.23 KB
/
eneboo-git-mergetool
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
if [ "$1" == "install" ]; then
git config --global mergetool.eneboo.cmd "eneboo-git-mergetool \$BASE \$LOCAL \$REMOTE \$MERGED" || exit 1;
git config --global mergetool.eneboo.trustExitCode true || exit 1;
echo "Se ha instalado correctamente el mergetool 'eneboo'"
exit 0;
fi
if [ "$1" == "replay-kdiff3" ]; then
shift
LOCAL_BRANCH="HEAD^1"
REMOTE_BRANCH="HEAD^2"
BASE_BRANCH=$(git merge-base $LOCAL_BRANCH $REMOTE_BRANCH)
for file in $*; do
EXT=${file#*.}
echo $file
file="$(git rev-parse --show-prefix)$file"
cd "$(git rev-parse --show-cdup)"
git show "$BASE_BRANCH:$file" > "$file.BASE.$EXT"
git show "$LOCAL_BRANCH:$file" > "$file.LOCAL.$EXT"
git show "$REMOTE_BRANCH:$file" > "$file.REMOTE.$EXT"
kdiff3 "$file.BASE.$EXT" "$file.LOCAL.$EXT" "$file.REMOTE.$EXT" -o "$file"
echo
done
exit 0;
fi
if [ "$1" == "manual" -o "$1" == "replay" ]; then
if [ "$1" == "replay" ]; then
LOCAL_BRANCH="HEAD^1"
REMOTE_BRANCH="HEAD^2"
else
shift
LOCAL_BRANCH=$1
shift
REMOTE_BRANCH=$1
fi
shift
BASE_BRANCH=$(git merge-base $LOCAL_BRANCH $REMOTE_BRANCH)
for file in $*; do
EXT=${file#*.}
echo $file
file="$(git rev-parse --show-prefix)$file"
(
cd "$(git rev-parse --show-cdup)"
git show "$BASE_BRANCH:$file" > "$file.BASE.$EXT"
git show "$LOCAL_BRANCH:$file" > "$file.LOCAL.$EXT"
git show "$REMOTE_BRANCH:$file" > "$file.REMOTE.$EXT"
if [ "$1" == "replay" ]; then
$0 "$file.BASE.$EXT" "$file.LOCAL.$EXT" "$file.REMOTE.$EXT" "$file" && {
test -s "$file" && {
mv "$file" "$file.test1"
$0 "$file.BASE.$EXT" "$file.REMOTE.$EXT" "$file.LOCAL.$EXT" "$file"
mv "$file" "$file.test2"
kdiff3 "$file.test1" "$file.test2"
#kdiff3 "$file.LOCAL.$EXT" "$file" "$file.REMOTE.$EXT" >/dev/null 2>&1 &
#kdiff3 "$file.BASE.$EXT" "$file.LOCAL.$EXT" "$file.REMOTE.$EXT" >/dev/null 2>&1 &
}
}
else # replay-kdiff3
kdiff3 "$file.BASE.$EXT" "$file.LOCAL.$EXT" "$file.REMOTE.$EXT" -o "$file"
fi
)
echo
done
exit 0;
else
BASE=$1
LOCAL=$2
REMOTE=$3
MERGED=$4
fi
EXT=${MERGED##*.}
MODE="error"
if [ "$EXT" = "qs" ]; then
MODE="qsdir"
MODE="qs-split"
fi
if [ "$EXT" = "ui" ]; then
MODE="xml"
fi
if [ "$EXT" = "mtd" ]; then
MODE="xml"
fi
if [ "$EXT" = "xml" ]; then
MODE="xml"
fi
if [ "$EXT" = "ts" ]; then
MODE="xml"
fi
if [ "$EXT" = "kut" ]; then
MODE="xml"
fi
if [ ! -e $BASE ]; then
exec kdiff3 $LOCAL $REMOTE -o $MERGED --auto
fi
if [ "$EXT" = "qry" ]; then
MODE="kdiff3"
fi
if [ "$EXT" = "sql" ]; then
MODE="kdiff3"
fi
if [ "$MODE" = "error" ]; then
echo "Se desconoce como mezclar la extension '.$EXT'"
exit 3;
fi
test -e $BASE || { echo "fichero BASE '$BASE' no existe"; exit 2; };
test -e $LOCAL || { echo "fichero LOCAL '$LOCAL' no existe"; exit 2; };
test -e $REMOTE || { echo "fichero REMOTE '$REMOTE' no existe"; exit 2; };
if [ "$MODE" = "kdiff3" ]; then
exec kdiff3 $BASE $LOCAL $REMOTE -o $MERGED --auto
exit 3;
fi
if [ "$MODE" = "xml" -o "$MODE" = "qsdir" ]; then
filename=$(basename "$MERGED")
extension="${filename##*.}"
eneboo-mergetool file-diff $MODE $BASE $REMOTE \
--output $MERGED.patch_br || echo "Error al generar el parche BR"
eneboo-mergetool file-diff $MODE $BASE $LOCAL \
--output $MERGED.patch_bl || echo "Error al generar el parche BL"
if [ $(wc -c < $MERGED.patch_br) -ge $(wc -c < $MERGED.patch_bl) ]; then
PMODE="blr" # (Base - Local) + Remote
eneboo-mergetool file-diff $MODE $LOCAL $BASE --output $MERGED.patch_bl_uninst -q --clean-patch \
|| echo "Error al generar desintalación base-local"
eneboo-mergetool file-patch $MODE $MERGED.patch_bl_uninst $REMOTE --output $MERGED.uninst.$extension -q \
|| echo "Error al aplicar desintalación base-local"
test -s $MERGED.uninst.$extension || cp $REMOTE $MERGED.uninst.$extension
eneboo-mergetool file-patch $MODE $MERGED.patch_bl $MERGED.uninst.$extension --output $MERGED -v \
|| echo "Error al aplicar parche $PMODE"
else
PMODE="brl" # (Base - Remote) + Local
eneboo-mergetool file-diff $MODE $REMOTE $BASE --output $MERGED.patch_br_uninst -q --clean-patch \
|| echo "Error al generar desintalación base-remote"
eneboo-mergetool file-patch $MODE $MERGED.patch_br_uninst $LOCAL --output $MERGED.uninst.$extension -q \
|| echo "Error al aplicar desintalación base-remote"
test -s $MERGED.uninst.$extension || cp $LOCAL $MERGED.uninst.$extension
eneboo-mergetool file-patch $MODE $MERGED.patch_br $MERGED.uninst.$extension --output $MERGED -v \
|| echo "Error al aplicar parche $PMODE"
fi
#exit 8
test -f $MERGED.patch_br_uninst && unlink $MERGED.patch_br_uninst
test -f $MERGED.patch_bl_uninst && unlink $MERGED.patch_bl_uninst
unlink $MERGED.patch_br
unlink $MERGED.patch_bl
unlink $MERGED.uninst.$extension
test -s $MERGED || exit 5
exit 0
fi
if [ "$MODE" = "qs-split" ]; then
eneboo-mergetool qs-split $BASE -v
eneboo-mergetool qs-split $REMOTE -v
eneboo-mergetool qs-split $LOCAL -v
test -d "${MERGED%.qs}-splitted" && rm -Rf "${MERGED%.qs}-splitted"
mkdir "${MERGED%.qs}-splitted"
kdiff3 "${BASE%.qs}-splitted" "${LOCAL%.qs}-splitted" "${REMOTE%.qs}-splitted" -o "${MERGED%.qs}-splitted" -m
eneboo-mergetool qs-join "${MERGED%.qs}-splitted" -v
if test -s "${MERGED%.qs}.joined.qs" ; then
cp "${MERGED%.qs}.joined.qs" "$MERGED"
rm "${MERGED%.qs}.joined.qs" "${BASE%.qs}-splitted" "${LOCAL%.qs}-splitted" "${REMOTE%.qs}-splitted" "${MERGED%.qs}-splitted" -Rf
exit 0;
else
rm "${MERGED%.qs}.joined.qs" "${BASE%.qs}-splitted" "${LOCAL%.qs}-splitted" "${REMOTE%.qs}-splitted" "${MERGED%.qs}-splitted" -Rf
exit 5;
fi
fi
echo "Se desconoce el modo de mezla '$MODE'"
exit 3;