1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-28 16:02:01 +03:00

move file and submodule

This commit is contained in:
Jesse Duffield
2020-09-29 18:45:00 +10:00
parent eda4619a4f
commit 8d2af5cc61
11 changed files with 69 additions and 66 deletions

View File

@ -4,6 +4,8 @@ import (
"bufio"
"os"
"regexp"
"github.com/jesseduffield/lazygit/pkg/models"
)
// .gitmodules looks like this:
@ -11,7 +13,7 @@ import (
// path = blah/mysubmodule
// url = git@github.com:subbo.git
func (c *GitCommand) GetSubmoduleConfigs() ([]*SubmoduleConfig, error) {
func (c *GitCommand) GetSubmoduleConfigs() ([]*models.SubmoduleConfig, error) {
file, err := os.Open(".gitmodules")
if err != nil {
if os.IsNotExist(err) {
@ -34,12 +36,12 @@ func (c *GitCommand) GetSubmoduleConfigs() ([]*SubmoduleConfig, error) {
}
}
configs := []*SubmoduleConfig{}
configs := []*models.SubmoduleConfig{}
for scanner.Scan() {
line := scanner.Text()
if name, ok := firstMatch(line, `\[submodule "(.*)"\]`); ok {
configs = append(configs, &SubmoduleConfig{Name: name})
configs = append(configs, &models.SubmoduleConfig{Name: name})
continue
}
@ -57,7 +59,7 @@ func (c *GitCommand) GetSubmoduleConfigs() ([]*SubmoduleConfig, error) {
return configs, nil
}
func (c *GitCommand) SubmoduleStash(config *SubmoduleConfig) error {
func (c *GitCommand) SubmoduleStash(config *models.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) {
@ -68,7 +70,7 @@ func (c *GitCommand) SubmoduleStash(config *SubmoduleConfig) error {
return c.OSCommand.RunCommand("git -C %s stash --include-untracked", config.Path)
}
func (c *GitCommand) SubmoduleReset(config *SubmoduleConfig) error {
func (c *GitCommand) SubmoduleReset(config *models.SubmoduleConfig) error {
return c.OSCommand.RunCommand("git submodule update --force %s", config.Name)
}