views:

125

answers:

3

Is there any command line trick to get svn to add in all the missing files from svn stat interactively?

eg, something like:

svn add --interactive
$ new file:     file1.tmp (Add / Ignore) ?
$ missing file: file.tmp (Remove / Ignore) ?

EDIT:

If anyone knows of script that could achieve this that would also work.

+1  A: 
  1. I don't know of such a feature.
  2. Shouldn't be a problem to implement this yourself with a little scripting.
  3. The GUI interface does not suffer from this problem (e.g. Tortoise)...
Assaf Lavie
My scripting skills are kind of rusty, was wondering if anyone had such a script? I would like to avoid the gui
Sam Saffron
+1  A: 

The following line on a UNIX-shell adds all missing files:

svn status | grep '?' | sed 's/^.* /svn add /' | bash
Mnementh
The trouble is that it is not interactive, see my answer.
Sam Saffron
A: 

I wrote a little ruby script to do this:

require 'fileutils'
buffer = "" 

CACHE_DIR = File.join(ENV['HOME'], '.svn_interactive_temp')
FileUtils.mkdir_p(CACHE_DIR)

data = IO.popen 'svn stat' do |process|
  while process.read(512, buffer) 
  end
end

def handle_file(file) 
  system("stty raw")
  print "new file: #{file} [a]dd/[i]gnore/[s]kip? "
  c = STDIN.getc
  system("stty cooked")
  exit if c == 3
  c = c.chr
  success = true
  puts
  case c 
  when 'a'
    puts "adding the file: #{file}"
    system "svn add #{file}"
  when 'i'
    puts "adding svn:ignore for #{file}"
    cache_filename = File.join(CACHE_DIR, (1..10).map{(rand * 10).to_i}.to_s)
    p file
    parent = File.dirname(file)

    system("svn propget svn:ignore #{parent} >> #{cache_filename}")
    File.open(cache_filename, 'a') do |f| 
      f.puts(File.basename(file))
    end
    system("svn propset svn:ignore -F #{cache_filename} #{parent}")
    system("rm #{cache_filename}")
  when 's'
    puts "skipping: #{file}"
  else 
    success = false
  end
  success 
end

buffer.scan(/\?\s*(.*)$/).each do |file|
  while !(handle_file(file.to_s))
    sleep(0.01) 
  end
end

Eg:

sam@sam-ubuntu:~/Source/stuff$ ruby ../scripts/svn_interactive.rb
new file: test.txt [a]dd/[i]gnore/[s]kip? i
adding svn:ignore for test.txt
"test.txt"
property 'svn:ignore' set on '.'
Sam Saffron