[英]git-clone a bare repo with nodegit
我正在将工作树克隆为nodegit
中的裸仓库
Git.Clone('/work/localrepo', '/git/newbare', {bare: 1})
这会创建一个裸仓库,就像
# in /git/newbare
> git clone --bare /work/localrepo
注意: newbare
对/git/newbare/refs/remote/origin
中的所有localrepo
分支都有引用,但只有localrepo's
活动分支被克隆到newbare's
本地引用中
这意味着如果localrepo
在克隆时在 master 上,那么newbare
只会跟踪 master
现在在git
origin
可以用
#in bare
> git fetch origin '+refs/*;refs/*'
>>> /git/newbare
From /work/localrepo
* [new branch] feature -> feature
如果您想在此处获取有关获取的更多信息,请查看refspec 。
我不知道如何在裸目录中设置跟踪分支,使用nodegit
为remote/origin
上的所有分支
我写了这个并解决了我的问题
module.exports = {
async trackRemoteBranch(repo, remote_name, branch_name) {
let remote_path = path.join(remote_name, branch_name)
let branch_commit = await repo.getBranchCommit(remote_path)
let branch_ref = await repo.createBranch(branch_name, branch_commit)
await Branch.setUpstream(branch_ref, remote_path)
return true
},
/**
* refs/remotes/origin/master =>
* {
* remote_name: origin,
* branch_name: master,
* }
* very rough solution
*/
async cleaveRef(remote_ref) {
let parts = remote_ref.split('/')
let [remote_name, branch_name] = parts.slice(parts.length - 2)
return {
remote_name,
branch_name
}
},
async getRemoteReferences(repo) {
let refs = await repo.getReferences()
let remote_refs = refs
.filter((ref) => ref.isRemote())
.map(ref => ref.name())
return remote_refs
},
async trackAll(repo) {
(await this.getRemoteReferences(repo))
.map(ref => this.cleaveRef(ref))
.forEach(async ({remote_name, branch_name}) => {
try {
await this.trackRemoteBranch(config, remote_name, branch_name)
} catch (err) {}
})
return true
}
}
如果有人觉得这很有趣,我可以尽力解释。 现在,这里是 go。 有一个好人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.