tags:

views:

47

answers:

2

Hi,

Please consider the following scenario:
1. User A creates and commits a file (lets say file1.txt).
2. User B deletes this file from the repository.
3. User A has the file in his local working copy and would like to restore it. The user finds that out after an Update() was done.

What is the proper way to achieve this?

So far I've tried:
- Client.Revert() followed by Update but I see no change.
- Client.Merge(local_working_copy, SvnUriTarget_of_repository, revision_range_between_the_previous_and_new) - still no change.
- Client.DiffMerge(), where the target path is the local path of the file, the merge_from is the path in the repository with the previous revision number, and the merge_to is the local path with the new revision. - I get an exception saying that the file is not under version control. It can't be added since it doesn't exist locally anymore. When I replaced the target path to be the repository path I get an exception saying this is not a working copy.

Please help,
Noa

+2  A: 

You should reverse the revision properties, because you're reversing the merge. This means you have to create an SvnRevisionRange like:

new SvnRevisionRange(newRevision, oldRevision);

When you use from old to new, you're trying to apply the same change again (which is a no-op because it has already happened).

Sander Rijken
Ok, this does make a different, but it also deletes other files that were added, and a status check still shows the restored file as out of date :( Thanks for your answer though.
Noich
you can also restore just the file instead of the entire working copy. To do this, pass an SvnUriTarget with Uri and revision (revision can be oldRevision, it's to indicate what file you need)
Sander Rijken
A: 

For anyone else who might need this and has no previous experience with SVN:

When running update, use this useful answer to subscribe to the Update() event. This way you can save all the names of the files that were deleted (or whatever other action interests you).

Then, after Update() is done, you can use Copy() as follows:
Copy(new SvnUriTarget(path/to/file/in/repository, new SvnRevision(the_old_revision_which_had_the_files)), local/path/to/file);

Now all that's left is to Commit() the file(s) back to the repository and you're done :)

Noa

Noich
but `Copy` ing stuff back is actually quite a bad idea. It's better to revert just the files you want to revert.
Sander Rijken
As I mentioned, I have no previous experience with Svn or SharpSvn. This is the best I found so far, but if you care to publish a piece of code to replace the `copy` action, I'd really appreciate it. Please remember that I need the deleted file to become a part of the new revision, nothing more. Thanks!
Noich