aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-02-14 19:26:32 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-02-15 09:30:05 +0100
commitd6a6decd1be0515faf36256ce06c58c7d662bbd0 (patch)
treeb91c4f618470c7cf1ef9547b9146d08e30df6204 /worktree.go
parent09110d8e6d1ddb6f6a22867dcedeebd8f2262780 (diff)
downloadgo-git-d6a6decd1be0515faf36256ce06c58c7d662bbd0.tar.gz
submodule update implementation
Diffstat (limited to 'worktree.go')
-rw-r--r--worktree.go45
1 files changed, 19 insertions, 26 deletions
diff --git a/worktree.go b/worktree.go
index 2a5b58a..2514a0c 100644
--- a/worktree.go
+++ b/worktree.go
@@ -212,17 +212,18 @@ const gitmodulesFile = ".gitmodules"
// Submodule returns the submodule with the given name
func (w *Worktree) Submodule(name string) (*Submodule, error) {
- m, err := w.readGitmodulesFile()
- if err != nil || m == nil {
+ l, err := w.Submodules()
+ if err != nil {
return nil, err
}
- c, ok := m.Submodules[name]
- if !ok {
- return nil, ErrSubmoduleNotFound
+ for _, m := range l {
+ if m.Config().Name == name {
+ return m, nil
+ }
}
- return w.newSubmodule(c)
+ return nil, ErrSubmoduleNotFound
}
// Submodules returns all the available submodules
@@ -233,34 +234,26 @@ func (w *Worktree) Submodules() (Submodules, error) {
return l, err
}
- for _, c := range m.Submodules {
- s, err := w.newSubmodule(c)
- if err != nil {
- return nil, err
- }
-
- l = append(l, s)
+ c, err := w.r.Config()
+ for _, s := range m.Submodules {
+ l = append(l, w.newSubmodule(s, c.Submodules[s.Name]))
}
return l, nil
}
-func (w *Worktree) newSubmodule(m *config.Submodule) (*Submodule, error) {
- s, err := w.r.Storer.Module(m.Name)
- if err != nil {
- return nil, err
- }
+func (w *Worktree) newSubmodule(fromModules, fromConfig *config.Submodule) *Submodule {
+ m := &Submodule{w: w}
+ m.initialized = fromConfig != nil
- r, err := Init(s, w.fs.Dir(m.Path))
- if err != nil {
- return nil, err
+ if !m.initialized {
+ m.c = fromModules
+ return m
}
- return &Submodule{
- m: m,
- w: w,
- r: r,
- }, nil
+ m.c = fromConfig
+ m.c.Path = fromModules.Path
+ return m
}
func (w *Worktree) readGitmodulesFile() (*config.Modules, error) {