























just-git 是基于ts 实现的git 协议,支持虚拟文件系统client 以及支持嵌入式server 模式,与just-bash 集成起来是一个很你不错的玩法
import { Bash, InMemoryFs } from "just-bash";
import { createGit, findRepo } from "just-git";
// Origin repo on its own filesystem
const originFs = new InMemoryFs();
const setupBash = new Bash({
fs: originFs,
cwd: "/repo",
customCommands: [
createGit({ identity: { name: "Setup", email: "setup@example.com", locked: true } }),
],
});
await setupBash.exec("git init");
await setupBash.exec("echo 'hello' > README.md");
await setupBash.exec("git add . && git commit -m 'initial'");
const alice = new Bash({
fs: new InMemoryFs(),
cwd: "/repo",
customCommands: [
createGit({
identity: { name: "Alice", email: "alice@example.com", locked: true },
resolveRemote: () => findRepo(originFs, "/repo"),
}),
],
});
const bob = new Bash({
fs: new InMemoryFs(),
cwd: "/repo",
customCommands: [
createGit({
identity: { name: "Bob", email: "bob@example.com", locked: true },
resolveRemote: () => findRepo(originFs, "/repo"),
}),
],
});
console.log(await alice.exec("git clone /origin /repo"));
console.log(await bob.exec("git clone /origin /repo"));
just-git 与just-bash 集成起来还是挺有意思的,尤其在agent 应用中,可以研究下
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。