[英]git-clone a bare repo with nodegit
I am cloning a worktree as a bare repo in nodegit
我正在将工作树克隆为nodegit
中的裸仓库
Git.Clone('/work/localrepo', '/git/newbare', {bare: 1})
This creates a bare repo just like这会创建一个裸仓库,就像
# in /git/newbare
> git clone --bare /work/localrepo
Note: newbare
has refs to all localrepo
branches in /git/newbare/refs/remote/origin
, but only localrepo's
active branch is cloned in the newbare's
local refs注意: newbare
对/git/newbare/refs/remote/origin
中的所有localrepo
分支都有引用,但只有localrepo's
活动分支被克隆到newbare's
本地引用中
That means that if localrepo
was on master when it was cloned, then newbare
is only tracking master这意味着如果localrepo
在克隆时在 master 上,那么newbare
只会跟踪 master
Now in git
I can track all branches on origin
with现在在git
origin
可以用
#in bare
> git fetch origin '+refs/*;refs/*'
>>> /git/newbare
From /work/localrepo
* [new branch] feature -> feature
Look at refspec if you want more info on the fetch here.如果您想在此处获取有关获取的更多信息,请查看refspec 。
I can't figure out how to setup tracking branches in a bare directory, for all branches on remote/origin
with nodegit
我不知道如何在裸目录中设置跟踪分支,使用nodegit
为remote/origin
上的所有分支
I wrote this and solved my problem我写了这个并解决了我的问题
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
}
}
If anyone finds this interesting, I can do my best to explain.如果有人觉得这很有趣,我可以尽力解释。 For now, here ya go.现在,这里是 go。 Have a good one guys!有一个好人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.