mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +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)
|
||||
}
|
||||
|
||||
func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
||||
func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*models.File {
|
||||
// check if config wants us ignoring untracked files
|
||||
untrackedFilesSetting := c.GetConfigValue("status.showUntrackedFiles")
|
||||
|
||||
@ -286,7 +286,7 @@ func (c *GitCommand) GetStatusFiles(opts GetStatusFileOptions) []*File {
|
||||
c.Log.Error(err)
|
||||
}
|
||||
statusStrings := utils.SplitLines(statusOutput)
|
||||
files := []*File{}
|
||||
files := []*models.File{}
|
||||
|
||||
for _, statusString := range statusStrings {
|
||||
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)
|
||||
hasInlineMergeConflicts := utils.IncludesString([]string{"UU", "AA"}, change)
|
||||
|
||||
file := &File{
|
||||
file := &models.File{
|
||||
Name: filename,
|
||||
DisplayString: statusString,
|
||||
HasStagedChanges: !hasNoStagedChanges,
|
||||
@ -331,7 +331,7 @@ func (c *GitCommand) StashSave(message string) error {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return newFiles
|
||||
}
|
||||
@ -339,7 +339,7 @@ func (c *GitCommand) MergeStatusFiles(oldFiles, newFiles []*File, selectedFile *
|
||||
appendedIndexes := []int{}
|
||||
|
||||
// retain position of files we already could see
|
||||
result := []*File{}
|
||||
result := []*models.File{}
|
||||
for _, oldFile := range oldFiles {
|
||||
for newIndex, newFile := range newFiles {
|
||||
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() {
|
||||
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, " -> ")
|
||||
filesWithoutRenames := c.GetStatusFiles(GetStatusFileOptions{NoRenames: true})
|
||||
var beforeFile *File
|
||||
var afterFile *File
|
||||
var beforeFile *models.File
|
||||
var afterFile *models.File
|
||||
for _, f := range filesWithoutRenames {
|
||||
if f.Name == split[0] {
|
||||
beforeFile = f
|
||||
@ -716,7 +716,7 @@ func (c *GitCommand) BeforeAndAfterFileForRename(file *File) (*File, *File, erro
|
||||
}
|
||||
|
||||
// DiscardAllFileChanges directly
|
||||
func (c *GitCommand) DiscardAllFileChanges(file *File) error {
|
||||
func (c *GitCommand) DiscardAllFileChanges(file *models.File) error {
|
||||
if file.IsRename() {
|
||||
beforeFile, afterFile, err := c.BeforeAndAfterFileForRename(file)
|
||||
if err != nil {
|
||||
@ -749,7 +749,7 @@ func (c *GitCommand) DiscardAllFileChanges(file *File) error {
|
||||
}
|
||||
|
||||
// DiscardUnstagedFileChanges directly
|
||||
func (c *GitCommand) DiscardUnstagedFileChanges(file *File) error {
|
||||
func (c *GitCommand) DiscardUnstagedFileChanges(file *models.File) error {
|
||||
quotedFileName := c.OSCommand.Quote(file.Name)
|
||||
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
|
||||
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
|
||||
s, _ := c.OSCommand.RunCommandWithOutput(c.WorktreeFileDiffCmdStr(file, plain, cached))
|
||||
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 := ""
|
||||
trackedArg := "--"
|
||||
colorArg := c.colorArg()
|
||||
|
@ -311,7 +311,7 @@ func TestGitCommandGetStatusFiles(t *testing.T) {
|
||||
type scenario struct {
|
||||
testName string
|
||||
command func(string, ...string) *exec.Cmd
|
||||
test func([]*File)
|
||||
test func([]*models.File)
|
||||
}
|
||||
|
||||
scenarios := []scenario{
|
||||
@ -320,7 +320,7 @@ func TestGitCommandGetStatusFiles(t *testing.T) {
|
||||
func(cmd string, args ...string) *exec.Cmd {
|
||||
return exec.Command("echo")
|
||||
},
|
||||
func(files []*File) {
|
||||
func(files []*models.File) {
|
||||
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",
|
||||
)
|
||||
},
|
||||
func(files []*File) {
|
||||
func(files []*models.File) {
|
||||
assert.Len(t, files, 5)
|
||||
|
||||
expected := []*File{
|
||||
expected := []*models.File{
|
||||
{
|
||||
Name: "file1.txt",
|
||||
HasStagedChanges: true,
|
||||
@ -457,22 +457,22 @@ func TestGitCommandCommitAmend(t *testing.T) {
|
||||
func TestGitCommandMergeStatusFiles(t *testing.T) {
|
||||
type scenario struct {
|
||||
testName string
|
||||
oldFiles []*File
|
||||
newFiles []*File
|
||||
test func([]*File)
|
||||
oldFiles []*models.File
|
||||
newFiles []*models.File
|
||||
test func([]*models.File)
|
||||
}
|
||||
|
||||
scenarios := []scenario{
|
||||
{
|
||||
"Old file and new file are the same",
|
||||
[]*File{},
|
||||
[]*File{
|
||||
[]*models.File{},
|
||||
[]*models.File{
|
||||
{
|
||||
Name: "new_file.txt",
|
||||
},
|
||||
},
|
||||
func(files []*File) {
|
||||
expected := []*File{
|
||||
func(files []*models.File) {
|
||||
expected := []*models.File{
|
||||
{
|
||||
Name: "new_file.txt",
|
||||
},
|
||||
@ -484,7 +484,7 @@ func TestGitCommandMergeStatusFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"Several files to merge, with some identical",
|
||||
[]*File{
|
||||
[]*models.File{
|
||||
{
|
||||
Name: "new_file1.txt",
|
||||
},
|
||||
@ -495,7 +495,7 @@ func TestGitCommandMergeStatusFiles(t *testing.T) {
|
||||
Name: "new_file3.txt",
|
||||
},
|
||||
},
|
||||
[]*File{
|
||||
[]*models.File{
|
||||
{
|
||||
Name: "new_file4.txt",
|
||||
},
|
||||
@ -506,8 +506,8 @@ func TestGitCommandMergeStatusFiles(t *testing.T) {
|
||||
Name: "new_file1.txt",
|
||||
},
|
||||
},
|
||||
func(files []*File) {
|
||||
expected := []*File{
|
||||
func(files []*models.File) {
|
||||
expected := []*models.File{
|
||||
{
|
||||
Name: "new_file1.txt",
|
||||
},
|
||||
@ -1099,7 +1099,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
testName string
|
||||
command func() (func(string, ...string) *exec.Cmd, *[][]string)
|
||||
test func(*[][]string, error)
|
||||
file *File
|
||||
file *models.File
|
||||
removeFile func(string) error
|
||||
}
|
||||
|
||||
@ -1121,7 +1121,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
{"reset", "--", "test"},
|
||||
})
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test",
|
||||
HasStagedChanges: true,
|
||||
},
|
||||
@ -1144,7 +1144,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
assert.EqualError(t, err, "an error occurred when removing file")
|
||||
assert.Len(t, *cmdsCalled, 0)
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test",
|
||||
Tracked: false,
|
||||
},
|
||||
@ -1169,7 +1169,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
{"checkout", "--", "test"},
|
||||
})
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test",
|
||||
Tracked: true,
|
||||
HasStagedChanges: false,
|
||||
@ -1195,7 +1195,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
{"checkout", "--", "test"},
|
||||
})
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test",
|
||||
Tracked: true,
|
||||
HasStagedChanges: false,
|
||||
@ -1222,7 +1222,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
{"checkout", "--", "test"},
|
||||
})
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test",
|
||||
Tracked: true,
|
||||
HasStagedChanges: true,
|
||||
@ -1249,7 +1249,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
{"checkout", "--", "test"},
|
||||
})
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test",
|
||||
Tracked: true,
|
||||
HasMergeConflicts: true,
|
||||
@ -1275,7 +1275,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
{"reset", "--", "test"},
|
||||
})
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test",
|
||||
Tracked: false,
|
||||
HasStagedChanges: true,
|
||||
@ -1299,7 +1299,7 @@ func TestGitCommandDiscardAllFileChanges(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, *cmdsCalled, 0)
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test",
|
||||
Tracked: false,
|
||||
HasStagedChanges: false,
|
||||
@ -1386,7 +1386,7 @@ func TestGitCommandDiff(t *testing.T) {
|
||||
type scenario struct {
|
||||
testName string
|
||||
command func(string, ...string) *exec.Cmd
|
||||
file *File
|
||||
file *models.File
|
||||
plain bool
|
||||
cached bool
|
||||
}
|
||||
@ -1400,7 +1400,7 @@ func TestGitCommandDiff(t *testing.T) {
|
||||
|
||||
return exec.Command("echo")
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test.txt",
|
||||
HasStagedChanges: false,
|
||||
Tracked: true,
|
||||
@ -1416,7 +1416,7 @@ func TestGitCommandDiff(t *testing.T) {
|
||||
|
||||
return exec.Command("echo")
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test.txt",
|
||||
HasStagedChanges: false,
|
||||
Tracked: true,
|
||||
@ -1432,7 +1432,7 @@ func TestGitCommandDiff(t *testing.T) {
|
||||
|
||||
return exec.Command("echo")
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test.txt",
|
||||
HasStagedChanges: false,
|
||||
Tracked: true,
|
||||
@ -1448,7 +1448,7 @@ func TestGitCommandDiff(t *testing.T) {
|
||||
|
||||
return exec.Command("echo")
|
||||
},
|
||||
&File{
|
||||
&models.File{
|
||||
Name: "test.txt",
|
||||
HasStagedChanges: false,
|
||||
Tracked: false,
|
||||
@ -1806,7 +1806,7 @@ func TestGitCommandDiscardOldFileChanges(t *testing.T) {
|
||||
func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) {
|
||||
type scenario struct {
|
||||
testName string
|
||||
file *File
|
||||
file *models.File
|
||||
command func(string, ...string) *exec.Cmd
|
||||
test func(error)
|
||||
}
|
||||
@ -1814,7 +1814,7 @@ func TestGitCommandDiscardUnstagedFileChanges(t *testing.T) {
|
||||
scenarios := []scenario{
|
||||
{
|
||||
"valid case",
|
||||
&File{Name: "test.txt"},
|
||||
&models.File{Name: "test.txt"},
|
||||
test.CreateMockCommand(t, []*test.CommandSwapper{
|
||||
{
|
||||
Expect: `git checkout -- "test.txt"`,
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ type CustomCommandObjects struct {
|
||||
SelectedLocalCommit *models.Commit
|
||||
SelectedReflogCommit *models.Commit
|
||||
SelectedSubCommit *models.Commit
|
||||
SelectedFile *commands.File
|
||||
SelectedFile *models.File
|
||||
SelectedLocalBranch *models.Branch
|
||||
SelectedRemoteBranch *models.RemoteBranch
|
||||
SelectedRemote *models.Remote
|
||||
|
@ -2,10 +2,10 @@ package gui
|
||||
|
||||
import (
|
||||
"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 {
|
||||
if config.Name == file.Name {
|
||||
return config
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/models"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -73,7 +73,7 @@ func (w *fileWatcher) watchFilename(filename string) {
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
|
@ -14,13 +14,14 @@ import (
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/mgutz/str"
|
||||
)
|
||||
|
||||
// list panel functions
|
||||
|
||||
func (gui *Gui) getSelectedFile() *commands.File {
|
||||
func (gui *Gui) getSelectedFile() *models.File {
|
||||
selectedLine := gui.State.Panels.Files.SelectedLineIdx
|
||||
if selectedLine == -1 {
|
||||
return nil
|
||||
@ -119,9 +120,9 @@ func (gui *Gui) refreshFiles() error {
|
||||
|
||||
// specific functions
|
||||
|
||||
func (gui *Gui) stagedFiles() []*commands.File {
|
||||
func (gui *Gui) stagedFiles() []*models.File {
|
||||
files := gui.State.Files
|
||||
result := make([]*commands.File, 0)
|
||||
result := make([]*models.File, 0)
|
||||
for _, file := range files {
|
||||
if file.HasStagedChanges {
|
||||
result = append(result, file)
|
||||
@ -130,9 +131,9 @@ func (gui *Gui) stagedFiles() []*commands.File {
|
||||
return result
|
||||
}
|
||||
|
||||
func (gui *Gui) trackedFiles() []*commands.File {
|
||||
func (gui *Gui) trackedFiles() []*models.File {
|
||||
files := gui.State.Files
|
||||
result := make([]*commands.File, 0, len(files))
|
||||
result := make([]*models.File, 0, len(files))
|
||||
for _, file := range files {
|
||||
if file.Tracked {
|
||||
result = append(result, file)
|
||||
|
@ -272,8 +272,8 @@ type Modes struct {
|
||||
}
|
||||
|
||||
type guiState struct {
|
||||
Files []*commands.File
|
||||
SubmoduleConfigs []*commands.SubmoduleConfig
|
||||
Files []*models.File
|
||||
SubmoduleConfigs []*models.SubmoduleConfig
|
||||
Branches []*models.Branch
|
||||
Commits []*models.Commit
|
||||
StashEntries []*commands.StashEntry
|
||||
@ -349,7 +349,7 @@ func (gui *Gui) resetState() {
|
||||
}
|
||||
|
||||
gui.State = &guiState{
|
||||
Files: make([]*commands.File, 0),
|
||||
Files: make([]*models.File, 0),
|
||||
Commits: make([]*models.Commit, 0),
|
||||
FilteredReflogCommits: make([]*models.Commit, 0),
|
||||
ReflogCommits: make([]*models.Commit, 0),
|
||||
|
@ -2,12 +2,12 @@ package presentation
|
||||
|
||||
import (
|
||||
"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/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))
|
||||
|
||||
for i := range files {
|
||||
@ -19,7 +19,7 @@ func GetFileListDisplayStrings(files []*commands.File, diffName string, submodul
|
||||
}
|
||||
|
||||
// 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
|
||||
// objects with each render
|
||||
red := color.New(color.FgRed)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package models
|
||||
|
||||
import (
|
||||
"strings"
|
@ -1,4 +1,4 @@
|
||||
package commands
|
||||
package models
|
||||
|
||||
type SubmoduleConfig struct {
|
||||
Name string
|
Reference in New Issue
Block a user