You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Francois Beausoleil <fb...@users.sourceforge.net> on 2003/08/23 15:50:29 UTC

Edit commit list prior to commit - qcommit.rb

Hello all,

There recently was a mention of a feature which I found interesting.  The
feature is described here:
http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=43828

Look at point #3.

So, I set out to create a script that does exactly that.  This script,
which I named qcommit, is the result of this cogitation.

I hope somebody finds this useful.

Have a nice day !
François Beausoleil



#!/usr/bin/ruby
# A script that works in conjuction with Subversion.  This script works
by
# running svn status and finding all files which should be either added
or
# committed.  It then pops up SVN_EDITOR to allow modifying the list
# of files to commit.  Once the editor is closed, this script calls svn
commit
# without a message, allowing the user to create an appropriate message.
# If the list of files to commit includes files which have not yet been
# added to the repository, the script automagically adds them.
#
# Author:  François Beausoleil (fbos@users.sourceforge.net)
# Date:  2003/08/23

require "tempfile"

SeparatorLine = "-- Move the files below above this point to add them
automatgically --"

files = []
unknown = []
open("|svn status", 'r') do |io|
    io.each do |line|
        files << $1 if line =~ /^[^?]\s+(.*)$/
        unknown << $1 if line =~ /^\?\s+(.*)$/
        raise "#{$1} has conflicts.  Resolve the issue before committing"
        if
                line =~ /^C\s+(.*)/
        raise "#{$1} is missing.  Run svn update to update your working
        copy" if
                line =~ /^!\s+(.*)/
        raise if line =~ /error/i
    end
end

io = Tempfile.new("svn-commit.tmp")
files.each do |file|
    io.print file, $/
end

io.print $/, SeparatorLine, $/, $/

unknown.each do |file|
    io.print file, $/
end

io.close

raise "Unable to edit temporary file" unless
        system("#{ENV['SVN_EDITOR']}", io.path)

io.open
filestocommit = []
filestoadd = []
io.each do |line|
    next if line =~ /^$/
    break if line =~ /^#{SeparatorLine}$/

    line.chomp!

    filestoadd << line if unknown.include?(line)
    filestocommit << line
end
io.close

exit(0) if filestoadd.size == 0 && filestocommit.size == 0

raise "An error occured while adding files" unless
        system "svn add #{filestoadd.join(' ')}"
raise "An error occured while committing the files" unless
        system "svn commit #{filestocommit.join(' ')}"

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org