Class: Subversion::SvnCommand

Inherits:
Console::Command
  • Object
show all
Defined in:
lib/subwrap/svn_command.rb,
lib/subwrap/svn_command.rb,
lib/subwrap/svn_command.rb

Defined Under Namespace

Modules: Add, Browse, Commit, Copy, Diff, EditMessage, EditRevisionProperty, Externalize, ExternalsItems, GetMessage, Help, Import, LocalIgnore, Log, Mkdir, Move, Revisions, SetMessage, ShowOrBrowseRevisions, Status, Update, ViewCommits, WhatsNew

Constant Summary collapse

@@user_preferences =
{}
@@subcommand_list =

This shouldn’t be necessary. Console::Command should allow introspection. But until such time…

[
  'each_unadded',
  'externals_items', 'externals_outline', 'externals_containers', 'edit_externals', 'externalize',
  'ignore', 'edit_ignores',
  'revisions',
  'get_message', 'set_message', 'edit_message',
  'view_commits',
  'url',
  'repository_root', 'working_copy_root', 'repository_uuid',
  'latest_revision',
  'delete_svn',
  'fix_out_of_date_commit_state'
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ SvnCommand

Returns a new instance of SvnCommand.



205
206
207
208
# File 'lib/subwrap/svn_command.rb', line 205

def initialize(*args)
  @passthrough_options = []
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(subcommand, *args) ⇒ Object

Any subcommands that we haven’t implemented here will simply be passed on to the built-in svn command. :todo: Distinguish between subcommand_missing and method_missing !

Currently, for example, if as isn't defined, this: puts Subversion.externalize(repo_path, {:as => as })
will call method_missing and try to run `svn as`, which of course will fail (without a sensible relevant error)...
I think we should probably just have a separate subcommand_missing, like we already have a separate option_missing !!!
Even a simple type (sss instead of ss) causes trouble... *this* was causing a call to "/usr/bin/svn new_messsage" -- what huh??
   def set_message(new_message = nil)
     args << new_messsage if new_message


253
254
255
256
# File 'lib/subwrap/svn_command.rb', line 253

def method_missing(subcommand, *args)
  #puts "method_missing(#{subcommand}, #{args.inspect})"
  svn :exec, subcommand, *args
end

Class Method Details

.parse_revision_ranges(revisions_array) ⇒ Object



947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
# File 'lib/subwrap/svn_command.rb', line 947

def SvnCommand.parse_revision_ranges(revisions_array)
  revisions_array.map do |item|
    case item
      when /(\d+):(\d+)/
        ($1.to_i .. $2.to_i)
      when /(\d+)-(\d+)/
        ($1.to_i .. $2.to_i)
      when /(\d+)\.\.(\d+)/
        ($1.to_i .. $2.to_i)
      when /\d+/
        item.to_i
      else
        raise "Item in revisions_array had an unrecognized format: #{item}"
    end
  end.expand_ranges
end

Instance Method Details

#__debugObject



217
218
219
# File 'lib/subwrap/svn_command.rb', line 217

def __debug
  $debug = true
end

#__dry_runObject



220
221
222
# File 'lib/subwrap/svn_command.rb', line 220

def __dry_run
  Subversion::dry_run = true
end

#__exceptObject Also known as: __exclude

Usually most Subversion commands are recursive and all-inclusive. This option adds file exclusion to most of Subversion’s commands. Use this if you want to commit (/add/etc.) everything but a certain file or set of files

svn commit dir1 dir2 --except dir1/not_ready_yet.rb


235
236
237
238
239
# File 'lib/subwrap/svn_command.rb', line 235

def __except
  # We'll have to use a FileList to do this. This option will remove all file arguments, put them into a FileList as inclusions, 
  # add the exclusions, and then pass the resulting list of files on to the *actual* svn command.
  # :todo:
end

#__no_colorObject



214
215
216
# File 'lib/subwrap/svn_command.rb', line 214

def __no_color
  Subversion::color = false
end

#__print_commandsObject Also known as: __show_commands, _V, __Verbose



224
225
226
# File 'lib/subwrap/svn_command.rb', line 224

def __print_commands
  Subversion::print_commands = true
end

#add(*args) ⇒ Object



309
310
311
312
# File 'lib/subwrap/svn_command.rb', line 309

def add(*args)
  #puts "add #{args.inspect}"
  svn :exec, 'add', *args
end

#add_all_unaddedObject


Raises:

  • (NotImplementedError)


1356
1357
1358
# File 'lib/subwrap/svn_command.rb', line 1356

def add_all_unadded
  raise NotImplementedError
end

#browse(directory = './') ⇒ Object



1548
1549
1550
1551
# File 'lib/subwrap/svn_command.rb', line 1548

def browse(directory = './')
  @interactive = true
  show_or_browse_revisions(directory)
end

#commit(*args) ⇒ Object

module Commit



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/subwrap/svn_command.rb', line 374

def commit(*args)
  directory = args.first || './'    # We can only pass one path to .latest_revision and .repository_root, so we'll just arbitrarily choose the first path. They should all be paths within the same repository anyway, so it shouldn't matter.
  if @broken || @skip_notification
    latest_rev_before_commit = Subversion.latest_revision(directory)
    repository_root = Subversion.repository_root(directory)
  end

  Subversion.print_commands! do
    puts svn(:capture, "propset svn:skip_commit_notification_for_next_commit true --revprop -r #{latest_rev_before_commit} #{repository_root}", :prepare_args => false)
  end if @skip_notification
  # :todo:
  # Add some logic to automatically skip the commit e-mail if the size of the files to be committed exceeds a threshold of __ MB.
  # (Performance idea: Only check the size of the files if svn st includes (bin)?)

  # Have to use :system rather than :capture because they may not have specified a commit message, in which case it will open up an editor...
  svn(:system, 'commit', *(['--force-log'] + args))

  puts ''.add_exit_code_error
  return if !exit_code.success?

  # The following only works if we do :capture (`svn`), but that doesn't work so well (at all) if svn tries to open up an editor (vim),
  # which is what happens if you don't specify a message.:
  #   puts output = svn(:capture, 'commit', *(['--force-log'] + args))
  #   just_committed = (matches = output.match(/Committed revision (\d+)\./)) && matches[1]

  Subversion.print_commands! do
    puts svn(:capture, "propset code:broken true --revprop -r #{latest_rev_before_commit + 1}", :prepare_args => false)
  end if @broken

  if @include_externals
    #:todo:
    #externals.each do |external|
    #svn(:system, 'commit', *(['--force-log'] + args + external))
    #end
  end


  # This should be disableable! ~/.subwrap ?
  # http://svn.collab.net/repos/svn/trunk/doc/user/svn-best-practices.html:
  #   After every svn commit, your working copy has mixed revisions. The things you just committed are now at the HEAD revision, and everything else is at an older revision.
  #puts "Whenever you commit something, strangely, your working copy becomes out of date (as you can observe if you run svn info and look at the revision number). This is a problem for svn log, and piston, to name two applications. So we will now update '#{(args.every + '/..').join(' ').white.bold}' just to make sure they're not out of date..."
  #print ''.bold # Clear the bold flag that svn annoyingly sets
  #working_copy_root = Subversion.working_copy_root(directory).to_s
  #response = confirm("Do you want to update #{working_copy_root.bold} now? (Any key other than y to skip) ")
  #if response == 'y'
    #puts "Updating #{working_copy_root} (non-recursively)..."
  #end
  #puts Subversion.update_lines_filter( Subversion.update(*args) )
end

#copy(*args) ⇒ Object



723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'lib/subwrap/svn_command.rb', line 723

def copy(*args)
  destination = args.pop

  # Unlike the built-in copy, this one lets you list multiple source files 
  #   Source... DestinationDir
  # or
  #   Source Destination
  # Useful when you have a long list of files you want to copy, such as when you are using wild-cards. Makes commands like this possible:
  #   svn cp source/* dest/
  if args.length >= 2
    sources = args

    sources.each do |source|
      puts filtered_svn('copy', source, destination)
    end
  else
    svn :exec, 'copy', *(args + [destination])
  end
end

#defaultObject

This is here solely to allow subcommandless commands like ‘svn –version`



258
259
260
# File 'lib/subwrap/svn_command.rb', line 258

def default()
  svn :exec
end

#delete_svn(directory = './') ⇒ Object


Cause a working copy to cease being a working copy



1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
# File 'lib/subwrap/svn_command.rb', line 1343

def delete_svn(directory = './')
  puts "If you continue, all of the following directories/files will be deleted:"
  system("find #{directory} -name .svn -type d | xargs -n1 echo")
  response = confirm("Do you wish to continue?")
  puts

  if response == 'y'
    system("find #{directory} -name .svn -type d | xargs -n1 rm -r")
  end
end

#diff(*directories) ⇒ Object



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/subwrap/svn_command.rb', line 506

def diff(*directories)
  directories = ['./'] if directories.empty?
  puts Subversion.colorized_diff(*(prepare_args(directories)))

  begin # Show diff for externals (if there *are* any and the user didn't tell us to ignore them)
    output = StringIO.new
    #paths = args.reject{|arg| arg =~ /^-/} || ['./']
    directories.each do |path|
      (Subversion.externals_items(path) || []).each do |item|
        diff_output = Subversion.colorized_diff(item).strip
        unless diff_output == ""
          #output.puts '-'*100
          #output.puts item.ljust(100, ' ').black_on_white.bold.underline
          output.puts item.ljust(100).yellow_on_red.bold
          output.puts diff_output
        end
      end
    end
    unless output.string == ""
      #puts '='*100
      puts (' '*100).yellow.underline
      puts " Diff of externals (**don't forget to commit these too!**):".ljust(100, ' ').yellow_on_red.bold.underline
      puts output.string
    end
  end unless @ignore_externals || @non_recursive
end

#each_unadded(*args) ⇒ Object


Goes through each “unadded” file (each file reporting a status of ?) reported by svn status and asks you what you want to do with them (add, delete, or ignore)



966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
# File 'lib/subwrap/svn_command.rb', line 966

def each_unadded(*args)
  catch :exit do

    $ignore_dry_run_option = true
    Subversion.each_unadded( Subversion.status(*args) ) do |file|
      $ignore_dry_run_option = false
      begin
        puts( ('-'*100).green )
        puts "What do you want to do with '#{file.white.underline}'?".white.bold
        begin
          if !File.exist?(file)
            raise "#{file} doesn't seem to exist -- even though it was reported by svn status"
          end
          if File.file?(file)
            if FileTest.binary_file?(file)
              puts "(Binary file -- cannot show preview)".bold
            else
              puts "File contents:"
              # Only show the first x bytes so that we don't accidentally dump the contens of some 20 GB log file to screen...
              contents = File.read(file, bytes_threshold = 5000) || ''
              max_lines = 55
              contents.lines[0..max_lines].each {|line| puts line}
              puts "..." if contents.length >= bytes_threshold          # So they know that there may be *more* to the file than what's shown
            end
          elsif File.directory?(file)
            puts "Directory contains:"
            Dir.new(file).reject {|f| ['.','..'].include? f}.each do |f|
              puts f
            end
          else
            raise "#{file} is not a file or directory -- what *is* it then???"
          end
        end
        print(
          "Add".menu_item(:green) + ", " +
          "Delete".menu_item(:red) + ", " +
          "add to " + "svn:".yellow + "Ignore".menu_item(:yellow) + " property, " + 
          "ignore ".yellow + "Contents".menu_item(:yellow) + " of directory, " + 
          "or " + "any other key".white.bold + " to do nothing > "
        )
        response = ""
        response = $stdin.getch.downcase # while !['a', 'd', 'i', "\n"].include?(begin response.downcase!; response end)

        case response
          when 'a'
            print "\nAdding... "
            Subversion.add file
            puts
          when 'd'
            puts

            response = ""
            if File.directory?(file)
              response = confirm("Are you pretty much " + "SURE".bold + " you want to '" + "rm -rf #{file}".red.bold + "'? ")
            else
              response = "y"
            end

            if response == 'y'
              print "\nDeleting... "
              FileUtils.rm_rf file
              puts
            else
              puts "\nI figured as much!"
            end
          when 'i'
            print "\nIgnoring... "
            Subversion.ignore file
            puts
          else
            # Skip / Do nothing with this file
            puts " (Skipping...)"
        end
      rescue Interrupt
        puts "\nGoodbye!"
        throw :exit
      end
    end # each_unadded

  end # catch :exit
end

#edit_externals(directory = nil) ⇒ Object



1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
# File 'lib/subwrap/svn_command.rb', line 1124

def edit_externals(directory = nil)
  catch :exit do
    if directory.nil? || !Subversion::ExternalsContainer.new(directory).has_entries?
      if directory.nil?
        puts "No directory specified. Editing externals for *all* externals dirs..."
        directory = "./"
      else
        puts "Editing externals for *all* externals dirs..."
      end
      Subversion.externals_containers(directory).each do |external|
        puts external.to_s
        command = "propedit svn:externals #{external.container_dir}"
        begin
          response = confirm("Do you want to edit svn:externals for this directory?".black_on_white)
          svn :system,  command if response == 'y'
        rescue Interrupt
          puts "\nGoodbye!"
          throw :exit
        ensure
          puts
        end
      end
      puts 'Done'
    else
      #system "#{Subversion.executable} propedit svn:externals #{directory}"
      svn :system, "propedit svn:externals #{directory}"
    end
  end # catch :exit
end

#edit_ignores(directory = './') ⇒ Object

Example:

svn edit_ignores tmp/sessions/


1237
1238
1239
1240
1241
1242
# File 'lib/subwrap/svn_command.rb', line 1237

def edit_ignores(directory = './')
  #puts Subversion.get_property("ignore", directory)
  # If it's empty, ask them if they want to edit it anyway??

  svn :system, "propedit svn:ignore #{directory}"
end

#edit_message(directory = './') ⇒ Object



1334
1335
1336
# File 'lib/subwrap/svn_command.rb', line 1334

def edit_message(directory = './')
  edit_revision_property('svn:log', directory)
end

#edit_property(property_name, directory = './') ⇒ Object



1338
1339
# File 'lib/subwrap/svn_command.rb', line 1338

def edit_property(property_name, directory = './')
end

#edit_revision_property(property_name, directory = './') ⇒ Object



1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
# File 'lib/subwrap/svn_command.rb', line 1301

def edit_revision_property(property_name, directory = './')
  args = ['propedit', '--revprop', property_name, directory]
  rev = @revision ? @revision : 'head'
  args.concat ['-r', rev]
  Subversion.print_commands! do
    svn :system, *args
  end

  value = Subversion::get_revision_property(property_name, rev)
  p value

  # Currently there is no seperate option to *delete* a revision property (propdel)... That would be useful for those
  # properties that are just boolean *flags* (set or not set).
  # I'm assuming most people will very rarely if ever actually want to set a property to the empty string (''), so
  # we can use the empty string as a way to trigger a propdel...
  if value == ''
    puts
    response = confirm("Are you sure you want to delete property #{property_name}".red.bold + "'? ")
    puts
    if response == 'y'
      Subversion.print_commands! do
        Subversion::delete_revision_property(property_name, rev)
      end
    end
  end
end

#externalize(repo_path, as_arg = nil) ⇒ Object

svn externalize your/repo/shared_tasks/tasks –as shared or

svn externalize http://your/repo/shared_tasks/tasks shared


1171
1172
1173
1174
1175
1176
# File 'lib/subwrap/svn_command.rb', line 1171

def externalize(repo_path, as_arg = nil)
  # :todo: let them pass in local_path as well? -- then we would need to accept 2 -- 3 -- args, the first one poylmorphic, the second optional
  # :todo: automated test for as_arg/as combo

  Subversion.externalize(repo_path, {:as => as || as_arg})
end

#externals_containers(directory = "./") ⇒ Object

Lists directories that have the svn:externals property set.



1117
1118
1119
1120
1121
# File 'lib/subwrap/svn_command.rb', line 1117

def externals_containers(directory = "./")
  puts Subversion.externals_containers(directory).map { |external|
    external.container_dir
  }
end

#externals_items(directory = "./") ⇒ Object



1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
# File 'lib/subwrap/svn_command.rb', line 1070

def externals_items(directory = "./")
  longest_path_name = 25

  externals_structs = Subversion.externals_containers(directory).map do |external|
    returning(
      external.entries_structs.map do |entry|
          Struct.new(:path, :repository_path).new(
            File.join(external.container_dir, entry.name).relativize_path,
            entry.repository_path
          )
        end
    ) do |entries_structs|
      longest_path_name = 
        [
          longest_path_name,
          entries_structs.map { |entry|
            entry.path.size
          }.max.to_i
        ].max
    end
  end

  puts externals_structs.map { |entries_structs|
    entries_structs.map { |entry|
      entry.path.ljust(longest_path_name + 1) +
        (@omit_repository_path ? '' : entry.repository_path)
    }
  }
  puts "(Tip: Also consider using svn externals_outline. Or use the -o/--omit-repository-path option if you just want a list of the paths that are externalled (without the repository URLs that they come from)".magenta unless @omit_repository_path
end

#externals_outline(directory = "./") ⇒ Object

For every directory that has the svn:externals property set, this prints out the container name and then lists the contents of its svn:externals property (dir, URL) as a bulleted list



1108
1109
1110
1111
1112
# File 'lib/subwrap/svn_command.rb', line 1108

def externals_outline(directory = "./")
  puts Subversion.externals_containers(directory).map { |external|
    external.to_s.relativize_path
  }
end

#fix_out_of_date_commit_state(dir) ⇒ Object

A fix for this annoying problem that I seem to come across all too frequentrly:

svn: Commit failed (details follow):
svn: Your file or directory 'whatever.rb' is probably out-of-date


431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/subwrap/svn_command.rb', line 431

def fix_out_of_date_commit_state(dir)
  dir = $1 if dir =~ %r|^(.*)/$|                           # Strip trailing slash.

  puts Subversion.export("#{dir}", "#{dir}.new").          # Exports (copies) the contents of working copy 'dir' (including your uncommitted changes, don't worry! ... and you'll get a chance to confirm before anything is deleted; but sometimes although it exports files that are scheduled for addition, they are no longer scheduled for addition in the new working copy, so you have to re-add them) to non-working-copy 'dir.new'
    add_exit_code_error 
  return if !exit_code.success?

  system("mv #{dir} #{dir}.backup")                        # Just in case something goes ary
  puts ''.add_exit_code_error
  return if !exit_code.success?

  puts "Restoring #{dir}..."
  Subversion.update dir                                    # Restore the directory to a pristine state so we will no longer get that annoying error

  # Assure the user that dir.new really does have your latest changes
  #puts "Here's a diff. Your changes/additions will be in the *right* (>) file."
  #system("diff #{dir}.backup #{dir}")

  # Merge those latest changes back into the pristine working copy
  system("cp -R #{dir}.new/. #{dir}/")

  # Assure the user one more time
  puts Subversion.colorized_diff(dir)

  puts "Please check the output of " + "svn st #{dir}.backup".blue.bold + " to check if any files were scheduled for addition. You will need to manually re-add these, as the export will have caused those files to lost their scheduling."
  Subversion.print_commands! do
    print Subversion.status_lines_filter( Subversion.status("#{dir}.backup") )
    print Subversion.status_lines_filter( Subversion.status("#{dir}") )
  end

  # Actually commit
  puts
  response = confirm("Are you ready to try the commit again now?")
  puts
  if response == 'y'
    puts "Great! Go for it. (I'd do it for you but I don't know what commit command you were trying to execute when the problem occurred.)"
  end

  # Clean up
  #puts
  #response = confirm("Do you want to delete array.backup array.new now?")
  puts "Don't forget to " + "rm -rf #{dir}.backup #{dir}.new".blue.bold + " when you are done!"
  #rm_rf array.backup, array.new
  puts
end

#get_messageObject



1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
# File 'lib/subwrap/svn_command.rb', line 1254

def get_message()
  #svn propget --revprop svn:log -r2325
  args = ['propget', '--revprop', 'svn:log']
  #args.concat ['-r', @revision ? @revision : Subversion.latest_revision]
  args.concat ['-r', (revision = @revision ? @revision : 'head')]
  puts "Message for r#{Subversion.latest_revision} :" if revision == 'head'

  $ignore_dry_run_option = true
  puts filtered_svn(*args)
  $ignore_dry_run_option = false
end

#grepObject

Raises:

  • (NotImplementedError)


1359
1360
1361
# File 'lib/subwrap/svn_command.rb', line 1359

def grep
  raise NotImplementedError
end

#grep_externalsObject

Raises:

  • (NotImplementedError)


1362
1363
1364
# File 'lib/subwrap/svn_command.rb', line 1362

def grep_externals
  raise NotImplementedError
end

#grep_logObject

Raises:

  • (NotImplementedError)


1365
1366
1367
# File 'lib/subwrap/svn_command.rb', line 1365

def grep_log
  raise NotImplementedError
end

#help(subcommand = nil) ⇒ Object



541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/subwrap/svn_command.rb', line 541

def help(subcommand = nil)
  case subcommand
    when "externals"
      puts %Q{
             | externals (ext): Lists all externals in the given working directory.
             | usage: externals [PATH]
             }.margin
      # :todo: Finish...

    when nil
      puts "You are using " + 
           's'.green.bold + 'u'.cyan.bold + 'b'.magenta.bold + 'w'.white.bold + 'r'.red.bold + 'a'.blue.bold + 'p'.yellow.bold + ' version ' + Project::Version
           ", a colorful, useful replacement/wrapper for the standard svn command."
      puts "subwrap is installed at: " + $0.bold
      puts "You may bypass this wrapper by using the full path to svn: " + Subversion.executable.bold
      puts
      puts Subversion.help(subcommand).gsub(<<End, '')

Subversion is a tool for version control.
For additional information, see http://subversion.tigris.org/
End

      puts
      puts 'Subcommands added by subwrap (refer to '.green.underline + 'http://subwrap.rubyforge.org/'.white.underline + ' for usage details):'.green.underline
      @@subcommand_list.each do |subcommand|
        aliases_list = subcommand_aliases_list(subcommand.option_methodize.to_sym)
        aliases_list = aliases_list.empty? ? '' : ' (' + aliases_list.join(', ') + ')'
        puts '   ' + subcommand + aliases_list
      end
      #p subcommand_aliases_list(:edit_externals)

    else
      #puts "help #{subcommand}"
      puts Subversion.help(subcommand)
  end
end

#ignore(file) ⇒ Object




1231
1232
1233
# File 'lib/subwrap/svn_command.rb', line 1231

def ignore(file)
  Subversion.ignore(file)
end

#import(*args) ⇒ Object



756
757
758
759
# File 'lib/subwrap/svn_command.rb', line 756

def import(*args)
  p args
  svn :exec, 'import', *(args)
end

#latest_revision(*args) ⇒ Object




900
901
902
# File 'lib/subwrap/svn_command.rb', line 900

def latest_revision(*args)
  puts Subversion.latest_revision
end

#local_ignoreObject Also known as: dont_commit, pretend_isnt_versioned



1223
1224
1225
# File 'lib/subwrap/svn_command.rb', line 1223

def local_ignore
  #...
end

#log(*args) ⇒ Object



592
593
594
595
# File 'lib/subwrap/svn_command.rb', line 592

def log(*args)
  puts Subversion.log( prepare_args(args) )
  #svn :exec, *args
end

#mkdir(*directories) ⇒ Object



614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/subwrap/svn_command.rb', line 614

def mkdir(*directories)
  if @create_parents
    directories.each do |directory|
    
      # :todo: change this so that it's guaranteed to have an exit condition; currently, can get into infinite loop
      loop do
        puts "Creating '#{directory}'"
        FileUtils.mkdir_p directory   # Create it if it doesn't already exist
        if Subversion.under_version_control?(File.dirname(directory))
          # Yay, we found a working copy. Now we can issue an add command, from that directory, which will recursively add the
          # (non-working copy) directories we've been creating along the way.
          
          #puts Subversion.add prepare_args([directory])
          svn :system, 'add', *directory
          break
        else
          directory = File.dirname(directory)
        end
      end
    end
  else
    # Preserve default behavior.
    svn :system, 'mkdir', *directories
  end
end

#move(*args) ⇒ Object



662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
# File 'lib/subwrap/svn_command.rb', line 662

def move(*args)
  destination = args.pop

  # If the last character is a '/', then they obviously expect the destination to be a *directory*. Yet when I do this:
  #   svn mv a b/
  # and b doesn't exist,
  #   it moves a (a file) to b as a file, rather than creating directory b/ and moving a to b/a.
  # I find this default behavior less than intuitive, so I have "fixed" it here...
  # So instead of seeing this:
  #   A  b
  #   D  a
  # You should see this:
  #   A  b
  #   A  b/a
  #   D  a
  if destination[-1..-1] == '/'
    if !File.exist?(destination[0..-2])
      puts "Notice: It appears that the '" + destination.bold + "' directory doesn't exist. Would you like to create it now? Good..."
      self.mkdir destination   # @create_parents flag will be reused there
    elsif !File.directory?(destination[0..-2])
      puts "Error".red.bold + ": It appears that '" + destination.bold + "' already exists but is not actually a directory. " +
        "The " + 'destination'.bold + " must either be the path to a " + 'file'.underline + " that does " + 'not'.underline + " yet exist or the path to a " + 'directory'.underline + " (which may or may not yet exist)."
      return
    end
  end

  if @create_parents and !Subversion.under_version_control?(destination_dir = File.dirname(destination))
    puts "Creating parent directory '#{destination_dir}'..."
    self.mkdir destination_dir   # @create_parents flag will be reused there
  end

  # Unlike the built-in move, this one lets you list multiple source files 
  #   Source... DestinationDir
  # or
  #   Source Destination
  # Useful when you have a long list of files you want to move, such as when you are using wild-cards. Makes commands like this possible:
  #   svn mv source/* dest/
  if args.length >= 2
    sources = args

    sources.each do |source|
      puts filtered_svn('move', source, destination)
    end
  else
    svn :exec, 'move', *(args + [destination])
  end
end

#option_missing(option_name, args) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/subwrap/svn_command.rb', line 262

def option_missing(option_name, args)
  #puts "#{@subcommand} defined? #{@subcommand_is_defined}"
  if !@subcommand_is_defined
    # It's okay to use this for pass-through subcommands, because we just pass all options/arguments verbatim anyway...
    #puts "option_missing(#{option_name}, #{args.inspect})"
  else
    # But for subcommands that are defined here, we should know better! All valid options should be explicitly listed!
    raise UnknownOptionError.new(option_name)
  end

  # The following is necessary because we really don't know the arity (how many subsequent tokens it should eat) of the option -- we don't know anything about the options, in fact; that's why we've landed in option_missing.
  # This is kind of a hokey solution, but for any unrecognized options/args (which will be *all* of them unless we list the available options in the subcommand module), we just eat all of the args, store them in @passthrough_options, and later we will add them back on.
  # What's annoying about it this solution is that *everything* after the first unrecognized option comes in as args, even if they are args for the subcommand and not for the *option*!
  # But...it seems to work to just pretend they're options.
  # It seems like this is mostly a problem for *wrappers* that try to use Console::Command. Sometimes you just want to *pass through all args and options* unchanged and just filter the output somehow.
  # Command doesn't make that super-easy though. If an option (--whatever) isn't defined, then the only way to catch it is in option_missing. And since we can't the arity unless we enumerate all options, we have to hokily treat the first option as having unlimited arity.
  #   Alternatives considered: 
  #     * Assume arity of 0. Then I'm afraid it would extract out all the option flags and leave the args that were meant for the args dangling there out of order ("-r 1 -m 'hi'" => "-r -m", "1 'hi'")
  #     * Assume arity of 1. Then if it was really 0, it would pick up an extra arg that really wasn't supposed to be an arg for the *option*.
  # Ideally, we wouldn't be using option_missing at all because all options would be listed in the respective subcommand module...but for subcommands handled through method_missing, we don't have that option.

  # The args will look like this, for example:
  #   option_missing(-m, ["a multi-word message", "--something-else", "something else"])
  # , so we need to be sure we wrap multi-word args in quotes as necessary. That's what the args.shell_escape does.

  @passthrough_options << "#{option_name}" << args.shell_escape
  @passthrough_options.flatten!  # necessary now that we have args.shell_escape ?

  return arity = args.size  # All of 'em
end

#play_revisions(directory = './') ⇒ Object



1534
1535
1536
1537
# File 'lib/subwrap/svn_command.rb', line 1534

def play_revisions(directory = './')
  @interactive = false
  show_or_browse_revisions(directory)
end

#repository_root(*args) ⇒ Object

Returns root repository URL for a working copy



893
894
895
# File 'lib/subwrap/svn_command.rb', line 893

def repository_root(*args)
  puts Subversion.repository_root(*args)
end

#repository_uuid(*args) ⇒ Object

Returns the UUID for a working copy/URL



887
888
889
# File 'lib/subwrap/svn_command.rb', line 887

def repository_uuid(*args)
  puts Subversion.repository_uuid(*args)
end

#set_message(new_message) ⇒ Object



1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
# File 'lib/subwrap/svn_command.rb', line 1276

def set_message(new_message)
  #svn propset --revprop -r 25 svn:log "Journaled about trip to New York."
  puts "Message before changing:"
  get_message

  args = ['propset', '--revprop', 'svn:log']
  args.concat ['-r', @revision ? @revision : 'head']
  args << new_message if new_message
  if @filename
    contents = File.readlines(@filename).join.strip
    puts "Read file '#{@filename}':"
    print contents
    puts
    args << contents
  end
  svn :exec, *args
end

#status(*args) ⇒ Object



806
807
808
809
810
811
# File 'lib/subwrap/svn_command.rb', line 806

def status(*args)
  options = {}
  options[:only_statuses] = @only_statuses
  options[:files_only] = @files_only
  print Subversion.status_lines_filter( Subversion.status(*(prepare_args(args))), options )
end

#under_version_control(*args) ⇒ Object




875
876
877
# File 'lib/subwrap/svn_command.rb', line 875

def under_version_control(*args)
  puts Subversion.under_version_control?(*args)
end

#update(*args) ⇒ Object



845
846
847
848
849
850
851
852
853
854
# File 'lib/subwrap/svn_command.rb', line 845

def update(*args)
  directory = (args[0] ||= './')
  revision_of_directory = Subversion.latest_revision_for_path(directory)
  puts "(Note: The working copy '#{directory.white.bold}' was at #{('r' + revision_of_directory.to_s).magenta.bold} before updating...)"

  @passthrough_options << '--ignore-externals' if ignore_externals?
  Subversion.print_commands! do   # Print the commands and options used so they can be reminded that they're using user_preferences['update']['ignore_externals']...
    puts Subversion.update_lines_filter( Subversion.update(*prepare_args(args)) )
  end
end

#url(*args) ⇒ Object




869
870
871
# File 'lib/subwrap/svn_command.rb', line 869

def url(*args)
  puts Subversion.url(*args)
end

#view_commits(path = "./") ⇒ Object



928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File 'lib/subwrap/svn_command.rb', line 928

def view_commits(path = "./")
  if @revisions.nil?
    raise "-r (revisions) option is mandatory"
  end
  $ignore_dry_run_option = true
  base_url = Subversion.base_url(path)
  $ignore_dry_run_option = false
  #puts "Base URL: #{base_url}"
  revisions = self.class.parse_revision_ranges(@revisions)
  revisions.each do |revision|
    puts Subversion.log("-r #{revision} -v #{base_url}")
  end
  
  puts Subversion.diff("-r #{revisions.first}:#{revisions.last} #{path}")
  #/usr/bin/svn diff http://code.qualitysmith.com/gemables/subversion@2279 http://code.qualitysmith.com/gemables/subwrap@2349 --diff-cmd colordiff

end

#whats_new(directory = './') ⇒ Object



1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
# File 'lib/subwrap/svn_command.rb', line 1570

def whats_new(directory = './')
  revision_of_directory = Subversion.latest_revision_for_path(directory)

  #__whats_new
  # (allow this to be overriden with, for example, a --since option)
  @first_revision_default = revision_of_directory.to_s
  @last_revision_default  = 'head'
  @oldest_first_default = true

  #puts "Updating..."
  #Subversion.update(directory)  # silent
  #Subversion.execute("update")

  @interactive = false
  show_or_browse_revisions(directory)
end

#working_copy_root(*args) ⇒ Object

Returns root/base path for a working copy



881
882
883
# File 'lib/subwrap/svn_command.rb', line 881

def working_copy_root(*args)
  puts Subversion.working_copy_root(*args)
end