-
Notifications
You must be signed in to change notification settings - Fork 7
/
flmergetool
executable file
·199 lines (172 loc) · 4.46 KB
/
flmergetool
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
# FLMERGETOOL.
# To add this tool to git, do the following:
# flmergetool INSTALL
editors=(medit kate gedit kwrite nano vim vi)
EDITOR_FILEPATH=
for editor in "${editors[@]}"; do
EDITOR_FILEPATH=$(command -v $editor)
[[ $EDITOR_FILEPATH ]] && break
done
echo $EDITOR_FILEPATH
thisprg=`realpath $0`
thisdir=`dirname $thisprg`
if test "$1" = "INSTALL"
then
sudo ln -s $thisprg /usr/local/bin/flmergetool
git config --global mergetool.flmergetool.cmd \
"flmergetool \$MERGED \$BASE \$LOCAL \$REMOTE"
git config --global mergetool.flmergetool.trustExitCode true
exit 0
fi
if [[ $1 == "--debug" ]]; then
DEBUG="--debug"
shift
else
DEBUG=""
fi
MERGE=$1
BASE=$2
LOCAL=$4
REMOTE=$3
if test -f $LOCAL
then
OK=1
else
echo "File $LOCAL does not exist."
exit 1
fi
if test -f $REMOTE
then
OK=1
else
echo "File $REMOTE does not exist."
exit 1
fi
if test -f $BASE
then
OK=1
else
if kdiff3 $LOCAL $REMOTE -o $MERGE >/dev/null 2>&1
then
#echo "KDIFF3 OK"
OK=1
exit 0
else
echo "KDIFF3 FAILED"
exit 1
fi
fi
merge_other() {
kdiff3 "$BASE" "$LOCAL" "$REMOTE" -o "$MERGE" --auto >/dev/null 2>&1
return $?
}
merge_xml() {
python $thisdir/xml2json.py convert "$BASE" "$LOCAL" "$REMOTE" && \
kdiff3 "$BASE.json" "$LOCAL.json" "$REMOTE.json" -o "$MERGE.json" --auto >/dev/null 2>&1 && \
python $thisdir/xml2json.py revert "$MERGE.json" && \
cp $MERGE.json.* $MERGE
for f in "$BASE" "$LOCAL" "$REMOTE" "$MERGE"; do
rm "$f".json "$f".json.*
done
return $?
}
merge_qs() {
if echo $MERGE | grep -E '\.qs'
then
OK=1
else
echo "File $MERGE does not have .qs"
exit 1
fi
(
for file1 in "$BASE" "$LOCAL" "$REMOTE"; do
is_done=1
until [[ $is_done == 0 ]]
do
if python $thisdir/flscriptparse.py -O file "$file1" && test -f "$file1.xml"
then
#echo "FLScriptParse OK"
is_done=0
else
patched=0
for kpatch in /tmp/knownpatch.*; do
[[ $kpatch == "/tmp/knownpatch.*" ]] && break
patch "$file1" "$kpatch" -f -F4 -l && {
patched=1
}
done
read -p "Fallo en el parseo del fichero, desea abrir un editor para corregirlo manualmente? [Y/n]:" editor
[[ $editor == "n" ]] && {
echo "FLScriptParse FAILED"
exit 1
}
bname=$(basename "$file1")
cp $file1 /tmp/$bname.orig
"$EDITOR_FILEPATH" "$file1"
read -p "Pulse Intro si ha terminado."
diff -U6 -p --minimal -d /tmp/$bname.orig $file1 >/tmp/knownpatch.$bname.patch.tmp
if [[ $? == 1 ]] && [[ $(wc -l /tmp/knownpatch.$bname.patch.tmp) > 0 ]] ; then
mv /tmp/knownpatch.$bname.patch.tmp /tmp/knownpatch.$bname.patch
else
unlink /tmp/knownpatch.$bname.patch.tmp
fi
fi
done
done
if python $thisdir/flpremerge.py $DEBUG $BASE $LOCAL $REMOTE
then
#echo "FLPreMerge OK"
OK=1
else
echo "FLPreMerge FAILED"
exit 1
fi
if python $thisdir/flalign.py $DEBUG $BASE $LOCAL $REMOTE
then
#echo "FLAlign OK"
OK=1
else
echo "FLAlign FAILED"
exit 1
fi
if test -f $BASE.aligned && test -f $LOCAL.aligned && test -f $REMOTE.aligned
then
OK=1
else
echo "FLAlign FAILED"
exit 1
fi
unlink $MERGE
#echo "kdiff3 $BASE.aligned $LOCAL.aligned $REMOTE.aligned -o $MERGE --auto"
if kdiff3 --auto $BASE.aligned $LOCAL.aligned $REMOTE.aligned -o $MERGE >/dev/null 2>&1
then
#echo "KDIFF3 OK"
OK=1
else
echo "KDIFF3 FAILED"
exit 1
fi
)
for file1 in "$BASE" "$LOCAL" "$REMOTE"; do
unlink "$file1.xml"
unlink "$file1.blocks"
unlink "$file1.aligned"
unlink "$file1.hash"
done
return $?;
}
if echo $MERGE | grep -E '\.qs' ; then
merge_qs
exit $?
fi
if echo $MERGE | grep -E '\.(xml|mtd|ui)' ; then
merge_xml
exit $?
fi
if echo $MERGE | grep -E '\.(kut|qry)' ; then
merge_other
exit $?
fi
print "Unknown extension."
exit 3