Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial HG library for Node.js for local repositories

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?

like image 585
mrzepinski Avatar asked Jan 10 '12 10:01

mrzepinski


2 Answers

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.

like image 164
Martin Geisler Avatar answered Nov 09 '22 11:11

Martin Geisler


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);
            });
        });
    });
});
like image 7
Jacob Avatar answered Nov 09 '22 10:11

Jacob