Reputation: 9052
I have a Windows batch which will run periodically to add/remove files from SVN
I want the script to do:
*.*
) which are not under version control yetI 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
! new file.txt
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
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
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