summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-09-29 08:47:14 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-09-29 18:21:59 +1000
commitb882ac9e066bce21c18d73122005f06acfda3bfa (patch)
tree85835667e83a585e381b2840b7de19031bb967f8 /pkg/commands
parentb8da166ab1c66671d681bc2454b911993716de58 (diff)
support nuking all submodules
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git.go17
-rw-r--r--pkg/commands/submodules.go11
2 files changed, 28 insertions, 0 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 90fbc9890..c2c617b68 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -375,6 +375,23 @@ func includesInt(list []int, a int) bool {
// ResetAndClean removes all unstaged changes and removes all untracked files
func (c *GitCommand) ResetAndClean() error {
+ submoduleConfigs, err := c.GetSubmoduleConfigs()
+ if err != nil {
+ return err
+ }
+
+ if len(submoduleConfigs) > 0 {
+ for _, config := range submoduleConfigs {
+ if err := c.SubmoduleStash(config); err != nil {
+ return err
+ }
+ }
+
+ if err := c.SubmoduleUpdateAll(); err != nil {
+ return err
+ }
+ }
+
if err := c.ResetHard("HEAD"); err != nil {
return err
}
diff --git a/pkg/commands/submodules.go b/pkg/commands/submodules.go
index ad130544c..7debb7d91 100644
--- a/pkg/commands/submodules.go
+++ b/pkg/commands/submodules.go
@@ -58,9 +58,20 @@ func (c *GitCommand) GetSubmoduleConfigs() ([]*SubmoduleConfig, error) {
}
func (c *GitCommand) SubmoduleStash(config *SubmoduleConfig) error {
+ // if the path does not exist then it hasn't yet been initialized so we'll swallow the error
+ // because the intention here is to have no dirty worktree state
+ if _, err := os.Stat(config.Path); os.IsNotExist(err) {
+ c.Log.Infof("submodule path %s does not exist, returning", config.Path)
+ return nil
+ }
+
return c.OSCommand.RunCommand("git -C %s stash --include-untracked", config.Path)
}
func (c *GitCommand) SubmoduleReset(config *SubmoduleConfig) error {
return c.OSCommand.RunCommand("git submodule update --force %s", config.Name)
}
+
+func (c *GitCommand) SubmoduleUpdateAll() error {
+ return c.OSCommand.RunCommand("git submodule update --force")
+}