mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-02 09:21:40 +02:00
support nuking all submodules
This commit is contained in:
parent
b8da166ab1
commit
b882ac9e06
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user