mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
move file and submodule
This commit is contained in:
@ -272,7 +272,7 @@ func (c *GitCommand) GetConfigValue(key string) string {
|
|||||||
return strings.TrimSpace(output)
|
return strings.TrimSpace(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*models.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")
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
|||||||
c.Log.Error(err)
|
c.Log.Error(err)
|
||||||
}
|
}
|
||||||
statusStrings := utils.SplitLines(statusOutput)
|
statusStrings := utils.SplitLines(statusOutput)
|
||||||
files := []*File{}
|
files := []*models.File{}
|
||||||
|
|
||||||
for _, statusString := range statusStrings {
|
for _, statusString := range statusStrings {
|
||||||
if strings.HasPrefix(statusString, "warning") {
|
if strings.HasPrefix(statusString, "warning") {
|
||||||
@ -302,7 +302,7 @@ func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
|||||||
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)
|
||||||
|
|
||||||
file := &File{
|
file := &models.File{
|
||||||
Name: filename,
|
Name: filename,
|
||||||
DisplayString: statusString,
|
DisplayString: statusString,
|
||||||
HasStagedChanges: !hasNoStagedChanges,
|
HasStagedChanges: !hasNoStagedChanges,
|
||||||
@ -331,7 +331,7 @@ func (c *GitCommand) StashSave(message string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MergeStatusFiles merge status files
|
// MergeStatusFiles merge status files
|
||||||
func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []*File, selectedFile *File) []*File {
|
func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []*models.File, selectedFile *models.File) []*models.File {
|
||||||
if len(oldFiles) == 0 {
|
if len(oldFiles) == 0 {
|
||||||
return newFiles
|
return newFiles
|
||||||
}
|
}
|
||||||
@ -339,7 +339,7 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []*File, selectedFile *
|
|||||||
appendedIndexes := []int{}
|
appendedIndexes := []int{}
|
||||||
|
|
||||||
// retain position of files we already could see
|
// retain position of files we already could see
|
||||||
result := []*File{}
|
result := []*models.File{}
|
||||||
for _, oldFile := range oldFiles {
|
for _, oldFile := range oldFiles {
|
||||||
for newIndex, newFile := range newFiles {
|
for newIndex, newFile := range newFiles {
|
||||||
if includesInt(appendedIndexes, newIndex) {
|
if includesInt(appendedIndexes, newIndex) {
|
||||||
@ -679,7 +679,7 @@ func (c *GitCommand) RebaseMode() (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) BeforeAndAfterFileForRename(file *File) (*File, *File, error) {
|
func (c *GitCommand) BeforeAndAfterFileForRename(file *models.File) (*models.File, *models.File, error) {
|
||||||
|
|
||||||
if !file.IsRename() {
|
if !file.IsRename() {
|
||||||
return nil, nil, errors.New("Expected renamed file")
|
return nil, nil, errors.New("Expected renamed file")
|
||||||
@ -692,8 +692,8 @@ func (c *GitCommand) BeforeAndAfterFileForRename(file *File) (*File, *File, erro
|
|||||||
|
|
||||||
split := strings.Split(file.Name, " -> ")
|
split := strings.Split(file.Name, " -> ")
|
||||||
filesWithoutRenames := c.GetStatusFiles(GetStatusFileOptions{NoRenames: true})
|
filesWithoutRenames := c.GetStatusFiles(GetStatusFileOptions{NoRenames: true})
|
||||||
var beforeFile *File
|
var beforeFile *models.File
|
||||||
var afterFile *File
|
var afterFile *models.File
|
||||||
for _, f := range filesWithoutRenames {
|
for _, f := range filesWithoutRenames {
|
||||||
if f.Name == split[0] {
|
if f.Name == split[0] {
|
||||||
beforeFile = f
|
beforeFile = f
|
||||||
@ -716,7 +716,7 @@ func (c *GitCommand) BeforeAndAfterFileForRename(file *File) (*File, *File, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DiscardAllFileChanges directly
|
// DiscardAllFileChanges directly
|
||||||
func (c *GitCommand) DiscardAllFileChanges(file *File) error {
|
func (c *GitCommand) DiscardAllFileChanges(file *models.File) error {
|
||||||
if file.IsRename() {
|
if file.IsRename() {
|
||||||
beforeFile, afterFile, err := c.BeforeAndAfterFileForRename(file)
|
beforeFile, afterFile, err := c.BeforeAndAfterFileForRename(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -749,7 +749,7 @@ func (c *GitCommand) DiscardAllFileChanges(file *File) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DiscardUnstagedFileChanges directly
|
// DiscardUnstagedFileChanges directly
|
||||||
func (c *GitCommand) DiscardUnstagedFileChanges(file *File) error {
|
func (c *GitCommand) DiscardUnstagedFileChanges(file *models.File) error {
|
||||||
quotedFileName := c.OSCommand.Quote(file.Name)
|
quotedFileName := c.OSCommand.Quote(file.Name)
|
||||||
return c.OSCommand.RunCommand("git checkout -- %s", quotedFileName)
|
return c.OSCommand.RunCommand("git checkout -- %s", quotedFileName)
|
||||||
}
|
}
|
||||||
@ -824,13 +824,13 @@ func (c *GitCommand) CheckRemoteBranchExists(branch *models.Branch) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorktreeFileDiff returns the diff of a file
|
// WorktreeFileDiff returns the diff of a file
|
||||||
func (c *GitCommand) WorktreeFileDiff(file *File, plain bool, cached bool) string {
|
func (c *GitCommand) WorktreeFileDiff(file *models.File, plain bool, cached bool) string {
|
||||||
// for now we assume an error means the file was deleted
|
// for now we assume an error means the file was deleted
|
||||||
s, _ := c.OSCommand.RunCommandWithOutput(c.WorktreeFileDiffCmdStr(file, plain, cached))
|
s, _ := c.OSCommand.RunCommandWithOutput(c.WorktreeFileDiffCmdStr(file, plain, cached))
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) WorktreeFileDiffCmdStr(file *File, plain bool, cached bool) string {
|
func (c *GitCommand) WorktreeFileDiffCmdStr(file *models.File, plain bool, cached bool) string {
|
||||||
cachedArg := ""
|
cachedArg := ""
|
||||||
trackedArg := "--"
|
trackedArg := "--"
|
||||||
colorArg := c.colorArg()
|
colorArg := c.colorArg()
|
||||||
|
@ -311,7 +311,7 @@ func TestGitCommandGetStatusFiles(t *testing.T) {
|
|||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
command func(string, ...string) *exec.Cmd
|
command func(string, ...string) *exec.Cmd
|
||||||
test func([]*File)
|
test func([]*models.File)
|
||||||
}
|
}
|
||||||
|
|
||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
@ -320,7 +320,7 @@ func TestGitCommandGetStatusFiles(t *testing.T) {
|
|||||||
func(cmd string, args ...string) *exec.Cmd {
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
},
|
},
|
||||||
func(files []*File) {
|
func(files []*models.File) {
|
||||||
assert.Len(t, files, 0)
|
assert.Len(t, files, 0)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -332,10 +332,10 @@ func TestGitCommandGetStatusFiles(t *testing.T) {
|
|||||||
"MM file1.txt\nA file3.txt\nAM file2.txt\n?? file4.txt\nUU file5.txt",
|
"MM file1.txt\nA file3.txt\nAM file2.txt\n?? file4.txt\nUU file5.txt",
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
func(files []*File) {
|
func(files []*models.File) {
|
||||||
assert.Len(t, files, 5)
|
assert.Len(t, files, 5)
|
||||||
|
|
||||||
expected := []*File{
|
expected := []*models.File{
|
||||||
{
|
{
|
||||||
Name: "file1.txt",
|
Name: "file1.txt",
|
||||||
HasStagedChanges: true,
|
HasStagedChanges: true,
|
||||||
@ -457,22 +457,22 @@ func TestGitCommandCommitAmend(t *testing.T) {
|
|||||||
func TestGitCommandMergeStatusFiles(t *testing.T) {
|
func TestGitCommandMergeStatusFiles(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
oldFiles []*File
|
oldFiles []*models.File
|
||||||
newFiles []*File
|
newFiles []*models.File
|
||||||
test func([]*File)
|
test func([]*models.File)
|
||||||
}
|
}
|
||||||
|
|
||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
{
|
{
|
||||||
"Old file and new file are the same",
|
"Old file and new file are the same",
|
||||||
[]*File{},
|
[]*models.File{},
|
||||||
[]*File{
|
[]*models.File{
|
||||||
{
|
{
|
||||||
Name: "new_file.txt",
|
Name: "new_file.txt",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
func(files []*File) {
|
func(files []*models.File) {
|
||||||
expected := []*File{
|
expected := []*models.File{
|
||||||
{
|
{
|
||||||
Name: "new_file.txt",
|
Name: "new_file.txt",
|
||||||
},
|
},
|
||||||
@ -484,7 +484,7 @@ func TestGitCommandMergeStatusFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Several files to merge, with some identical",
|
"Several files to merge, with some identical",
|
||||||
[]*File{
|
[]*models.File{
|
||||||
{
|
{
|
||||||
Name: "new_file1.txt",
|
Name: "new_file1.txt",
|
||||||
},
|
},
|
||||||
@ -495,7 +495,7 @@ func TestGitCommandMergeStatusFiles(t *testing.T) {
|
|||||||
Name: "new_file3.txt",
|
Name: "new_file3.txt",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[]*File{
|
[]*models.File{
|
||||||
{
|
{
|
||||||
Name: "new_file4.txt",
|
Name: "new_file4.txt",
|
||||||
},
|
},
|
||||||
@ -506,8 +506,8 @@ func TestGitCommandMergeStatusFiles(t *testing.T) {
|
|||||||
Name: "new_file1.txt",
|
Name: "new_file1.txt",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
func(files []*File) {
|
func(files []*models.File) {
|
||||||
expected := []*File{
|
expected := []*models.File{
|
||||||
{
|
{
|
||||||
Name: "new_file1.txt",
|
Name: "new_file1.txt",
|
||||||
},
|
},
|
||||||
@ -1099,7 +1099,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
testName string
|
testName string
|
||||||
command func() (func(string, ...string) *exec.Cmd, *[][]string)
|
command func() (func(string, ...string) *exec.Cmd, *[][]string)
|
||||||
test func(*[][]string, error)
|
test func(*[][]string, error)
|
||||||
file *File
|
file *models.File
|
||||||
removeFile func(string) error
|
removeFile func(string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1121,7 +1121,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
{"reset", "--", "test"},
|
{"reset", "--", "test"},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
HasStagedChanges: true,
|
HasStagedChanges: true,
|
||||||
},
|
},
|
||||||
@ -1144,7 +1144,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
assert.EqualError(t, err, "an error occurred when removing file")
|
assert.EqualError(t, err, "an error occurred when removing file")
|
||||||
assert.Len(t, *cmdsCalled, 0)
|
assert.Len(t, *cmdsCalled, 0)
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tracked: false,
|
Tracked: false,
|
||||||
},
|
},
|
||||||
@ -1169,7 +1169,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
{"checkout", "--", "test"},
|
{"checkout", "--", "test"},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tracked: true,
|
Tracked: true,
|
||||||
HasStagedChanges: false,
|
HasStagedChanges: false,
|
||||||
@ -1195,7 +1195,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
{"checkout", "--", "test"},
|
{"checkout", "--", "test"},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tracked: true,
|
Tracked: true,
|
||||||
HasStagedChanges: false,
|
HasStagedChanges: false,
|
||||||
@ -1222,7 +1222,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
{"checkout", "--", "test"},
|
{"checkout", "--", "test"},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tracked: true,
|
Tracked: true,
|
||||||
HasStagedChanges: true,
|
HasStagedChanges: true,
|
||||||
@ -1249,7 +1249,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
{"checkout", "--", "test"},
|
{"checkout", "--", "test"},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tracked: true,
|
Tracked: true,
|
||||||
HasMergeConflicts: true,
|
HasMergeConflicts: true,
|
||||||
@ -1275,7 +1275,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
{"reset", "--", "test"},
|
{"reset", "--", "test"},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tracked: false,
|
Tracked: false,
|
||||||
HasStagedChanges: true,
|
HasStagedChanges: true,
|
||||||
@ -1299,7 +1299,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, *cmdsCalled, 0)
|
assert.Len(t, *cmdsCalled, 0)
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Tracked: false,
|
Tracked: false,
|
||||||
HasStagedChanges: false,
|
HasStagedChanges: false,
|
||||||
@ -1386,7 +1386,7 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
command func(string, ...string) *exec.Cmd
|
command func(string, ...string) *exec.Cmd
|
||||||
file *File
|
file *models.File
|
||||||
plain bool
|
plain bool
|
||||||
cached bool
|
cached bool
|
||||||
}
|
}
|
||||||
@ -1400,7 +1400,7 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test.txt",
|
Name: "test.txt",
|
||||||
HasStagedChanges: false,
|
HasStagedChanges: false,
|
||||||
Tracked: true,
|
Tracked: true,
|
||||||
@ -1416,7 +1416,7 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test.txt",
|
Name: "test.txt",
|
||||||
HasStagedChanges: false,
|
HasStagedChanges: false,
|
||||||
Tracked: true,
|
Tracked: true,
|
||||||
@ -1432,7 +1432,7 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test.txt",
|
Name: "test.txt",
|
||||||
HasStagedChanges: false,
|
HasStagedChanges: false,
|
||||||
Tracked: true,
|
Tracked: true,
|
||||||
@ -1448,7 +1448,7 @@ func TestGitCommandDiff(t *testing.T) {
|
|||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
},
|
},
|
||||||
&File{
|
&models.File{
|
||||||
Name: "test.txt",
|
Name: "test.txt",
|
||||||
HasStagedChanges: false,
|
HasStagedChanges: false,
|
||||||
Tracked: false,
|
Tracked: false,
|
||||||
@ -1806,7 +1806,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
|
|||||||
func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) {
|
func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) {
|
||||||
type scenario struct {
|
type scenario struct {
|
||||||
testName string
|
testName string
|
||||||
file *File
|
file *models.File
|
||||||
command func(string, ...string) *exec.Cmd
|
command func(string, ...string) *exec.Cmd
|
||||||
test func(error)
|
test func(error)
|
||||||
}
|
}
|
||||||
@ -1814,7 +1814,7 @@ func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) {
|
|||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
{
|
{
|
||||||
"valid case",
|
"valid case",
|
||||||
&File{Name: "test.txt"},
|
&models.File{Name: "test.txt"},
|
||||||
test.CreateMockCommand(t, []*test.CommandSwapper{
|
test.CreateMockCommand(t, []*test.CommandSwapper{
|
||||||
{
|
{
|
||||||
Expect: `git checkout -- "test.txt"`,
|
Expect: `git checkout -- "test.txt"`,
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// .gitmodules looks like this:
|
// .gitmodules looks like this:
|
||||||
@ -11,7 +13,7 @@ import (
|
|||||||
// path = blah/mysubmodule
|
// path = blah/mysubmodule
|
||||||
// url = git@github.com:subbo.git
|
// url = git@github.com:subbo.git
|
||||||
|
|
||||||
func (c *GitCommand) GetSubmoduleConfigs() ([]*SubmoduleConfig, error) {
|
func (c *GitCommand) GetSubmoduleConfigs() ([]*models.SubmoduleConfig, error) {
|
||||||
file, err := os.Open(".gitmodules")
|
file, err := os.Open(".gitmodules")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
@ -34,12 +36,12 @@ func (c *GitCommand) GetSubmoduleConfigs() ([]*SubmoduleConfig, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configs := []*SubmoduleConfig{}
|
configs := []*models.SubmoduleConfig{}
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
|
|
||||||
if name, ok := firstMatch(line, `\[submodule "(.*)"\]`); ok {
|
if name, ok := firstMatch(line, `\[submodule "(.*)"\]`); ok {
|
||||||
configs = append(configs, &SubmoduleConfig{Name: name})
|
configs = append(configs, &models.SubmoduleConfig{Name: name})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ func (c *GitCommand) GetSubmoduleConfigs() ([]*SubmoduleConfig, error) {
|
|||||||
return configs, nil
|
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
|
// 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
|
// because the intention here is to have no dirty worktree state
|
||||||
if _, err := os.Stat(config.Path); os.IsNotExist(err) {
|
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)
|
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)
|
return c.OSCommand.RunCommand("git submodule update --force %s", config.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ type CustomCommandObjects struct {
|
|||||||
SelectedLocalCommit *models.Commit
|
SelectedLocalCommit *models.Commit
|
||||||
SelectedReflogCommit *models.Commit
|
SelectedReflogCommit *models.Commit
|
||||||
SelectedSubCommit *models.Commit
|
SelectedSubCommit *models.Commit
|
||||||
SelectedFile *commands.File
|
SelectedFile *models.File
|
||||||
SelectedLocalBranch *models.Branch
|
SelectedLocalBranch *models.Branch
|
||||||
SelectedRemoteBranch *models.RemoteBranch
|
SelectedRemoteBranch *models.RemoteBranch
|
||||||
SelectedRemote *models.Remote
|
SelectedRemote *models.Remote
|
||||||
|
@ -2,10 +2,10 @@ package gui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) submoduleFromFile(file *commands.File) *commands.SubmoduleConfig {
|
func (gui *Gui) submoduleFromFile(file *models.File) *models.SubmoduleConfig {
|
||||||
for _, config := range gui.State.SubmoduleConfigs {
|
for _, config := range gui.State.SubmoduleConfigs {
|
||||||
if config.Name == file.Name {
|
if config.Name == file.Name {
|
||||||
return config
|
return config
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/models"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ func (w *fileWatcher) watchFilename(filename string) {
|
|||||||
w.WatchedFilenames = append(w.WatchedFilenames, filename)
|
w.WatchedFilenames = append(w.WatchedFilenames, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *fileWatcher) addFilesToFileWatcher(files []*commands.File) error {
|
func (w *fileWatcher) addFilesToFileWatcher(files []*models.File) error {
|
||||||
if w.Disabled {
|
if w.Disabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,14 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/mgutz/str"
|
"github.com/mgutz/str"
|
||||||
)
|
)
|
||||||
|
|
||||||
// list panel functions
|
// list panel functions
|
||||||
|
|
||||||
func (gui *Gui) getSelectedFile() *commands.File {
|
func (gui *Gui) getSelectedFile() *models.File {
|
||||||
selectedLine := gui.State.Panels.Files.SelectedLineIdx
|
selectedLine := gui.State.Panels.Files.SelectedLineIdx
|
||||||
if selectedLine == -1 {
|
if selectedLine == -1 {
|
||||||
return nil
|
return nil
|
||||||
@ -119,9 +120,9 @@ func (gui *Gui) refreshFiles() error {
|
|||||||
|
|
||||||
// specific functions
|
// specific functions
|
||||||
|
|
||||||
func (gui *Gui) stagedFiles() []*commands.File {
|
func (gui *Gui) stagedFiles() []*models.File {
|
||||||
files := gui.State.Files
|
files := gui.State.Files
|
||||||
result := make([]*commands.File, 0)
|
result := make([]*models.File, 0)
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if file.HasStagedChanges {
|
if file.HasStagedChanges {
|
||||||
result = append(result, file)
|
result = append(result, file)
|
||||||
@ -130,9 +131,9 @@ func (gui *Gui) stagedFiles() []*commands.File {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) trackedFiles() []*commands.File {
|
func (gui *Gui) trackedFiles() []*models.File {
|
||||||
files := gui.State.Files
|
files := gui.State.Files
|
||||||
result := make([]*commands.File, 0, len(files))
|
result := make([]*models.File, 0, len(files))
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if file.Tracked {
|
if file.Tracked {
|
||||||
result = append(result, file)
|
result = append(result, file)
|
||||||
|
@ -272,8 +272,8 @@ type Modes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type guiState struct {
|
type guiState struct {
|
||||||
Files []*commands.File
|
Files []*models.File
|
||||||
SubmoduleConfigs []*commands.SubmoduleConfig
|
SubmoduleConfigs []*models.SubmoduleConfig
|
||||||
Branches []*models.Branch
|
Branches []*models.Branch
|
||||||
Commits []*models.Commit
|
Commits []*models.Commit
|
||||||
StashEntries []*commands.StashEntry
|
StashEntries []*commands.StashEntry
|
||||||
@ -349,7 +349,7 @@ func (gui *Gui) resetState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gui.State = &guiState{
|
gui.State = &guiState{
|
||||||
Files: make([]*commands.File, 0),
|
Files: make([]*models.File, 0),
|
||||||
Commits: make([]*models.Commit, 0),
|
Commits: make([]*models.Commit, 0),
|
||||||
FilteredReflogCommits: make([]*models.Commit, 0),
|
FilteredReflogCommits: make([]*models.Commit, 0),
|
||||||
ReflogCommits: make([]*models.Commit, 0),
|
ReflogCommits: make([]*models.Commit, 0),
|
||||||
|
@ -2,12 +2,12 @@ package presentation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFileListDisplayStrings(files []*commands.File, diffName string, submoduleConfigs []*commands.SubmoduleConfig) [][]string {
|
func GetFileListDisplayStrings(files []*models.File, diffName string, submoduleConfigs []*models.SubmoduleConfig) [][]string {
|
||||||
lines := make([][]string, len(files))
|
lines := make([][]string, len(files))
|
||||||
|
|
||||||
for i := range files {
|
for i := range files {
|
||||||
@ -19,7 +19,7 @@ func GetFileListDisplayStrings(files []*commands.File, diffName string, submodul
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getFileDisplayStrings returns the display string of branch
|
// getFileDisplayStrings returns the display string of branch
|
||||||
func getFileDisplayStrings(f *commands.File, diffed bool, submoduleConfigs []*commands.SubmoduleConfig) []string {
|
func getFileDisplayStrings(f *models.File, diffed bool, submoduleConfigs []*models.SubmoduleConfig) []string {
|
||||||
// potentially inefficient to be instantiating these color
|
// potentially inefficient to be instantiating these color
|
||||||
// objects with each render
|
// objects with each render
|
||||||
red := color.New(color.FgRed)
|
red := color.New(color.FgRed)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
@ -1,4 +1,4 @@
|
|||||||
package commands
|
package models
|
||||||
|
|
||||||
type SubmoduleConfig struct {
|
type SubmoduleConfig struct {
|
||||||
Name string
|
Name string
|
Reference in New Issue
Block a user