Bash Script to Review Local Subversion Modifications

Daily task when you work with a source control system is to review your changes before check in, in order to avoid accidentally committing temporary (debugging) or incomplete changes.
Reviewing the changes from the command line (terminal) is a tedious task.
With Subversion you need to check for modifications by running:

svn stat

This command returns the list of locally modified files. Then you need to inspect those files, using:

svn diff <em>some_file</em>

The final step in the process is to commit the changes (comprising logical unit), by listing the files you want to commit:

svn ci <em>file1</em> ... <em>fileN</em> -m "Commit description"

I created a simple script that optimizes this task for me:

#!/bin/bash

svnList=""
key=""

lines=$(svn status)
while read status file
do
        if [ "$status" == "M" ]
        then 
                svn diff $file
                echo "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
                read -n 1 -p $"Press [y] to commit, [n] to skip file" key </dev/tty
                [[ "$key" == "y" ]] && svnList+=" $file"
                echo ""
        fi
done <<<"$lines"
if [ ! -z "$svnList" ]
then
        echo "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
        echo "Commit command:"
        echo "svn ci $svnList -m \"\""
fi

The script gets the list of modified files, diffs each one against the HEAD revision and asks the user to approve the change. All approved files are assembled into a check in command that can be used to commit the changes to the repository.

You can leave a response, or trackback from your own site.

Leave a Reply