I have a Windows batch which will run periodically to add/remove files from SVN
I want the script to do:
- Delete all files which were deleted in Windows (not SVN) from SVN
- Add all files (
*.*
) which are not under version control yet - Commit all changes
- 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
- The delete command runs then lists the file like
! new file.txt
- The add command runs, which adds all the new files if any
- Commit
- 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