'svn add' interactive

前端 未结 3 1407
闹比i
闹比i 2021-01-18 12:41

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

For example, something like:

s         


        
相关标签:
3条回答
  • 2021-01-18 12:44

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

    svn status | grep '?' | sed 's/^.* /svn add /' | bash
    
    0 讨论(0)
  • 2021-01-18 12:44
    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)...
    0 讨论(0)
  • 2021-01-18 13:05

    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 '.'
    
    0 讨论(0)
提交回复
热议问题