문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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);
            });
        });
    });
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top