#!/bin/bash # General tool for semi-auto 3way merging: # We have 3 dirs/files in this show : # - curr - the current version of sth. - e.g. a hacked version of Drupal core # - orig - some original that we compare curr to - e.g. drupal core with the same version # - new - and we want the diffs between curr and orig to be migrated to new # but we want full knowledge of what is happening - so we decide at each step what to do. # cause we like to sleep well at night afterwards :) curr=$1 orig=$2 new=$3 rules=$4 # read auto resolve rules specific for sth from $4 # auto rules for drupal #################### if proj=core auto-resolve the sites diff, as well as the backup and cache dirs # remove /sites dir from both dirs #drush dl drupal-$latest_drv || echo "ERR 33"; exit #drush dl drupal-$site_drv || echo "Error 34"; exit #__dru_rm_from_both_core_dirs sites && echo "OK: removed sites from untouched core versions cause we will put our live site's 'sites' dir there" #__dru_cp_from_site_dir_to_both_core_dirs sites backup cache ################## now do an interactive diff reolution - some things deleted, others copied , others left alone = hacks left to reside in the new version ######## the last diff should be NULL = dirs match exactly diff_command="diff -qr $orig $curr" diff_output=`$diff_command` #echo "$diff_output" #echo "$diff_output" | less # There are 3 cases (output of 'diff -qr dir1 dir2' below ): # Only in /var/www/vhosts/jdw.segments.at: 1.sql # Only in /var/www/vhosts/jdw.segments.at: 1.txt # Only in drupal-6.12/themes: bluemarine # Files drupal-6.12/themes/garland/style.css and /var/www/vhosts/jdw.segments.at/themes/garland/style.css differ # ... # 1. File/dir "Only in" dir1 - auto resolution - copy file/dir so dir1 and dir2 become identical # 2. File/dir "Only in" dir2 - same as above but copy in the opposite direction # 3. File/dir is in both dirs but there are differences - then do the following: 1. exit , 2. manual resolution, 3. diff again #echo "$diff_output" | grep "^Only in $site_dir" # diffr . ../drupal-6.12/| sed 's/: /\//' | sed 's/^Only in \.\///' | tr '\n' ' ' | sed 's/$/\n/' #echo "$diff_output" | grep -v "^Only in $site_dir" | grep "^Only in drupal-$site_drv" #echo "$diff_output" | grep -v "^Only in $site_dir" | grep -v "^Only in drupal-$site_drv" while [[ 1 == 1 ]] do echo $status echo "========= $diff_command ============" echo if $diff_command then echo "Identical" ; exit 0; # diff shows they are identical else echo " ========= diff end ============== There are some diffs. For action press a number. (after each action you will see the new diff that results) [1] resolve in background manually [2] resolve in background with help from me (copy-paste multi-file cp, rm commands we create for you) [3] cp $curr $orig [4] cp $orig $curr [5] rm $curr [6] rm $orig [7] produce a patch ... [8] quit " read act case $act in "1") echo $act ;; "2") echo $act ;; "3") echo $act ;; "4") echo $act ;; "5") echo $act ;; "6") echo $act ;; "7") echo $act ;; "8") echo $act ;; *) status="choose a number from the list" ;; esac fi done