简体   繁体   中英

Programmatically setting svn:externals on a remote repository

I am working on a web-based tool to allow project managers to set up new subversion repositories and corresponding Trac instances.

As part of this tool, I'd like to be able to automatically add some specific dependencies to the new repository, like setting some externals for other libraries.

I'm aware that svn propset doesn't work on remote repositories, however svn propedit does.

My question is this - how can I issue a svn propedit and set the svn:externals property in one command on the command line?

Put another way, propedit requires an editor, is there some kind of "fake" editor I can use that just accepts command line args (which I can use with svn's --editor-cmd option)? That way, I can build a CLI command programmatically and issue it with a system call.

I am not worried about overwriting existing properties since this will only ever work on a brand new repository that has been created a few CPU cycles earlier.

You can write an executable script that serves as your prop-editor. It will get as its first argument ( $1 on unix-like systems) a temporary file name with the current value of the property being edited. You modify the contents of the file in the script - and that's the new value of the property. You pass your script as svn propedit <pro-name> <item> --editor-cmd <my-custom-editor> .

A more specific answer would be to use a simple command-line "editor" that uses the echo command to set the new text of the property. On unix, this is pretty simple:

svn propedit svn:externals \
--editor-cmd "echo '<property_value>' >" \
<target> -m "<commit_message>"

This can even handle multi-line property values (like multiple externals), since unix is quite happy accepting new-lines in quoted strings:

svn propedit svn:externals \
--editor-cmd "echo 'first property value
another property value
yet another one' >" \
<target> -m "<commit_message>"

On windows the simple case looks like this, since its echo doesn't want quotes:

svn propedit svn:externals ^
--editor-cmd "echo <property_value> >" ^
<target> -m "<commit_message>"

But the multi-line version is more tricky:

svn propedit svn:externals ^
--editor-cmd "(echo first property value & echo another property value & echo yet another one) >" ^
<target> -m "<commit_message>"

Building that last one is actually pretty simple in most scripting languages, by joining the lines of the property value with a " & echo " instead of a " \\n ", and then wrapping that in parentheses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM