mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-31 23:19:40 +02:00
Removed a lot of useless code
This commit is contained in:
parent
d91493b587
commit
2edd2b74ff
@ -63,7 +63,6 @@ type GitCommand struct {
|
|||||||
Worktree *gogit.Worktree
|
Worktree *gogit.Worktree
|
||||||
Repo *gogit.Repository
|
Repo *gogit.Repository
|
||||||
Tr *i18n.Localizer
|
Tr *i18n.Localizer
|
||||||
SavedCredentials SavedCredentials
|
|
||||||
getGlobalGitConfig func(string) (string, error)
|
getGlobalGitConfig func(string) (string, error)
|
||||||
getLocalGitConfig func(string) (string, error)
|
getLocalGitConfig func(string) (string, error)
|
||||||
removeFile func(string) error
|
removeFile func(string) error
|
||||||
@ -94,19 +93,12 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
credentials := SavedCredentials{
|
|
||||||
Username: "",
|
|
||||||
Password: "",
|
|
||||||
HasAsked: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &GitCommand{
|
return &GitCommand{
|
||||||
Log: log,
|
Log: log,
|
||||||
OSCommand: osCommand,
|
OSCommand: osCommand,
|
||||||
Tr: tr,
|
Tr: tr,
|
||||||
Worktree: worktree,
|
Worktree: worktree,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
SavedCredentials: credentials,
|
|
||||||
getGlobalGitConfig: gitconfig.Global,
|
getGlobalGitConfig: gitconfig.Global,
|
||||||
getLocalGitConfig: gitconfig.Local,
|
getLocalGitConfig: gitconfig.Local,
|
||||||
removeFile: os.RemoveAll,
|
removeFile: os.RemoveAll,
|
||||||
@ -255,43 +247,14 @@ func (c *GitCommand) RenameCommit(name string) error {
|
|||||||
return c.OSCommand.RunCommand(fmt.Sprintf("git commit --allow-empty --amend -m %s", c.OSCommand.Quote(name)))
|
return c.OSCommand.RunCommand(fmt.Sprintf("git commit --allow-empty --amend -m %s", c.OSCommand.Quote(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SavedCredentials are the user's git login credentials
|
|
||||||
type SavedCredentials struct {
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
HasAsked bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch fetch git repo
|
// Fetch fetch git repo
|
||||||
func (c *GitCommand) Fetch(unamePassQuestion func(string) string, runDry bool) error {
|
func (c *GitCommand) Fetch(unamePassQuestion func(string) string, canSskForCredentials bool) error {
|
||||||
newCredentials := SavedCredentials{
|
return c.OSCommand.DetectUnamePass("git fetch", func(question string) string {
|
||||||
Username: c.SavedCredentials.Username,
|
if canSskForCredentials {
|
||||||
Password: c.SavedCredentials.Password,
|
return unamePassQuestion(question)
|
||||||
}
|
|
||||||
cmd := "git fetch"
|
|
||||||
if runDry {
|
|
||||||
cmd += " --dry-run"
|
|
||||||
}
|
|
||||||
|
|
||||||
err := c.OSCommand.DetectUnamePass(cmd, func(question string) string {
|
|
||||||
if question == "username" && len(c.SavedCredentials.Username) != 0 {
|
|
||||||
return c.SavedCredentials.Username
|
|
||||||
}
|
}
|
||||||
if question == "password" && len(c.SavedCredentials.Password) != 0 {
|
return "-"
|
||||||
return c.SavedCredentials.Password
|
|
||||||
}
|
|
||||||
output := unamePassQuestion(question)
|
|
||||||
if question == "password" {
|
|
||||||
newCredentials.Password = output
|
|
||||||
} else {
|
|
||||||
newCredentials.Username = output
|
|
||||||
}
|
|
||||||
return output
|
|
||||||
})
|
})
|
||||||
if err == nil {
|
|
||||||
c.SavedCredentials = newCredentials
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetToCommit reset to commit
|
// ResetToCommit reset to commit
|
||||||
|
@ -33,6 +33,11 @@ func (gui *Gui) handleCreatePullRequestPress(g *gocui.Gui, v *gocui.View) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleGitFetch(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
gui.fetch(g, true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error {
|
||||||
branch := gui.getSelectedBranch(v)
|
branch := gui.getSelectedBranch(v)
|
||||||
message := gui.Tr.SLocalize("SureForceCheckout")
|
message := gui.Tr.SLocalize("SureForceCheckout")
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
// "strings"
|
// "strings"
|
||||||
@ -351,50 +350,21 @@ func (gui *Gui) promptAnonymousReporting() error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) fetch(g *gocui.Gui) error {
|
func (gui *Gui) fetch(g *gocui.Gui, canSskForCredentials bool) error {
|
||||||
err := gui.GitCommand.Fetch(func(passOrUname string) string {
|
err := gui.GitCommand.Fetch(func(passOrUname string) string {
|
||||||
if !gui.GitCommand.SavedCredentials.HasAsked {
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Add(1)
|
|
||||||
gui.GitCommand.SavedCredentials.HasAsked = true
|
|
||||||
close := func(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
wg.Done()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
_ = gui.createConfirmationPanel(
|
|
||||||
g,
|
|
||||||
g.CurrentView(),
|
|
||||||
gui.Tr.SLocalize("RepoRequiresCredentialsTitle"),
|
|
||||||
gui.Tr.SLocalize("RepoRequiresCredentialsBody"),
|
|
||||||
close,
|
|
||||||
close,
|
|
||||||
)
|
|
||||||
wg.Wait()
|
|
||||||
}
|
|
||||||
return gui.waitForPassUname(gui.g, gui.g.CurrentView(), passOrUname)
|
return gui.waitForPassUname(gui.g, gui.g.CurrentView(), passOrUname)
|
||||||
}, false)
|
}, canSskForCredentials)
|
||||||
|
|
||||||
var reTryErr error
|
if canSskForCredentials && err != nil && strings.Contains(err.Error(), "exit status 128") {
|
||||||
if err != nil && strings.Contains(err.Error(), "exit status 128") {
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
currentView := g.CurrentView()
|
|
||||||
colorFunction := color.New(color.FgRed).SprintFunc()
|
colorFunction := color.New(color.FgRed).SprintFunc()
|
||||||
coloredMessage := colorFunction(strings.TrimSpace(gui.Tr.SLocalize("PassUnameWrong")))
|
coloredMessage := colorFunction(strings.TrimSpace(gui.Tr.SLocalize("PassUnameWrong")))
|
||||||
close := func(g *gocui.Gui, v *gocui.View) error {
|
close := func(g *gocui.Gui, v *gocui.View) error {
|
||||||
wg.Done()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_ = gui.createConfirmationPanel(g, currentView, gui.Tr.SLocalize("Error"), coloredMessage, close, close)
|
_ = gui.createConfirmationPanel(g, g.CurrentView(), gui.Tr.SLocalize("Error"), coloredMessage, close, close)
|
||||||
wg.Wait()
|
|
||||||
reTryErr = gui.fetch(g)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.refreshStatus(g)
|
gui.refreshStatus(g)
|
||||||
if reTryErr != nil {
|
|
||||||
return reTryErr
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,9 +421,12 @@ func (gui *Gui) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := gui.fetch(g)
|
time.Sleep(time.Second * 60)
|
||||||
if err == nil {
|
err := gui.fetch(g, false)
|
||||||
gui.goEvery(g, time.Second*60, gui.fetch)
|
if err == nil || !strings.Contains(err.Error(), "exit status 128") {
|
||||||
|
gui.goEvery(g, time.Second*60, func(g *gocui.Gui) error {
|
||||||
|
return gui.fetch(g, false)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
gui.goEvery(g, time.Second*10, gui.refreshFiles)
|
gui.goEvery(g, time.Second*10, gui.refreshFiles)
|
||||||
|
@ -295,6 +295,12 @@ func (gui *Gui) GetKeybindings() []*Binding {
|
|||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleForceCheckout,
|
Handler: gui.handleForceCheckout,
|
||||||
Description: gui.Tr.SLocalize("forceCheckout"),
|
Description: gui.Tr.SLocalize("forceCheckout"),
|
||||||
|
}, {
|
||||||
|
ViewName: "branches",
|
||||||
|
Key: 'f',
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleGitFetch,
|
||||||
|
Description: gui.Tr.SLocalize("fetch"),
|
||||||
}, {
|
}, {
|
||||||
ViewName: "branches",
|
ViewName: "branches",
|
||||||
Key: 'n',
|
Key: 'n',
|
||||||
|
@ -413,11 +413,8 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
ID: "NoBranchOnRemote",
|
ID: "NoBranchOnRemote",
|
||||||
Other: `Deze branch bestaat niet op de remote. U moet het eerst naar de remote pushen.`,
|
Other: `Deze branch bestaat niet op de remote. U moet het eerst naar de remote pushen.`,
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "RepoRequiresCredentialsTitle",
|
ID: "fetch",
|
||||||
Other: `Repo heeft inloggegevens nodig`,
|
Other: `fetch`,
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "RepoRequiresCredentialsBody",
|
|
||||||
Other: `Lazygit heeft inloggegevens nodig om git fetch te kunnen gebruiken`,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -421,11 +421,8 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
ID: "NoBranchOnRemote",
|
ID: "NoBranchOnRemote",
|
||||||
Other: `This branch doesn't exist on remote. You need to push it to remote first.`,
|
Other: `This branch doesn't exist on remote. You need to push it to remote first.`,
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "RepoRequiresCredentialsTitle",
|
ID: "fetch",
|
||||||
Other: `Repo requires credentials`,
|
Other: `fetch`,
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "RepoRequiresCredentialsBody",
|
|
||||||
Other: `Lazygit needs credentials to use git fetch`,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -396,11 +396,8 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
|||||||
ID: "NoBranchOnRemote",
|
ID: "NoBranchOnRemote",
|
||||||
Other: `Ta gałąź nie istnieje na zdalnym. Najpierw musisz go odepchnąć na odległość.`,
|
Other: `Ta gałąź nie istnieje na zdalnym. Najpierw musisz go odepchnąć na odległość.`,
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "RepoRequiresCredentialsTitle",
|
ID: "fetch",
|
||||||
Other: `Repo requires credentials`,
|
Other: `fetch`,
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "RepoRequiresCredentialsBody",
|
|
||||||
Other: `Lazygit needs credentials to use git fetch`,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user