#!/bin/bash # # Copyright 2013 Karljohan Lundin Palmerius # # This script assist in the task of doing partial commit with # subversion. It will copy the changed files, revert the changes and # use the tool kompare to copy selected changes back to the code # tree. Then it will make a commit after which the changed files will # be copied back to the code tree, allowing the user to make a second # partial commit. # # Warning: since all changes are reverted in the process, there is a # risk of data loss. Use this tool at your own risk, no guarantees are # gives whatsoever. If you do find a bug, please report it back. # # Usage: simply execute svn-ci-partial in you code tree. Do this from # an interactive shell, since the subversion command-line tool may # need to communicate with you. # # Dependencies: # Command-line tools bash, svn, kompare # # # Revision history: # # 2013-06-24 Moved creation of temporary folder to just before it is # first used. # # 2013-06-24 Added debug output. # # 2013-06-24 Added commit list so that only modified files are # committed. # # 2013-06-11 Updated tool name and documentation. # # 2013-06-10 Fix on IFS for correct handling of multiple files. # # 2013-05-19 Initial version. # KOMPARE=/usr/bin/kompare #OUTPUT_LEVEL=0 OUTPUT_LEVEL=2 function error_and_exit { echo $1 exit 1 } function dbg_output { if [ "$OUTPUT_LEVEL" -ge "$2" ] then echo $1 >&2 fi } dbg_output "(DD) Checking if current working directory is a Subversion copy." 2 svn info > /dev/null 2> /dev/null \ || error_and_exit "No working copy!" dbg_output "(DD) Checking modified files." 2 UP_TO_DATE=`svn status -uq 2> /dev/null \ | grep "^M....... " \ | sed -e "s/^M........//g" \ | sed 's/\s\s*/ /g' \ | cut -d ' ' -f 3-` OUT_OF_DATE=`svn status -uq 2> /dev/null \ | grep "^M.......\*" \ | sed -e "s/^M........//g" \ | sed 's/\s\s*/ /g' \ | cut -d ' ' -f 3-` onterm() { error_and_exit "Signal caught, there may be important files in backup in $TMP_FOLDER" } trap onterm INT TERM if [ -n "$OUT_OF_DATE" ] then error_and_exit "Out-of-date files exist ($OUT_OF_DATE_FILES)" fi if [ -z "$UP_TO_DATE" ] then error_and_exit "No changed files exist" fi dbg_output "(DD) Creating temporary folder for backup and intermediate storing." 2 TMP_FOLDER=`mktemp -d` dbg_output "(DD) Temporary folder: '$TMP_FOLDER'." 2 dbg_output "(DD) Copying modified files to temporary folder." 2 cp --parents $UP_TO_DATE $TMP_FOLDER \ || error_and_exit "Couldn't copy changed files" dbg_output "(DD) Reverting modified files in working copy." 2 svn revert $UP_TO_DATE > /dev/null 2> /dev/null dbg_output "(DD) User intervention to copy changes back from temporary folder to working copy." 2 IFS=$'\n' for path in $UP_TO_DATE do kompare "$TMP_FOLDER/$path" "./$path" done unset IFS dbg_output "(DD) Calling 'svn commit $UP_TO_DATE' to submit selected changes." 2 svn commit $UP_TO_DATE dbg_output "(DD) Copying back the files from temporary folder to working copy." 2 cp -r $TMP_FOLDER/* . \ || error_and_exit "Couldn't restore uncommited changes. Find backup in $TMP_FOLDER" dbg_output "(DD) Removing temporary folder." 2 rm -r $TMP_FOLDER \ || error_and_exit "Couldn't remove temporary files (in $TMP_FOLDER)"