Skip to content

Commit

Permalink
WIP recursive submodules
Browse files Browse the repository at this point in the history
Entering submodules works, but other commands fail, so this is not good enough yet.
  • Loading branch information
stefanhaller committed Feb 5, 2024
1 parent 49df908 commit 6456eb1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
21 changes: 16 additions & 5 deletions pkg/commands/git_commands/submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func NewSubmoduleCommands(gitCommon *GitCommon) *SubmoduleCommands {
}
}

func (self *SubmoduleCommands) GetConfigs() ([]*models.SubmoduleConfig, error) {
file, err := os.Open(".gitmodules")
func (self *SubmoduleCommands) GetConfigs(parentName string, parentPath string) ([]*models.SubmoduleConfig, error) {
file, err := os.Open(filepath.Join(parentPath, ".gitmodules"))
if err != nil {
if os.IsNotExist(err) {
return nil, nil
Expand Down Expand Up @@ -55,17 +55,28 @@ func (self *SubmoduleCommands) GetConfigs() ([]*models.SubmoduleConfig, error) {
line := scanner.Text()

if name, ok := firstMatch(line, `\[submodule "(.*)"\]`); ok {
if parentName != "" {
name = parentName + "/" + name
}
configs = append(configs, &models.SubmoduleConfig{Name: name})
continue
}

if len(configs) > 0 {
lastConfig := configs[len(configs)-1]
lastConfigIdx := len(configs) - 1

if path, ok := firstMatch(line, `\s*path\s*=\s*(.*)\s*`); ok {
lastConfig.Path = path
if parentPath != "" {
configs[lastConfigIdx].Path = parentPath + "/" + path
} else {
configs[lastConfigIdx].Path = path
}
nestedConfigs, err := self.GetConfigs(configs[lastConfigIdx].Name, configs[lastConfigIdx].Path)
if err == nil {
configs = append(configs, nestedConfigs...)
}
} else if url, ok := firstMatch(line, `\s*url\s*=\s*(.*)\s*`); ok {
lastConfig.Url = url
configs[lastConfigIdx].Url = url
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/working_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (self *WorkingTreeCommands) RemoveUntrackedFiles() error {

// ResetAndClean removes all unstaged changes and removes all untracked files
func (self *WorkingTreeCommands) ResetAndClean() error {
submoduleConfigs, err := self.submodule.GetConfigs()
submoduleConfigs, err := self.submodule.GetConfigs("", "")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/helpers/refresh_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (self *RefreshHelper) refreshTags() error {
}

func (self *RefreshHelper) refreshStateSubmoduleConfigs() error {
configs, err := self.c.Git().Submodule.GetConfigs()
configs, err := self.c.Git().Submodule.GetConfigs("", "")
if err != nil {
return err
}
Expand Down

0 comments on commit 6456eb1

Please sign in to comment.