Pierre
Pierre

Reputation: 9052

SVN cmd to update without restoring files

I have a Windows batch which will run periodically to add/remove files from SVN

I want the script to do:

  1. Delete all files which were deleted in Windows (not SVN) from SVN
  2. Add all files (*.*) which are not under version control yet
  3. Commit all changes
  4. Update the folder to make sure the folder is up to date.

I have the following batch:

:: Go to my folder (already checked out as SVN folder)
cd C:\MyFolder\

:: Delete/Remove all missing files
svn status || ? { $_ -match '^!\s+(.*)' } | % { svn rm $Matches[1] }

:: Add new files
svn add *.*

:: Commit all changes
svn commit *.* -m ^"Committed on %date% %time%"

:: Update the folder
svn up --accept mine-full

What happens after I deleted the file new file.txt myself in Windows Explorer

  1. The delete command runs then lists the file like ! new file.txt
  2. The add command runs, which adds all the new files if any
  3. Commit
  4. Update then restores the file new file.txt <-- I do not want it to restore the deleted file.

for the Delete/Remove part I also tried these two commands:

svn status || grep "^\!" || sed 's/^\! *//g' || xargs svn rm
svn status || grep "^\!" | sed 's/^\! *//g' | gawk '{print "\""$0"\"" }' | xargs svn rm  ::includes whitespaces in filenames

Output:

C:\MyFolder>svn status   || ? { $_ -match '!\s+(.*)' }   | { svn rm $Matches[1] }
!       new file.txt

C:\MyFolder>svn add *.*
svn: Skipping argument: E200025: '.svn' ends in a reserved name
svn: warning: W150002: 'C:\MyFolder\old.txt' is already under 
version control
svn: E200009: Could not add all targets because some targets are already 
versioned
svn: E200009: Illegal target for the requested operation

C:\MyFolder>svn commit *.* -m "Committed on 2018-10-23 12:15:57.90"
svn: Skipping argument: E200025: '.svn' ends in a reserved name

C:\MyFolder>svn up --accept mine-full
Updating '.':
Restored 'new file.txt'
At revision 21.
Press any key to continue . . .

Bottom line, the folder must be synced to SVN (backup) so if there are files added/deleted, it must be added/deleted in SVN as well

Upvotes: 2

Views: 367

Answers (2)

Pierre
Pierre

Reputation: 9052

Finally got it to work by myself. Thanks to @user3689460 in https://stackoverflow.com/a/23944546/1876355

I have added svn delete "missing.list" else it added the missing.list file to SVN

Here is my final batch script which works:

:: Go to my folder (already checked out as SVN folder)
cd C:\MyFolder\

:: Delete/Remove all missing files
svn status | findstr /R "^!" > missing.list
for /F "tokens=* delims=! " %%A in (missing.list) do (svn delete "%%A")
del missing.list 2>NUL
svn delete "missing.list"

:: Commit Deletion of missing files
svn commit -m "Deleted files from MyFolder on %date% %time%"

:: Add new files
svn add *.*

:: Commit all changes and additions
svn commit *.* -m ^"Committed MyFolder on %date% %time%"

:: Update the folder
svn up --accept mine-full

Upvotes: 1

Lutz
Lutz

Reputation: 2292

Maybe you can use "cut" to do the remove part, like this (which takes everything as of the 9th column of the previous output):

svn status | grep "^\!" | cut -c 9- | xargs svn rm

Upvotes: 0

Related Questions