src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.91k stars 542 forks source link

How can I implement a filesystem-based repo? #1198

Closed easonyq closed 5 years ago

easonyq commented 5 years ago

I was trying to use go-git for building a filesystem-based git implementation. But I could not find much info from GoDoc nor examples in the project. Things got worse when I went to go-billy package... ( I could only find one example called 'remotes' which deals with git.Init, but memory.NewStorage doesnot need params unfortunately )

From the GoDoc and this issue [#704] (maybe out of date) , I should init a repo by ( I guess... )

fs := osfs.New("path/to/my/repo")
storage, err := filesystem.NewStorage(fs, ??) // What should I pass as a cache.Object ?
repo, err := git.Init(storage, ??) // What should I pass as a worktree
// I also see `repo, err := git.PlainInit("path/to/my/repo", false)` from doc. Will this work?

// I want to commit something to this repo later. So this must not be bare.

Here's my questions:

  1. According to the doc, the second param of filesystem.NewStorage cannot be nil if I want a normal repo (not a bare one because I want to commit something later). So what should I pass?
  2. I can barely find some instructions from go-billy but git.Init need it. Am I using osfs.New currectly?
  3. Similar to Question 1, I do want a normal repo and the second param of git.Init cannot be nil or omitted. What should I use?
  4. I saw git.PlainInit with pretty simple params. Can I use this?

Maybe an example will be the best. I really appreicate your great work at this tool!

easonyq commented 5 years ago

I've just tried and

git.PlainInit("path/to/my/repo", false)

works!