Skip to content

Instantly share code, notes, and snippets.

@tollyx
Last active August 17, 2016 13:23
Show Gist options
  • Save tollyx/6ed47fb6e5d97821fdb2c9f3814cc5ef to your computer and use it in GitHub Desktop.
Save tollyx/6ed47fb6e5d97821fdb2c9f3814cc5ef to your computer and use it in GitHub Desktop.
Fixes the svn history for multiple files when they've been moved without using 'svn move'
--
-- Fixes the svn history for multiple files
-- when they've been moved without using 'svn move'
--
-- It does not work on files that has been renamed
--
-- It works by looking for missing and untracked files with matching file names,
-- moving the untracked file to the missing files location and then moving it back
-- using svn move.
--
-- I cannot guarantee that it will work for all cases, so do a dry run first
-- and make sure it won't mess anything up.
--
local dryrun = false
if dryrun then
os.execute = print
end
local missing = {}
local untracked = {}
local filepattern = ".+[ \\](.-)$"
local pathpattern = " +(.*)\\.-$"
local svnstatus = io.popen("svn status")
for line in svnstatus:lines() do
if line:match("^%?") then
-- Untracked files
local file = line:match(filepattern)
local folder = line:match(pathpattern)
if not folder then folder = "." end
added[file] = folder
elseif line:match("^!") then
-- Missing files
local file = line:match(filepattern)
local folder = line:match(pathpattern)
if not folder then folder = "." end
untracked[file] = folder
end
end
for fileM,folderM in pairs(missing) do
for fileU,folderU in pairs(untracked) do
if fileU == fileM then
os.execute('move "'..folderU..'\\'..fileU..'" "'..folderM..'\\'..fileM..'"')
os.execute('svn mv "'..folderM..'\\'..fileM..'" "'..folderU..'"')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment