Javascript SVN wrapper
Asked Answered
D

4

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.

Dawkins answered 14/12, 2011 at 13:23 Comment(4)
Which type of JavaScript do you want to use? JavaScript in a Browser oder eg. node.js?Firebrand
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).Dawkins
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?Ity
@LittleJawa No unfortunately, I remember giving it a try but I feel it needs a lot of development and perseveranceDawkins
F
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/

Firebrand answered 22/12, 2011 at 13:6 Comment(0)
I
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

Ipsambul answered 22/7, 2014 at 8:31 Comment(1)
Please note that this code is compatible with SVN version 1.7+Exponible
I
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.

Inga answered 2/4, 2019 at 22:13 Comment(2)
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!Hoodwink
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.Inga
V
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.

Vincennes answered 25/12, 2011 at 15:2 Comment(1)
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.Ity

© 2022 - 2024 — McMap. All rights reserved.