aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal/dotgit/dotgit.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-22 13:47:42 +0200
committerGitHub <noreply@github.com>2017-05-22 13:47:42 +0200
commit2ff77a8d93529cefdca922dbed89d4b1cd0ee8e5 (patch)
treeaa27da9eb77c76b9d9912bb94d92c59823446692 /storage/filesystem/internal/dotgit/dotgit.go
parentd98ebb5e42cd07007010f6d10db11a792c58206e (diff)
parent8fbb9914931704257581f5a7474ee3f2abc3780f (diff)
downloadgo-git-2ff77a8d93529cefdca922dbed89d4b1cd0ee8e5.tar.gz
Merge pull request #398 from mcuadros/init-fix
storage: filesystem, initialize the default folder scaffolding
Diffstat (limited to 'storage/filesystem/internal/dotgit/dotgit.go')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index fdfcea7..f9f4d79 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -66,6 +66,33 @@ func New(fs billy.Filesystem) *DotGit {
return &DotGit{fs: fs}
}
+// Initialize creates all the folder scaffolding.
+func (d *DotGit) Initialize() error {
+ mustExists := []string{
+ d.fs.Join("objects", "info"),
+ d.fs.Join("objects", "pack"),
+ d.fs.Join("refs", "heads"),
+ d.fs.Join("refs", "tags"),
+ }
+
+ for _, path := range mustExists {
+ _, err := d.fs.Stat(path)
+ if err == nil {
+ continue
+ }
+
+ if !os.IsNotExist(err) {
+ return err
+ }
+
+ if err := d.fs.MkdirAll(path, os.ModeDir|os.ModePerm); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
// ConfigWriter returns a file pointer for write to the config file
func (d *DotGit) ConfigWriter() (billy.File, error) {
return d.fs.Create(configPath)