mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
support submodules
This commit is contained in:
@ -19,6 +19,7 @@ type File struct {
|
|||||||
DisplayString string
|
DisplayString string
|
||||||
Type string // one of 'file', 'directory', and 'other'
|
Type string // one of 'file', 'directory', and 'other'
|
||||||
ShortStatus string // e.g. 'AD', ' A', 'M ', '??'
|
ShortStatus string // e.g. 'AD', ' A', 'M ', '??'
|
||||||
|
IsSubmodule bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const RENAME_SEPARATOR = " -> "
|
const RENAME_SEPARATOR = " -> "
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -271,6 +272,32 @@ func (c *GitCommand) GetConfigValue(key string) string {
|
|||||||
return strings.TrimSpace(output)
|
return strings.TrimSpace(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *GitCommand) GetSubmoduleNames() ([]string, error) {
|
||||||
|
file, err := os.Open(".gitmodules")
|
||||||
|
if err != nil {
|
||||||
|
if err == os.ErrNotExist {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
submoduleNames := []string{}
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
scanner.Split(bufio.ScanLines)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
re := regexp.MustCompile(`\[submodule "(.*)"\]`)
|
||||||
|
matches := re.FindStringSubmatch(line)
|
||||||
|
|
||||||
|
if len(matches) > 0 {
|
||||||
|
submoduleNames = append(submoduleNames, matches[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return submoduleNames, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
||||||
// check if config wants us ignoring untracked files
|
// check if config wants us ignoring untracked files
|
||||||
untrackedFilesSetting := c.GetConfigValue("status.showUntrackedFiles")
|
untrackedFilesSetting := c.GetConfigValue("status.showUntrackedFiles")
|
||||||
@ -287,6 +314,11 @@ func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
|||||||
statusStrings := utils.SplitLines(statusOutput)
|
statusStrings := utils.SplitLines(statusOutput)
|
||||||
files := []*File{}
|
files := []*File{}
|
||||||
|
|
||||||
|
submoduleNames, err := c.GetSubmoduleNames()
|
||||||
|
if err != nil {
|
||||||
|
c.Log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, statusString := range statusStrings {
|
for _, statusString := range statusStrings {
|
||||||
if strings.HasPrefix(statusString, "warning") {
|
if strings.HasPrefix(statusString, "warning") {
|
||||||
c.Log.Warningf("warning when calling git status: %s", statusString)
|
c.Log.Warningf("warning when calling git status: %s", statusString)
|
||||||
@ -300,6 +332,7 @@ func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
|||||||
hasNoStagedChanges := utils.IncludesString([]string{" ", "U", "?"}, stagedChange)
|
hasNoStagedChanges := utils.IncludesString([]string{" ", "U", "?"}, stagedChange)
|
||||||
hasMergeConflicts := utils.IncludesString([]string{"DD", "AA", "UU", "AU", "UA", "UD", "DU"}, change)
|
hasMergeConflicts := utils.IncludesString([]string{"DD", "AA", "UU", "AU", "UA", "UD", "DU"}, change)
|
||||||
hasInlineMergeConflicts := utils.IncludesString([]string{"UU", "AA"}, change)
|
hasInlineMergeConflicts := utils.IncludesString([]string{"UU", "AA"}, change)
|
||||||
|
isSubmodule := utils.IncludesString(submoduleNames, filename)
|
||||||
|
|
||||||
file := &File{
|
file := &File{
|
||||||
Name: filename,
|
Name: filename,
|
||||||
@ -312,6 +345,7 @@ func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
|||||||
HasInlineMergeConflicts: hasInlineMergeConflicts,
|
HasInlineMergeConflicts: hasInlineMergeConflicts,
|
||||||
Type: c.OSCommand.FileType(filename),
|
Type: c.OSCommand.FileType(filename),
|
||||||
ShortStatus: change,
|
ShortStatus: change,
|
||||||
|
IsSubmodule: isSubmodule,
|
||||||
}
|
}
|
||||||
files = append(files, file)
|
files = append(files, file)
|
||||||
}
|
}
|
||||||
@ -718,7 +752,11 @@ func (c *GitCommand) DiscardAllFileChanges(file *File) error {
|
|||||||
|
|
||||||
// if the file isn't tracked, we assume you want to delete it
|
// if the file isn't tracked, we assume you want to delete it
|
||||||
quotedFileName := c.OSCommand.Quote(file.Name)
|
quotedFileName := c.OSCommand.Quote(file.Name)
|
||||||
if file.HasStagedChanges || file.HasMergeConflicts {
|
if file.IsSubmodule {
|
||||||
|
if err := c.OSCommand.RunCommand(fmt.Sprintf("git submodule update --checkout --force --init %s", quotedFileName)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if file.HasStagedChanges || file.HasMergeConflicts {
|
||||||
if err := c.OSCommand.RunCommand("git reset -- %s", quotedFileName); err != nil {
|
if err := c.OSCommand.RunCommand("git reset -- %s", quotedFileName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -828,7 +866,7 @@ func (c *GitCommand) WorktreeFileDiffCmdStr(file *File, plain bool, cached bool)
|
|||||||
colorArg = "never"
|
colorArg = "never"
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("git diff --no-ext-diff --color=%s %s %s %s", colorArg, cachedArg, trackedArg, fileName)
|
return fmt.Sprintf("git diff --submodule --no-ext-diff --color=%s %s %s %s", colorArg, cachedArg, trackedArg, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {
|
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {
|
||||||
@ -1108,7 +1146,7 @@ func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool, patchM
|
|||||||
reverseFlag = " -R "
|
reverseFlag = " -R "
|
||||||
}
|
}
|
||||||
|
|
||||||
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --no-ext-diff --name-status %s %s %s", reverseFlag, from, to)
|
filenames, err := c.OSCommand.RunCommandWithOutput("git diff --submodule --no-ext-diff --name-status %s %s %s", reverseFlag, from, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1161,7 +1199,7 @@ func (c *GitCommand) ShowFileDiffCmdStr(from string, to string, reverse bool, fi
|
|||||||
reverseFlag = " -R "
|
reverseFlag = " -R "
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("git diff --no-ext-diff --no-renames --color=%s %s %s %s -- %s", colorArg, from, to, reverseFlag, fileName)
|
return fmt.Sprintf("git diff --submodule --no-ext-diff --no-renames --color=%s %s %s %s -- %s", colorArg, from, to, reverseFlag, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckoutFile checks out the file for the given commit
|
// CheckoutFile checks out the file for the given commit
|
||||||
|
@ -14,7 +14,7 @@ func (gui *Gui) exitDiffMode() error {
|
|||||||
|
|
||||||
func (gui *Gui) renderDiff() error {
|
func (gui *Gui) renderDiff() error {
|
||||||
cmd := gui.OSCommand.ExecutableFromString(
|
cmd := gui.OSCommand.ExecutableFromString(
|
||||||
fmt.Sprintf("git diff --no-ext-diff --color %s", gui.diffStr()),
|
fmt.Sprintf("git diff --submodule --no-ext-diff --color %s", gui.diffStr()),
|
||||||
)
|
)
|
||||||
task := gui.createRunPtyTask(cmd)
|
task := gui.createRunPtyTask(cmd)
|
||||||
|
|
||||||
|
@ -10,6 +10,11 @@ func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if file.IsSubmodule {
|
||||||
|
// git submodule foreach '[[ "$name" == "renderers/chartify" ]] && git stash --include-untracked'
|
||||||
|
// git submodule update --force renderers/chartify
|
||||||
|
}
|
||||||
|
|
||||||
menuItems := []*menuItem{
|
menuItems := []*menuItem{
|
||||||
{
|
{
|
||||||
displayString: gui.Tr.SLocalize("discardAllChanges"),
|
displayString: gui.Tr.SLocalize("discardAllChanges"),
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFileListDisplayStrings(files []*commands.File, diffName string) [][]string {
|
func GetFileListDisplayStrings(files []*commands.File, diffName string) [][]string {
|
||||||
@ -53,5 +54,10 @@ func getFileDisplayStrings(f *commands.File, diffed bool) []string {
|
|||||||
output := firstCharCl.Sprint(firstChar)
|
output := firstCharCl.Sprint(firstChar)
|
||||||
output += secondCharCl.Sprint(secondChar)
|
output += secondCharCl.Sprint(secondChar)
|
||||||
output += restColor.Sprintf(" %s", f.Name)
|
output += restColor.Sprintf(" %s", f.Name)
|
||||||
|
|
||||||
|
if f.IsSubmodule {
|
||||||
|
output += utils.ColoredString(" (submodule)", theme.DefaultTextColor)
|
||||||
|
}
|
||||||
|
|
||||||
return []string{output}
|
return []string{output}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user