Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'svn add' interactive

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.

like image 856
Sam Saffron Avatar asked Jul 01 '09 11:07

Sam Saffron


People also ask

How do I commit changes in svn?

Select any file and/or folders you want to commit, then TortoiseSVN → Commit.... The commit dialog will show you every changed file, including added, deleted and unversioned files. If you don't want a changed file to be committed, just uncheck that file.

How do I add files to svn?

To add an existing file to a Subversion repository and put it under revision control, change to the directory with its working copy and run the following command: svn add file… Similarly, to add a directory and all files that are in it, type: svn add directory…

How do I commit a directory in svn?

Right-click in an empty area of the folder and select Refresh. You'll see “+” icons on the folders/files, now. Right-click an empty area in the folder once again and select SVN Commit. Add a message regarding what you are committing and click OK.

What is svn commit and update?

Read the SVN book, or at least the chapter about fundamental concepts and basic usage. Update means: "take all the new stuff in the repository and apply them in my working copy". Commit means: "take all the changes I've made in my working copy and apply them in the repository"


2 Answers

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 '.'
like image 87
Sam Saffron Avatar answered Sep 23 '22 07:09

Sam Saffron


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

svn status | grep '?' | sed 's/^.* /svn add /' | bash
like image 44
Mnementh Avatar answered Sep 26 '22 07:09

Mnementh