Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svn delete removed files

Tags:

svn

I have a working copy of an SVN project. Files get deleted from this working copy by an application. When I commit the working copy using the SVN command-line I would like to remove these deleted files from the repository.

If I commit the working copy using svn commit it doesn't remove the files from the project (because they weren't deleted locally with svn delete. Is there some way that I can tell SVN to remove (from the repository) any files that are missing in the working copy?

like image 343
Dónal Avatar asked Jun 16 '12 19:06

Dónal


People also ask

How remove deleted file from svn?

If you are using TortoiseSVN, just do a Check for Modifications, sort by the Status column, select all the entries marked missing , right-click to open the context menu, and select Delete. Finally, commit to publish the changes to the repository.

What will happen if some versioned file or directory is removed from working copy by svn delete command?

Using svn to delete a file from your working copy deletes your local copy of the file, but it merely schedules the file to be deleted from the repository. When you commit, the file is deleted in the repository.

What does svn RM do?

@Nyerguds That's correct, as the svn rm is removing the files from the repository. In the event you wish to remove files from the repo, BUT keep them locally on your machine then you'd use the flag above.


2 Answers

use an

svn status

it will list changes with the working copy. (deleted files start with a ! )

Then, you can :

svn delete file_to_del1 file_to_del2 etc

and finally commit

You can also write a little snippet to automate this:

svn status | grep '^!' | awk '{print $2}' | xargs svn delete

And eventually add an alias :

alias svn_precommit="svn status | grep '^!' | awk '{print $2}' | xargs svn delete"

If you need to support @ / spaces in file names you need to complicate the script (you should not use those chars in filenames but sometimes thats a decision that has been done by someone else) - you can use this in your .bashrc directly:

svn_prepare_del() {
        svn st | grep '^!' | awk '{$1=""; print " --force \""substr($0,2)"@\"" }' | xargs svn delete
}
like image 153
naab Avatar answered Oct 23 '22 23:10

naab


Your question as phrased (Is there some way that I can tell SVN to remove (from the repository) any files that are missing in the working copy?) is really a duplicate of the related question svn command to delete all locally missing files. In response to that question, I provided a one-line PowerShell script to let you automatically identify and remove the requisite files from your repository. I reproduce it here for convenience:

svn status | ? { $_ -match '^!\s+(.*)' } | % { svn rm $Matches[1] }

That assumes, of course, that you are on Windows. Here is an analogous solution if you are on Linux/Unix.

However, when you add in part two of your question, which you inadvertantly revealed :-) in a later comment--Is there a way to make this happen automatically upon a commit?--then your question is unique.

The only avenue I could see to answer part two is using a pre-commit hook, i.e. a hook script executed upon initiating a commit but before the commit itself actually occurs. Normally, you would use a pre-commit hook to validate some set of conditions and either allow the commit to proceed or terminate. Alas, I do not think it is allowable, let alone advisable, to modify the set of files being committed during the commit itself. But I have not found this point documented so you may want to dig further on this point.

2012.06.19 Clarification per Don's comment

Don is correct that you need a client-side hook, not a server-side hook because the deleted files to process are on the client. Command-line svn does not have this option but TortoiseSVN does offer client-side hooks. In fact, after I perused the referenced manual page I was reminded that not only does TortoiseSVN offer a pre-commit hook, but it also offers a start-commit hook, which is ideal for this situation. The difference is that the pre-commit hook runs after you open the commit dialog and after you press OK to attempt to execute the commit. The start-commit hook, on the other hand, runs before the commit dialog opens. Thus, with the hook script in place, by the time you see the list of files to commit it will include the files it is going to delete as well!

like image 7
Michael Sorens Avatar answered Oct 24 '22 01:10

Michael Sorens