Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix updating archived based files keeping local changes if diff and

patch can be found in PATH
Note: Updating VCS repositories throws an error on failure now
This was necessary to distinguish "Don't know how to handle this case"
from "do know, but failed"
In the first case the diff then patch implementation is used.
  • Loading branch information...
commit cf5299e2f67f046dd8d8aab5c767d03aadc2b16e 1 parent c81031e
@MarcWeber authored
View
66 autoload/scriptmanager2.vim
@@ -106,8 +106,8 @@ fun! scriptmanager2#UpdateAddon(name)
let newVersion = get(repository,'version','?')
let versionFile = pluginDir.'/version'
- let oldVersion = filereadable(versionFile) ? readfile(versionFile, true)[0] : "?"
- if oldVersion != newVersion || newVersion == '?'
+ let oldVersion = filereadable(versionFile) ? readfile(versionFile, 1)[0] : "?"
+ if oldVersion != newVersion || newVersion == '?'
" update plugin
echom "updating plugin ".a:name." because ".(newVersion == '?' ? 'version is unkown' : 'there is a different version')
let has_diff = executable('diff')
@@ -122,24 +122,37 @@ fun! scriptmanager2#UpdateAddon(name)
endif
endif
call rename(pluginDir, pluginDirBackup)
+ " can be romved. old version is encoded in tmp dir. Removing makes
+ " diffing easier
+ silent! call delete(pluginDirBackup.'/version')
" try creating diff by checking out old version again
if has_diff
- let diff_file = fnamemodify(pluginDir.'-'.oldVersion.'.diff')
+ let diff_file = s:c['plugin_root_dir'].'/'.a:name.'-'.oldVersion.'.diff'
" try to create a diff
- let archiveName = s:ArchiveNameFromDict(a:repository)
+ let archiveName = scriptmanager2#ArchiveNameFromDict(repository)
let archiveFileBackup = pluginDirBackup.'/archive/'.archiveName
if !filereadable(archiveFileBackup)
echom "old archive file ".archiveFileBackup." is gone, can't try to create diff."
else
let archiveFile = pluginDir.'/archive/'.archiveName
- call mkdir(pluginDir.'/archive',1)
+ call mkdir(pluginDir.'/archive','p')
call scriptmanager_util#CopyFile(archiveFileBackup, archiveFile)
- call scriptmanager_util#Unpack(archiveFile, a:targetDir,{ 'strip-components': get(repository,'strip-components',-1) })
- let diff = system(scriptmanager_util#ShellDSL('diff -U3 -r $p $p', pluginDirBackup, pluginDir)
- if diff != "" | call writefile([diff], diff_file, 1) | endif
+
+ let rep_copy = deepcopy(repository)
+ let rep_copy['url'] = 'file://'.expand(archiveFile)
+ call scriptmanager2#Checkout(pluginDir, rep_copy)
+ silent! call delete(pluginDir.'/version')
+ try
+ call vcs_checkouts#ExecIndir([{'d': s:c['plugin_root_dir'], 'c': scriptmanager_util#ShellDSL('diff -U3 -r $p $p', fnamemodify(pluginDir,':t'), fnamemodify(pluginDirBackup,':t')).' > '.diff_file}])
+ silent! call delete(diff_file)
+ catch /.*/
+ " :-( this is expected. diff returns non zero exit status. This is hacky
+ let diff=1
+ endtry
call scriptmanager_util#RmFR(pluginDir)
+ echo 6
endif
endif
@@ -148,20 +161,22 @@ fun! scriptmanager2#UpdateAddon(name)
" try applying patch
let patch_failure = 0
- if exists('diff') && diff != ""
+ if exists('diff')
if executable("patch")
- call system(scriptmanager_util#ShellDSL('patch -d $p $p', pluginDir, diff_file))
- let patch_failure = v:shell_error
- else
- let patch_failure = 1
- echom "failed trying to apply diff. patch exectubale not found"
- endif
- if !patch_failure
- echom "patching suceeded"
- call delete(diff_file)
- else
- echom "failed applying patch ".diff_file
- endif
+ try
+ call vcs_checkouts#ExecIndir([{'d': pluginDir, 'c': 'patch -p1 < '. diff_file }])
+ echom "patching suceeded"
+ let patch_failure = 0
+ call delete(diff_file)
+ let patch_failure = 0
+ catch /.*/
+ let patch_failure = 1
+ echom "failed applying patch ".diff_file." kept old dir in ".pluginDirBackup
+ endtry
+ else
+ echom "failed trying to apply diff. patch exectubale not found"
+ let patch_failure = 1
+ endif
endif
" tidy up - if user didn't provide diff we remove old directory
@@ -283,6 +298,7 @@ endf
" endwhile
" endfun
+" basename of url. if archive_name is given use that instead
fun! scriptmanager2#ArchiveNameFromDict(repository)
let archiveName = fnamemodify(substitute(get(a:repository,'archive_name',''), '\.\zsVIM$', 'vim', ''),':t')
if archiveName == ''
@@ -298,12 +314,11 @@ fun! scriptmanager2#Checkout(targetDir, repository) abort
call vcs_checkouts#Checkout(a:targetDir, a:repository)
else
" archive based repositories - no VCS
- " must have a:repository['archive_name']
if !isdirectory(a:targetDir) | call mkdir(a:targetDir.'/archive','p') | endif
" basename VIM -> vim
- let archiveName = s:ArchiveNameFromDict(a:repository)
+ let archiveName = scriptmanager2#ArchiveNameFromDict(a:repository)
" archive will be downloaded to this location
let archiveFile = a:targetDir.'/archive/'.archiveName
@@ -315,8 +330,9 @@ fun! scriptmanager2#Checkout(targetDir, repository) abort
call writefile([get(a:repository,"version","?")], a:targetDir."/version")
" hook for plugin / syntax files: Move into the correct direcotry:
- if a:repository['archive_name'] =~? '\.vim$'
- let type = tolower(get(a:repository,'script-type',''))
+ let scriptType = get(a:repository, 'script-type','')
+ if scriptType != ""
+ let type = tolower(scriptType)
if type =~# '^\%(syntax\|indent\|ftplugin\|plugin\|autoload\)$'
let dir = a:targetDir.'/'.type
call mkdir(dir)
View
51 autoload/scriptmanager_test.vim
@@ -70,38 +70,57 @@ fun! scriptmanager_test#TestUnpack(test) abort
endfor
endf
-fun! scriptmanager_test#TestUpdate()
+" tests that creating and applying diffs when updating archive plugins (found
+" on www.vim.org) works as expected.
+fun! scriptmanager_test#TestUpdate(case) abort
call scriptmanager2#LoadKnownRepos()
let tmpDir = scriptmanager_util#TempDir("vim-addon-manager-test")
let plugin_name = "www_vim_org_update_test"
let plugin_source_file = tmpDir.'/'.plugin_name.'.vim'
let installDir = scriptmanager#PluginDirByName(plugin_name)
let installCompareDir = scriptmanager#PluginDirByName(plugin_name.'-1.0')
+ silent! unlet g:vim_script_manager['activated_plugins'][plugin_name]
for dir in [tmpDir, installDir, installCompareDir]
- if isdirectory(dir) | scriptmanager_util#RmFR(dir) | endif
+ if isdirectory(dir) | call scriptmanager_util#RmFR(dir) | endif
endfor
- call mkdir(tmpDir.'/plugin',1)
+ call mkdir(tmpDir.'/plugin','p')
- let file_v1 = ["version 1.0, "1", "2", "3", "4", "5" ]
- let file_v1_patched = ["version 1.0, "1", "2", "3", "4", "patched" ]
- let file_v2 = ["version 2.0, "1", "2", "3", "4", "5" ]
- let file_v2_patched = ["version 2.0, "1", "2", "3", "4", "patched" ]
+ let file_v1 = ["version 1.0", "1", "2", "3", "4", "5" ]
+ let file_v1_patched = ["version 1.0", "1", "2", "3", "4", "patched" ]
+ let file_v2 = ["version 2.0", "1", "2", "3", "4", "5" ]
+ let file_v2_patched = ["version 2.0", "1", "2", "3", "4", "patched" ]
+
+
+ let file_v2_conflict = ["version 2.0", "1", "2", "3", "4", "conflicting line" ]
" install v1
call writefile( file_v1, plugin_source_file, 1)
- let g:vim_script_manager['plugin_sources'][plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '1.0' , 'srcipt-type': 'plugin' }
+ let g:vim_script_manager['plugin_sources'][plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '1.0' , 'script-type': 'plugin' }
exec 'ActivateAddons '.plugin_name
" patch
- call writefile( file_v1, installDir.'/plugin/'.plugin_name.'.vim', 1)
-
- " update to v2
- call writefile( file_v2, plugin_source_file, 1)
- let g:vim_script_manager['plugin_sources'][plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '2.0' , 'srcipt-type': 'plugin' }
- exec 'UpdateAddons '.plugin_name
+ call writefile( file_v1_patched, installDir.'/plugin/'.plugin_name.'.vim', 1)
+
+ if a:case == "normal"
+
+ " update to v2
+ call writefile( file_v2, plugin_source_file, 1)
+ let g:vim_script_manager['plugin_sources'][plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '2.0' , 'script-type': 'plugin' }
+ exec 'UpdateAddons '.plugin_name
+
+ " verify that the patch is still present
+ if file_v2_patched != readfile( installDir.'/plugin/'.plugin_name.'.vim', 1)
+ echoe "test failed"
+ endif
+ elseif a:case == "conflict"
+ " manual test: diff file should be kept
+ " update to v2 conflict
+ call writefile( file_v2_conflict, plugin_source_file, 1)
+ let g:vim_script_manager['plugin_sources'][plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '2.0' , 'script-type': 'plugin' }
+ exec 'UpdateAddons '.plugin_name
+ else
+ throw "unkown case"
- if file_v2_patched != readfile( installDir.'/plugin/'.plugin_name.'.vim', 1)
- echoe "test failed"
endif
endfun
View
6 autoload/vcs_checkouts.vim
@@ -14,9 +14,11 @@ fun! vcs_checkouts#Update(dir)
\ {'d': directory, 'c': 'hg pull'},
\ {'d': directory, 'c': 'hg update'}
\ ])
- return !v:shell_error
+ if v:shell_error
+ throw "updating ".a:dir." falied. Got exit code: ".v:shell_error
+ endif
else
- echoe "Plugin ".fnamemodify(directory, ':t')." is not controlled by any known SCM system."
+ " not knowing how to update a repo is not a failure
return 0
endif
endf
Please sign in to comment.
Something went wrong with that request. Please try again.