diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-10-01 07:55:28 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-10-02 08:09:42 +1000 |
commit | f3be2b3e68a49742ee88053a1d029926bc0d1819 (patch) | |
tree | d25592bbb8b82cea84fa97f3b8e3d5fb6267c3c9 /pkg/commands/submodules.go | |
parent | 988176e07374f67885fa4e3dd498a5e8fc1cc06c (diff) |
improved command for deleting a submodule
Diffstat (limited to 'pkg/commands/submodules.go')
-rw-r--r-- | pkg/commands/submodules.go | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/pkg/commands/submodules.go b/pkg/commands/submodules.go index 41ea3bbbf..06abd9bb6 100644 --- a/pkg/commands/submodules.go +++ b/pkg/commands/submodules.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "regexp" + "strings" "github.com/jesseduffield/lazygit/pkg/commands/models" ) @@ -84,10 +85,22 @@ func (c *GitCommand) SubmoduleDelete(submodule *models.SubmoduleConfig) error { // based on https://gist.github.com/myusuf3/7f645819ded92bda6677 if err := c.OSCommand.RunCommand("git submodule deinit --force %s", submodule.Path); err != nil { - return err + if strings.Contains(err.Error(), "did not match any file(s) known to git") { + if err := c.OSCommand.RunCommand("git config --file .gitmodules --remove-section submodule.%s", submodule.Name); err != nil { + return err + } + + if err := c.OSCommand.RunCommand("git config --remove-section submodule.%s", submodule.Name); err != nil { + return err + } + + // if there's an error here about it not existing then we'll just continue to do `git rm` + } else { + return err + } } - if err := c.OSCommand.RunCommand("git rm --force %s", submodule.Path); err != nil { + if err := c.OSCommand.RunCommand("git rm --force -r %s", submodule.Path); err != nil { return err } @@ -109,6 +122,6 @@ func (c *GitCommand) SubmoduleUpdateUrl(name string, path string, newUrl string) return err } - return c.OSCommand.RunCommand("git submodule sync -- %s", path) + return c.OSCommand.RunCommand("git submodule sync %s", path) } |