summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-02-24 15:52:53 (GMT)
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-02-26 11:49:21 (GMT)
commit087ad206db4ef25eff2c21c3d6e06194f0e217ee (patch)
treea5efde1dda2ad6004d987edbf7f7208173f605f5
parentb758575226de75e210bd9385c748732ca62bb877 (diff)
downloadtbdiff-087ad206db4ef25eff2c21c3d6e06194f0e217ee.tar.gz
Prevent patching when 'vu == v2' in 'baserock-system-config-sync'.
When vu == v2, the script tried to reverse the patch. Now this won't happen again. Also added '-f' flag calling 'patch' to prevent also reverse patching.
-rwxr-xr-xbaserock-system-config-sync/baserock-system-config-sync21
1 files changed, 15 insertions, 6 deletions
diff --git a/baserock-system-config-sync/baserock-system-config-sync b/baserock-system-config-sync/baserock-system-config-sync
index a093b15..e297197 100755
--- a/baserock-system-config-sync/baserock-system-config-sync
+++ b/baserock-system-config-sync/baserock-system-config-sync
@@ -134,6 +134,7 @@ merge_regular_file() {
v1_exists=$(test -f "$v1" && echo exists || echo none)
vu_exists=$(test -f "$vu" && echo exists || echo none)
v2_exists=$(test -f "$v2" && echo exists || echo none)
+
case "$v1_exists $vu_exists $v2_exists" in
'exists none none')
cp -a "$v1" "$vt"
@@ -152,16 +153,24 @@ merge_regular_file() {
;;
'none exists exists')
cp -a "$v2" "$vt"
- if ! (diff -u "$v2" --label="$v2" "$vu" --label="$vu" | patch "$vt" -t); then
- cp -a "$v2" "$vt" # merge failed, use v2
- # 'patch' creates a file '.rej' with the diff that did not apply
+
+ # If v2 == vu, then use v2
+ if ! cmp -s "$v2" "$vu"; then
+ if ! (diff -u "$v2" --label="$v2" "$vu" --label="$vu" | patch "$vt" -f); then
+ cp -a "$v2" "$vt" # merge failed, use v2
+ # 'patch' creates a file '.rej' with the diff that did not apply
+ fi
fi
;;
'exists exists exists')
cp -a "$v2" "$vt"
- if ! (diff -u "$v1" --label="$v1" "$vu" --label="$vu" | patch "$vt" -t); then
- cp -a "$v2" "$vt" # merge failed, use v2
- # 'patch' creates a file '.rej' with the diff that did not apply
+
+ # If v2 == vu, then use v2
+ if ! cmp -s "$v2" "$vu"; then
+ if ! (diff -u "$v1" --label="$v1" "$vu" --label="$vu" | patch "$vt" -f); then
+ cp -a "$v2" "$vt" # merge failed, use v2
+ # 'patch' creates a file '.rej' with the diff that did not apply
+ fi
fi
;;
*)