linux使用裸存储,linux – 如何提交裸存储库?

我正在为fuse(linux)编写一个git包装器来访问git存储库,比如普通文件和目录.

访问分支,标签和提交的文件夹和文件非常有效,但是当我提交文件时,我会遇到一种奇怪的行为.

我做以下的手风琴:

>从流中创建一个新的Blob(磁盘上的temporaney文件)

>创建一个新的TreeDefinition

>创建一个新树

>在ObjectDatabase中创建一个新提交

> update branch refs to new commit

之后,我更新分支引用,我只查看更新的文件,没有别的!

这里有代码

String referenceName = null; IEnumerable parentCommit = null; // Riposiziona il puntatore dello stream all'inizio openedHandle.Stream.Seek(0, SeekOrigin.Begin); // Crea il blob Blob blob = this.repository.ObjectDatabase.CreateBlob(openedHandle.Stream); // Acquisisce la path rimuovendo le prime due parti della path List pathParts = new List(openedHandle.Path.Split('/')); pathParts.RemoveRange(0, 3); // Inserisce il blob in un tree TreeDefinition treeDefinition = new TreeDefinition(); treeDefinition.Add(String.Join("/", pathParts), blob, Mode.NonExecutableFile); Tree tree = this.repository.ObjectDatabase.CreateTree(treeDefinition); // Inizializza l'autore ed il commiter Signature committer = new Signature("My Name", "abc@def.tld", DateTime.Now); Signature author = committer; // Acquisisce l'elenco dei commits switch (openedHandle.PathType) { case PathType.Branches: Branch branch = this.GetBranchByPath(openedHandle.Path); referenceName = branch.CanonicalName; parentCommit = branch.Commits; break; default: throw new Exception("Can update only branches"); } // Crea il commit Commit commit = this.repository.ObjectDatabase.CreateCommit( author, committer, (openedHandle.New ? String.Format("{0} created", openedHandle.Path) : String.Format("{0} updated", openedHandle.Path)) "\r\n", false, tree, parentCommit); // Aggiorna il riferimento del target this.repository.Refs.UpdateTarget(this.repository.Refs[referenceName], commit.Id);

解决方法:

TreeDefinition treeDefinition = new TreeDefinition()将创建一个空的TreeDefinition.因此,当您向其添加Blob时,最终创建的树将只包含一个条目.

TreeDefinition.From()静态帮助器方法可以在这里帮助您.它将允许从现有Commit或Tree的实际内容创建TreeDefinition.

标准流程是从Commit A构建TreeDefinition,更新TreeDefinition(通过添加/删除条目),从中创建一个Tree,最终生成一个新的Commit B,其父级将是Commit A.

你可以看看这个test,它显示了这种确切的用法(注意:测试实际上不会更新HEAD引用,使其指向新创建的提交,但是你的代码已经解决了这个问题).来源:https://www.icode9.com/content-3-427301.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值