-
Notifications
You must be signed in to change notification settings - Fork 534
Submodules init and update #270
Changes from 2 commits
498dbf7
b3b6e51
b18d649
c551c29
940a16c
f8b5557
65351f8
7e990a8
09110d8
d6a6dec
ed288b3
790fbda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
// It is highly extensible, we have been following the open/close principle in | ||
// its design to facilitate extensions, mainly focusing the efforts on the | ||
// persistence of the objects. | ||
package git | ||
package git // import "srcd.works/go-git.v4" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ type CloneOptions struct { | |
SingleBranch bool | ||
// Limit fetching to the specified number of commits | ||
Depth int | ||
// RecursiveSubmodules after the clone is created, initialize all submodules | ||
// within, using their default settings. This option is ignored if the | ||
// cloned repository does not have a worktree | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. end the paragraph with a full stop. |
||
RecursiveSubmodules bool | ||
// Progress is where the human readable information sent by the server is | ||
// stored, if nil nothing is stored and the capability (if supported) | ||
// no-progress, is sent to the server to avoid send this information | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"srcd.works/go-git.v4/plumbing" | ||
"srcd.works/go-git.v4/plumbing/object" | ||
"srcd.works/go-git.v4/plumbing/storer" | ||
"srcd.works/go-git.v4/storage" | ||
"srcd.works/go-git.v4/storage/filesystem" | ||
|
||
"srcd.works/go-billy.v1" | ||
|
@@ -29,7 +30,7 @@ var ( | |
|
||
// Repository represents a git repository | ||
type Repository struct { | ||
Storer Storer | ||
Storer storage.Storer | ||
|
||
r map[string]*Remote | ||
wt billy.Filesystem | ||
|
@@ -38,7 +39,7 @@ type Repository struct { | |
// Init creates an empty git repository, based on the given Storer and worktree. | ||
// The worktree Filesystem is optional, if nil a bare repository is created. If | ||
// the given storer is not empty ErrRepositoryAlreadyExists is returned | ||
func Init(s Storer, worktree billy.Filesystem) (*Repository, error) { | ||
func Init(s storage.Storer, worktree billy.Filesystem) (*Repository, error) { | ||
r := newRepository(s, worktree) | ||
_, err := r.Reference(plumbing.HEAD, false) | ||
switch err { | ||
|
@@ -66,7 +67,7 @@ func Init(s Storer, worktree billy.Filesystem) (*Repository, error) { | |
// The worktree can be nil when the repository being opened is bare, if the | ||
// repository is a normal one (not bare) and worktree is nil the err | ||
// ErrWorktreeNotProvided is returned | ||
func Open(s Storer, worktree billy.Filesystem) (*Repository, error) { | ||
func Open(s storage.Storer, worktree billy.Filesystem) (*Repository, error) { | ||
_, err := s.Reference(plumbing.HEAD) | ||
if err == plumbing.ErrReferenceNotFound { | ||
return nil, ErrRepositoryNotExists | ||
|
@@ -91,7 +92,7 @@ func Open(s Storer, worktree billy.Filesystem) (*Repository, error) { | |
// Clone a repository into the given Storer and worktree Filesystem with the | ||
// given options, if worktree is nil a bare repository is created. If the given | ||
// storer is not empty ErrRepositoryAlreadyExists is returned | ||
func Clone(s Storer, worktree billy.Filesystem, o *CloneOptions) (*Repository, error) { | ||
func Clone(s storage.Storer, worktree billy.Filesystem, o *CloneOptions) (*Repository, error) { | ||
r, err := Init(s, worktree) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -159,7 +160,7 @@ func PlainClone(path string, isBare bool, o *CloneOptions) (*Repository, error) | |
return r, r.clone(o) | ||
} | ||
|
||
func newRepository(s Storer, worktree billy.Filesystem) *Repository { | ||
func newRepository(s storage.Storer, worktree billy.Filesystem) *Repository { | ||
return &Repository{ | ||
Storer: s, | ||
wt: worktree, | ||
|
@@ -247,12 +248,6 @@ func (r *Repository) clone(o *CloneOptions) error { | |
return err | ||
} | ||
|
||
// marks the repository as bare in the config, until we have Worktree, all | ||
// the repository are bare | ||
if err := r.setIsBare(true); err != nil { | ||
return err | ||
} | ||
|
||
c := &config.RemoteConfig{ | ||
Name: o.RemoteName, | ||
URL: o.URL, | ||
|
@@ -270,11 +265,13 @@ func (r *Repository) clone(o *CloneOptions) error { | |
Progress: o.Progress, | ||
}) | ||
if err != nil { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove empty line. |
||
return err | ||
} | ||
|
||
head, err := storer.ResolveReference(remoteRefs, o.ReferenceName) | ||
if err != nil { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove empty line. |
||
return err | ||
} | ||
|
||
|
@@ -283,12 +280,33 @@ func (r *Repository) clone(o *CloneOptions) error { | |
} | ||
|
||
if err := r.updateWorktree(); err != nil { | ||
fmt.Println("q", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover? |
||
return err | ||
} | ||
|
||
if o.RecursiveSubmodules && r.wt != nil { | ||
if err := r.initSubmodules(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return r.updateRemoteConfig(remote, o, c, head) | ||
} | ||
|
||
func (r *Repository) initSubmodules() error { | ||
w, err := r.Worktree() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s, err := w.Submodules() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return s.Init() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have a recursive flag, so the init can be done recursively? |
||
} | ||
|
||
func (r *Repository) cloneRefSpec(o *CloneOptions, | ||
c *config.RemoteConfig) []config.RefSpec { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,10 @@ const ( | |
configPath = "config" | ||
indexPath = "index" | ||
shallowPath = "shallow" | ||
|
||
objectsPath = "objects" | ||
packPath = "pack" | ||
refsPath = "refs" | ||
modulePath = "module" | ||
objectsPath = "objects" | ||
packPath = "pack" | ||
refsPath = "refs" | ||
|
||
packExt = ".pack" | ||
idxExt = ".idx" | ||
|
@@ -390,6 +390,11 @@ func (d *DotGit) readReferenceFile(refsPath, refFile string) (ref *plumbing.Refe | |
return plumbing.NewReferenceFromStrings(refFile, line), nil | ||
} | ||
|
||
// Module return a billy.Filesystem poiting to the module folder | ||
func (d *DotGit) Module(name string) billy.Filesystem { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return d.fs.Dir(d.fs.Join(modulePath, name)) | ||
} | ||
|
||
func isHex(s string) bool { | ||
for _, b := range []byte(s) { | ||
if isNum(b) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package filesystem | ||
|
||
import ( | ||
"srcd.works/go-git.v4/storage" | ||
"srcd.works/go-git.v4/storage/filesystem/internal/dotgit" | ||
) | ||
|
||
type ModuleStorage struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this type?, can we just make dotgit implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the pattern we are using. I prefer keep dotgit isolate |
||
dir *dotgit.DotGit | ||
} | ||
|
||
func (s *ModuleStorage) Module(name string) (storage.Storer, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests and comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is already covered by the tests. And the documentation is on the interface as in the other methods |
||
return NewStorage(s.dir.Module(name)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"srcd.works/go-git.v4/plumbing" | ||
"srcd.works/go-git.v4/plumbing/format/index" | ||
"srcd.works/go-git.v4/plumbing/storer" | ||
"srcd.works/go-git.v4/storage" | ||
) | ||
|
||
var ErrUnsupportedObjectType = fmt.Errorf("unsupported object type") | ||
|
@@ -22,6 +23,7 @@ type Storage struct { | |
ShallowStorage | ||
IndexStorage | ||
ReferenceStorage | ||
ModuleStorage | ||
} | ||
|
||
// NewStorage returns a new Storage base on memory | ||
|
@@ -37,6 +39,7 @@ func NewStorage() *Storage { | |
Blobs: make(map[plumbing.Hash]plumbing.EncodedObject, 0), | ||
Tags: make(map[plumbing.Hash]plumbing.EncodedObject, 0), | ||
}, | ||
ModuleStorage: make(ModuleStorage, 0), | ||
} | ||
} | ||
|
||
|
@@ -227,3 +230,13 @@ func (s *ShallowStorage) SetShallow(commits []plumbing.Hash) error { | |
func (s ShallowStorage) Shallow() ([]plumbing.Hash, error) { | ||
return s, nil | ||
} | ||
|
||
type ModuleStorage map[string]*Storage | ||
|
||
func (s ModuleStorage) Module(name string) (storage.Storer, error) { | ||
if _, ok := s[name]; !ok { | ||
s[name] = NewStorage() | ||
} | ||
|
||
return s[name], nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't look up twice in the map, use a variable to store the results of the first lookup. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package storage | ||
|
||
import ( | ||
"srcd.works/go-git.v4/config" | ||
"srcd.works/go-git.v4/plumbing/storer" | ||
) | ||
|
||
// Storer is a generic storage of objects, references and any information | ||
// related to a particular repository. The package srcd.works/go-git.v4/storage | ||
// contains two implementation a filesystem base implementation (such as `.git`) | ||
// and a memory implementations being ephemeral | ||
type Storer interface { | ||
storer.EncodedObjectStorer | ||
storer.ReferenceStorer | ||
storer.ShallowStorer | ||
storer.IndexStorer | ||
config.ConfigStorer | ||
ModuleStorer | ||
} | ||
|
||
type ModuleStorer interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be explained, What if the module doesn't exists? |
||
Module(name string) (Storer, error) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change name to imperative:
RecurseSubmodules
.