2009-07-01 15 views
5

C'è qualche trucco da riga di comando per far sì che SVN aggiunga in tutti i file mancanti da svn stat in modo interattivo?'svn add' interattivo

Per esempio, qualcosa come:

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

EDIT:

Un sceneggiatura che potrebbe raggiungere questo obiettivo sarebbe anche lavorare.

+1

+1 Mi piacerebbe vedere questa cosa lavorare come 'darcs record'. – liori

risposta

5

ho scritto un piccolo script Ruby per fare questo:

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 

Per esempio,

[email protected]:~/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 '.' 
0
  1. Non so di una tale funzionalità.
  2. Non dovrebbe essere un problema implementarlo con un po 'di script.
  3. L'interfaccia GUI non soffrono di questo problema (per esempio Tortoise) ...
+0

Le mie capacità di scripting sono piuttosto arrugginite, mi chiedevo se qualcuno avesse una sceneggiatura del genere? Vorrei evitare la gui –

1

La seguente riga su una shell Unix aggiunge tutti i file mancanti.

svn status | grep '?' | sed 's/^.* /svn add /' | bash 
+0

Il problema è che non è interattivo, vedere la mia risposta. –