Question

I am looking for library written for Node.js which I will be able to use to manage from the web application my local repositories created in Mercurial HG.

Anyone implemented something like that?

Was it helpful?

Solution

I've never heard of such a library — it has not been announced on our mailinglist. The stable API for Mercurial is the command line, so I suggest just launching hg directly and parsing the output. It's designed to be easy to screen-scrape and you can further customize it by using templates.

OTHER TIPS

I've created a module available on npm called node-hg for precisely this reason.

It's a wrapper around the Command Server that issues commands via stdin and parses output on stdout.

Here's an example of how it works:

var path = require("path");

var hg = require("hg");

// Clone into "../example-node-hg"
var destPath = path.resolve(path.join(process.cwd(), "..", "my-node-hg"));

hg.clone("http://bitbucket.org/jgable/node-hg", destPath, function(err, output) {
    if(err) {
        throw err;
    }

    output.forEach(function(line) {
        console.log(line.body);
    });

    // Add some files to the repo with fs.writeFile, omitted for brevity

    hg.add(destPath, ["someFile1.txt", "someFile2.txt"], function(err, output) {
        if(err) {
            throw err;
        }

        output.forEach(function(line) {
            console.log(line.body);
        });

        var commitOpts = {
            "-m": "Doing the needful"
        };

        // Commit our new files
        hg.commit(destPath, commitOpts, function(err, output) {
            if(err) {
                throw err;
            }

            output.forEach(function(line) {
                console.log(line.body);
            });
        });
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top