[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Edit commit list prior to commit - qcommit.rb

From: Francois Beausoleil <fbos_at_users.sourceforge.net>
Date: 2003-08-23 17:50:29 CEST

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
Received on Sat Aug 23 17:51:24 2003

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.