我正在写保险丝(Linux)的git包装来访问git存储库,如普通文件和目录。如何提交到裸仓库?
访问文件夹和文件的分支机构,标签和提交工作得很好,但我犯了一个奇怪的行为,当我提交文件。
我做了以下styff:
- 创建一个流的新斑块(磁盘上的temporaney文件)
- 创建一个新的TreeDefinition
- 创建一个新的树
- 创建ObjectDatabase中的新提交
- 更新分支引用新提交
之后,我更新分支裁判,我只查看更新的文件,没有别的!
在这里有代码
String referenceName = null;
IEnumerable<Commit> 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<string> pathParts = new List<string>(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", "[email protected]", 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.From帮助器的方法,谢谢!现在,我必须了解为什么单熔丝在我尝试创建文件时出错!谢谢 –