用于本地存储库的Node.js的Mercurial HG库

mrz*_*ski 6 mercurial node.js npm

我正在寻找为Node.js编写的库,我将能够使用它来管理我在Mercurial HG中创建的本地存储库的Web应用程序.

有人实现了类似的东西?

Mar*_*ler 7

我从未听说过这样的图书馆 - 我们的邮件列表尚未公布.Mercurial的稳定API是命令行,所以我建议直接启动hg并解析输出.它的设计易于屏幕刮擦,您可以使用模板进一步自定义它.


Jac*_*cob 6

我已经在npm上创建了一个名为node-hg的模块,正是出于这个原因.

它是Command Server的一个包装器,它通过命令发出命令stdin并解析输出stdout.

这是一个如何工作的例子:

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);
            });
        });
    });
});
Run Code Online (Sandbox Code Playgroud)