6

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

For example, something like:

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

EDIT:

A script that could achieve this would also work.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Sam Saffron
  • 121,058
  • 74
  • 309
  • 495

3 Answers3

5

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

For example,

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 '.'
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Sam Saffron
  • 121,058
  • 74
  • 309
  • 495
1

The following line on a Unix shell adds all missing files.

svn status | grep '?' | sed 's/^.* /svn add /' | bash
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Mnementh
  • 47,129
  • 42
  • 140
  • 198
0
  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
  • 63,560
  • 33
  • 139
  • 197
  • My scripting skills are kind of rusty, was wondering if anyone had such a script? I would like to avoid the gui – Sam Saffron Jul 01 '09 at 11:26