@matheusbsbs / matheus-bagliano / commits / 44c36d1ccc
Fork 0

Tidy up git mergetool's backup file behaviour

Currently a backup pre-merge file with conflict markers is sometimes kept with a .orig extenstion and sometimes removed depending on the particular merge tool used. This patch makes the handling consistent across all merge tools and configurable via a new mergetool.keepBackup config variable Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Charles Bailey committed Feb 21, 2008 at 23:30 UTC 44c36d1ccc9a40bfb31910dfd7e18d59fa8be502
2 files changed +19 -24
Documentation/config.txt
+6
@@ -777,6 +777,12 @@ mergetool.<tool>.path::
777 Override the path for the given tool. This is useful in case
778 your tool is not in the PATH.
779
780 +mergetool.keepBackup::
781 + After performing a merge, the original file with conflict markers
782 + can be saved as a file with a `.orig` extension. If this variable
783 + is set to `false` then this file is not preserved. Defaults to
784 + `true` (i.e. keep the backup files).
785 +
786 pack.window::
787 The size of the window used by linkgit:git-pack-objects[1] when no
788 window size is given on the command line. Defaults to 10.
git-mergetool.sh
+13 -24
@@ -127,18 +127,6 @@ check_unchanged () {
127 fi
128 }
129
130 -save_backup () {
131 - if test "$status" -eq 0; then
132 - mv -- "$BACKUP" "$path.orig"
133 - fi
134 -}
135 -
136 -remove_backup () {
137 - if test "$status" -eq 0; then
138 - rm "$BACKUP"
139 - fi
140 -}
141 -
130 merge_file () {
131 path="$1"
132
@@ -201,7 +189,6 @@ merge_file () {
189 -o "$path" -- "$LOCAL" "$REMOTE" > /dev/null 2>&1)
190 fi
191 status=$?
204 - remove_backup
192 ;;
193 tkdiff)
194 if base_present ; then
@@ -210,20 +197,17 @@ merge_file () {
197 "$merge_tool_path" -o "$path" -- "$LOCAL" "$REMOTE"
198 fi
199 status=$?
213 - save_backup
200 ;;
201 meld|vimdiff)
202 touch "$BACKUP"
203 "$merge_tool_path" -- "$LOCAL" "$path" "$REMOTE"
204 check_unchanged
219 - save_backup
205 ;;
206 gvimdiff)
222 - touch "$BACKUP"
223 - "$merge_tool_path" -f -- "$LOCAL" "$path" "$REMOTE"
224 - check_unchanged
225 - save_backup
226 - ;;
207 + touch "$BACKUP"
208 + "$merge_tool_path" -f -- "$LOCAL" "$path" "$REMOTE"
209 + check_unchanged
210 + ;;
211 xxdiff)
212 touch "$BACKUP"
213 if base_present ; then
@@ -240,7 +224,6 @@ merge_file () {
224 --merged-file "$path" -- "$LOCAL" "$REMOTE"
225 fi
226 check_unchanged
243 - save_backup
227 ;;
228 opendiff)
229 touch "$BACKUP"
@@ -250,7 +233,6 @@ merge_file () {
233 "$merge_tool_path" "$LOCAL" "$REMOTE" -merge "$path" | cat
234 fi
235 check_unchanged
253 - save_backup
236 ;;
237 ecmerge)
238 touch "$BACKUP"
@@ -260,7 +242,6 @@ merge_file () {
242 "$merge_tool_path" "$LOCAL" "$REMOTE" --mode=merge2 --to="$path"
243 fi
244 check_unchanged
263 - save_backup
245 ;;
246 emerge)
247 if base_present ; then
@@ -269,7 +250,6 @@ merge_file () {
250 "$merge_tool_path" -f emerge-files-command "$LOCAL" "$REMOTE" "$(basename "$path")"
251 fi
252 status=$?
272 - save_backup
253 ;;
254 esac
255 if test "$status" -ne 0; then
@@ -277,6 +257,13 @@ merge_file () {
257 mv -- "$BACKUP" "$path"
258 exit 1
259 fi
260 +
261 + if test "$merge_keep_backup" = "true"; then
262 + mv -- "$BACKUP" "$path.orig"
263 + else
264 + rm -- "$BACKUP"
265 + fi
266 +
267 git add -- "$path"
268 cleanup_temp_files
269 }
@@ -380,6 +367,8 @@ else
367
368 init_merge_tool_path "$merge_tool"
369
370 + merge_keep_backup="$(git config --bool merge.keepBackup || echo true)"
371 +
372 if ! type "$merge_tool_path" > /dev/null 2>&1; then
373 echo "The merge tool $merge_tool is not available as '$merge_tool_path'"
374 exit 1