Jordan
Jordan

Reputation: 9114

Delete "Deleted" files from local repository

How do I delete files which have been deleted from the Repo but have not been deleted locally yet?

Essentially, I'm writing a build script in powershell that needs to get the most up-to-date changes from the repo and checkout, but there might be files which were deleted from the repo which haven't yet been deleted from my local checkout. I mean, one solution is to just delete everything and do a clean checkout, but that's rather expensive and would take a long time. I could also do a svn status and look for anything with a "D" and delete them locally, but that's rather tedious. I'd like to also just overwrite any conflicts and --force the checkout for files which need to be merged.

Is there some simple command like revert or a checkout switch that I'm missing?


**Edit: There are actually two different cases that I need to handle:

Part A) In one section, I need to leave anything modified in the working copy alone and just checkout the changes that aren't conflicts or merged. I need this to never abort, meaning that I just want to throw away anything that has a problem and keep the working/local copy.

I was thinking of using: svn update --accept mine-full --force (Note: This is on the root directory and not individual files)

Part B) In the other section, I want to overwrite any changes and delete files which were deleted in the repo.

I was thinking of using: svn update --accept theirs-full --force (Note: This is on the root directory and not individual files)

Would this work? Or is --force (or --accept) not what I want to be using?


My main concern with using update is that it will abort the entire process if there's a problem, won't it? What does --force do with svn update? It also doesn't delete unversioned items.

Revert isn't exactly what I need either, is it? It doesn't delete any of my unversioned items.

Also, doesn't checkout just do the same thing as update if there are already local files? It would be much simpler to just use checkout in the case where nothing exists yet. The problem is that I cannot specify the --accept parameter with svn checkout. I suppose I could test if the folder exists and then do a checkout or an update accordingly.

Upvotes: 3

Views: 5431

Answers (2)

Jordan
Jordan

Reputation: 9114

For Part A, I used:

svn update --accept mine-full --force

For Part B, I just did:

Step 1:

svn revert $localPath

Step 2:

svn update $localPath

Step 3 (using powershell + svn status, but can be done with rm -rf grep/sed in *nix):

svn status $localPath --no-ignore |
                Select-String '^[?I]' |
                ForEach-Object {
                    [Regex]::Match($_.Line, '^[^\s]*\s+(.*)$').Groups[1].Value
                } |
                Remove-Item -Recurse -Force -ErrorAction SilentlyContinue

Upvotes: 2

Edwin Buck
Edwin Buck

Reputation: 70979

If you delete the file manually, it will be restored until you update your local repository to the same version that lacks the file in the repository. So, the first course of action is to attempt to update your repository.

svn update

There are a few caveats. First, if someone deleted the file but didn't checkin his deletion, the deletion isn't really in the remote repository. Second, if you modified the file, you might get a conflict, as the deleted file in the repository isn't the same deleted file on your disk.

Assuming that there are some sort of conflicts which does make the update difficult. You should try

svn revert <problem file name>

And attempt the update again.

Using the --force option without having an excellent picture of what is going on is almost always a bad idea. Basically it's like not listening to expert advise. If you have more expertise than the advice giver, you know the caveats and pain points to avoid. If you don't have more expertise than the advice giver, you are going to hurt yourself. --force is not a "try again, ignoring warnings" flag, it is a "do it anyway, even if it totally screws up things" option.

Upvotes: 0

Related Questions