简体   繁体   中英

Update Local Workspace to SVN Repository 'Head' With Ruby SVN Bindings

I am writing a program in Ruby that necessitates downloading the most current version of my team's software from SVN upon start up.

The checkout function (from the Ruby SVN bindings) is what I believe I want to use, because an update would not ADD any files that do not exist on my machine's local "trunk" workspace. A checkout statement would both update files that do not match to HEAD, and it would download ones that don't exist at all. Effectively, after running a fully recursive checkout, I would hope to have an exact copy of the most recent SVN repository.

According to this API , a checkout statement basically takes the following:

  • an exact SVN URL
  • a local root project directory
  • a revision (I would be using the string 'HEAD')
  • recursive (integer 1 or 0)
  • a pool object (I cannot determine what this is for exactly, but I don't think it affects me)

Here's what I wrote, inside a block that iterates for each file in the SVN repository:

if status != NORMAL #any file that changed or is 'missing'
  ctx.checkout(status.entry.url, ROOTDIR, 'HEAD', 0, nil) #update abnormal file to HEAD
end

As a test, I erased a directory from my local workspace, and attempted to restore it with this command. It runs through until it reaches one of the missing files, at which point it raises an error:

`svn_client_checkout3': subversion/libsvn_fs_fs/tree.c:663: Svn::Error::FsNotFound: File not found: revision 0, path '/trunk/project-gadfly/SocketServer/DiscoveryServer.cpp' (Svn::Error::FsNotFound)

I do not understand why this error would be raised, because I thought that a checkout statement would see that the directory (ie file) does not exist locally and then create it. Perhaps I am doing something wrong?

Looking back on what I've written, I think all of this was a long-winded way of asking the following simple question: How do I get the most current version of SVN repository onto my local hard drive with an SVN Ruby command?

Thanks in advance, Elwood Hopkins

I don't know about Ruby-specific part of the question, but it's clear that you asked SVN API to checkout "status.entry.url" at revision 0, which of course doesn't exist here.

It's also strange that you looked into Perl documentation for writing in Ruby. I would recommend you to look at Subversion sources instead.

Here's Ruby method declaration: http://svn.apache.org/repos/asf/subversion/branches/1.7.x/subversion/bindings/swig/ruby/svn/client.rb

  def checkout(url, path, revision=nil, peg_rev=nil,
               depth=nil, ignore_externals=false,
               allow_unver_obstruction=false)
    revision ||= "HEAD"
    Client.checkout3(url, path, peg_rev, revision, depth,
                     ignore_externals, allow_unver_obstruction,
                     self)
  end

So as you can see, you've specified 0 as peg revision. But you should specify HEAD instead.

What about pools --- they are parts of SVN memory managements. Here's the explanation: http://subversion.apache.org/docs/community-guide/conventions.html#apr-pools

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM