在命令行中,我可以做到以下几点:
$ touch foo
$ GIT_INDEX_FILE=/tmp/tmp.d95ehfhUOffoo/index git add -A
$ GIT_INDEX_FILE=/tmp/tmp.d95ehfhUOffoo/index git status -s
A foo
$ git status -s
?? foo
$ GIT_INDEX_FILE=/tmp/tmp.d95ehfhUOffoo/index git write-tree
b8f7b1e052b441b53a969014803516bb7e681760
$ git cat-file -p b8f7b1e052b441b53a969014803516bb7e681760
100644 blob ae3fdc2989ae00d75ec106feadb78ed9f98ba41a .gitignore
100644 blob 4e1e0d2f722485c7d284fb5cd7da855826e39b5a .rspec
100644 blob 4bc0f1cdd31d348ddc0e91365c5be5a40104fa17 Dockerfile
100644 blob 7dc939ea79c2bd70d8d32416f9da8aa568029b05 Gemfile
100644 blob 145bb24613da12ffef73d5db34e89e2ea8e265ad LICENSE.txt
100644 blob b8a804e12699a964dbeb97b7a632250192421294 README.md
100644 blob 809eb5616adcc0ebb78862099794489bd5b5b1a0 Rakefile
100644 blob a18114c31713746a33a2e70d9914d1ef3e781425 foo
040000 tree 3c8a789fc07c8f35fb96a7e77896cbbf2384e3d7 lib
040000 tree a5e7e5d6a85504f30912a8f65a498d17fe989c01 spec
100755 blob 0dd422b073bc1123cdf4979432822db773463537 test
需要注意的是,当我运行git status
使用存储库索引它表明FOO尚未上演。
所以,我怎么能做到这一点与git2go? 一种尝试至今:
func Worktree() (string, error) {
› repo, err := git.OpenRepository(".")
› if err != nil {
› › return "", err
› }
› index, err := git.NewIndex()
› if err != nil {
› › return "", err
› }
› err = index.AddAll([]string{"."}, git.IndexAddDefault, nil)
› if err != nil {
› › return "", err
› }
› treeOid, err := index.WriteTreeTo(repo)
› if err != nil {
› › return "", err
› }
› return treeOid.String(), nil
}
结果是:
Error: Could not add paths to index. Index is not backed up by an existing repository.
如何用仓库存储指数相关联的?
似乎有一些libgit功能,如git_index_open
和git_index_read
还没有在git2go得到落实。 我已经扫描了大量的代码,并阅读了大量的libgit2的API。
一些指针(不,不是*指针)将是巨大的。