23

Is there any Javascript library that enables to read and commit files to a Subversion server?

The server could be using the svn:// protocol or the http:// (dav_svn) protocol. If one is more convenient that's ok, though a library that could handle both type is better.

I would like to avoid having to create a local working copy of the repository (is that even possible to checkout a repository in Javascript :p...).

Anyone sees a solution? I've been looking around but didn't find anything.

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
  • Which type of JavaScript do you want to use? JavaScript in a Browser oder eg. node.js? – TimWolla Dec 21 '11 at 20:01
  • Javascript in a browser. I'd like to do some kind of quick view/edit for a SVN repository (and without relying on a PHP/Java server for doing the job). – Matthieu Napoli Dec 21 '11 at 22:39
  • I'm actually having the same question, but I wanted to do DIFF this way - providing a way to show changes for a given revision without going through server-based commands. Matthieu - did you finally get it to work? Are you able to do DIFFs also? – Little Jawa Jul 16 '12 at 08:21
  • @LittleJawa No unfortunately, I remember giving it a try but I feel it needs a lot of development and perseverance – Matthieu Napoli Jul 16 '12 at 15:24

4 Answers4

10

I don't know a really ready solution, but maybe this: https://github.com/sara-nl/js-webdav-client could help. Thats a WebDAV-Client written in JS and with this it should be possible do checkout SVN as well.

Otherwise you will have to implement WebDAV by yourself. You can find the specification here: http://webdav.org/specs/

TimWolla
  • 31,849
  • 8
  • 63
  • 96
4

The https://github.com/sara-nl/js-webdav-client didn't work for me

I used jQuery to read an XML file:

var URL = window.location.href;
var baseURL = URL.substring(0, URL.lastIndexOf('/'));
$.ajax({
    type: "OPTIONS",
    url: baseURL,
    contentType: "text/xml", //for other files look up the api link below
    headers: {Depth: "0"},
    data: '<?xml version="1.0" encoding="utf-8" ?><D:options xmlns:D="DAV:"><D:activity-collection-set></D:activity-collection-set></D:options>',
    success: function(data1, status, jqxhr){
        latestRev = jqxhr.getResponseHeader('SVN-Youngest-Rev');
        $.ajax({
            type: "PROPFIND",
            url: baseURL + '/!svn/rvr/' + latestRev,
            contentType: "text/xml",
            headers: {Depth: "0"},
            data: '<?xml version="1.0" encoding="utf-8" ?><propfind xmlns="DAV:"><prop><resourcetype xmlns="DAV:"/></prop></propfind>',
            success: function(data2, status, jqxhr){
                $.ajax({
                    type: "OPTIONS",
                    url: baseURL,
                    contentType: "text/xml",
                    headers: {Depth: "0"},
                    data: '<?xml version="1.0" encoding="utf-8" ?><D:options xmlns:D="DAV:"><D:activity-collection-set></D:activity-collection-set></D:options>',
                    success: function(data3, status, jqxhr){
                        $.ajax({
                            type: "REPORT",
                            url: baseURL + "/!svn/me",
                            contentType: "text/xml",
                            data: '<S:update-report xmlns:S="svn:"><S:include-props>yes</S:include-props><S:src-path>/svn/check</S:src-path><S:target-revision>' + latestRev + '</S:target-revision><S:depth>unknown</S:depth><S:entry depth="infinity" rev="' + latestRev + '"></S:entry></S:update-report>',
                            success: function(data4,status,jqxhr){
                                svnSpecs = data4;
                                $.ajax({
                                    type: "GET",
                                    url: '/svn/check/!svn/rvr/' + latestRev + '/KickOff.xml',
                                    converters: {"text xml": function(obj) {
                                        hashBase = calcMD5(obj);
                                        return obj;
                                    }},
                                    cache: false,
                                    async: false,
                                    success: function(data5, status, jqxhr){
                                        hashdata5 = calcMD5(data5);
                                        xmlString = $($.parseXML(data5));
                                        drawTable(xmlString);
                                    },
                                });
                            },
                        });
                    },
                });
            },
        });
    },
});

If you want to import other files than xml look it up here: http://api.jquery.com/jQuery.ajax/

In data4/svnSpecs you can find every keyword you used within your xml - just do the same as with the xmlString

With a = xmlString.find("Member"); you get an array with every object named member of the xml if you do a[0].textContent = "Harry"; you set the content of the first object within your xmlString to Harry --> you can just do an drawTable() afterwards to refresh your table

EDIT: Within the drawTable() methode you have to do the a.find(""), var list = []; and list.push("html text for a table") and an $("#membertable").html(list); to write everthing in the existing table "membertable"

The hashBase is important for commiting. i'm not done with the commit but nearly. current code and process is over here: how to do SVN http-request checkin/commit within html

Community
  • 1
  • 1
manti
  • 241
  • 1
  • 2
  • 9
1

I have the same question, and I've just found svnjs which seems to be exactly this; I haven't tried it myself but it claims to support add, rm, propset, propdel, mkdir and commit. No move, copy, lock or unlock.

It also looks like it was last touched four years ago, for what it's worth.

Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
David Given
  • 13,277
  • 9
  • 76
  • 123
  • 1
    Hi David, did you get `svnjs` to work? I have tried both versions available on the repository, and none of them let me add or modify files... Thanks in advance! – Eric Roy Jul 06 '22 at 14:46
  • 1
    No, I never did, sorry. AFAICT github's cross-site-scripting safeguards mean that you can't make XMLHTTP requests to them from another site. – David Given Jul 06 '22 at 19:08
0

You can write your own Svn commands in a set of command files and then run them inside your script.

/* Create WSH Shell */
oShell = WScript.CreateObject( "WScript.Shell" );

/* Launch svn.exe with other orguments */
oShell.Run( "svn.exe svn://192.168.40.41  Param1 param2" );

/* Let the user know that we are done           */
WScript.Echo( "Done" );

But as you know, this is not safe.

TonySalimi
  • 8,257
  • 4
  • 33
  • 62
  • In addition to not being safe, it also have two drawbacks: 1) you will have trouble to make it run on all OSes (you have to adapt the commandline for each of supported OS, which is a pain), AND 2) it requires all users to have a commandline SVN client installed and available in the PATH, which will not always be the case - you'll not always look at this webpage from your dev machine, I guess. – Little Jawa Jul 16 '12 at 08:18