开发者

How can I "svn delete" a folder and then add a folder with same name?

I wrote a deployment tool for my own programs based on SQL and Subversion.

I'm able to create different versions of applications and store them with Subversion while the information for those is stored in 开发者_运维百科SQL.

Until my "deployment tool" worked quite fine but now I found a problem.

When creating a version of an application I checkout the head revision and visualize this in my program. The latest version can then be edited by deleting, renaming, adding or overwriting files and folders.

Say, if I have the following tree structure in my working copy:

- ProgramFiles
  - Assemblies
  - Data
     - Type 1
         - ...
     - Type 2 
         - ...
     - Type 3
         - ...

I want to replace one directory (Data). This calls svn delete and after that Directory.Delete, because "svn delete" just marks the folders for delete when you do a commit. Now I want to add a folder named "Data" again with new subfolders and files but then I get an exception "working copy admin area is missing". As far as I can tell the problem is that the directory .svn under ProgramFiles stores information that the folder Data shall be deleted an if I read this folder it crashes.

I also know that I can commit before adding the folder but that would increase my revision number with a "non stable version".

How can I solve this problem?


You can't do this with one commit, you need to commit the delete and the add separately


Can't you just delete the folder contents instead of deleting the folder (but don't delete the ".svn" folder!), and then just put the new files there?


Well, after I've thought about the problem for a while assuming that it's impossible to do what I'm trying to do here I had an idea.

What I'm actually trying to do, is working an that working copy that means exchanging, deleting, moving adding and so on. All those changes shall be visualized in my program. (based on the folder structure on the filesystem)

All those changes should not be commited until the user wants to save it as a new "packet". This indicates that he may cancel the progress and nothing is commited neither changed.

I know tried a workaround doing an export first. Editing those folders and files. When I am now ready to commit, I checkout the same path, delete all those things that don't exist in working copy and add all new files from export into the working copy.

It's only a workaround but the only thing that comes through my mind.

Is there a method in subversion doing something like that? My workaround is running only half as fast as before, because of that export and checkout instead of only checking out the program.

Also the comparison of both folders is really complicated. Does anyone know a solution to simplify this?


If you need this to be performed in a single commit then it is possible, but tricky!

Instead of the simple svn delete and then Directory.Delete(...) you should write a function that recursively checks files and folders of incumbent vs desired.

Pseudo code:

function OverwriteFolder(old, new){
    foreach (file system) object in old or new{
        if object is in old and new{
            if object is file{
                overwrite file //no svn command needed
            }
            if object is folder{
                OverwriteFolder(old/object,new/object)
            }
        }
        if file is in old and not new{
            svn delete object
        }
        if file is in new and not old{
            svn add object
        }
    }
}

Now it should work in a single commit. it only fails if you're trying to replace a folder with a file of the same name or vice-versa.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜