mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-05 15:15:49 +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
|
||||
Repo *gogit.Repository
|
||||
Tr *i18n.Localizer
|
||||
SavedCredentials SavedCredentials
|
||||
getGlobalGitConfig func(string) (string, error)
|
||||
getLocalGitConfig func(string) (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{
|
||||
Log: log,
|
||||
OSCommand: osCommand,
|
||||
Tr: tr,
|
||||
Worktree: worktree,
|
||||
Repo: repo,
|
||||
SavedCredentials: credentials,
|
||||
getGlobalGitConfig: gitconfig.Global,
|
||||
getLocalGitConfig: gitconfig.Local,
|
||||
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)))
|
||||
}
|
||||
|
||||
// SavedCredentials are the user's git login credentials
|
||||
type SavedCredentials struct {
|
||||
Username string
|
||||
Password string
|
||||
HasAsked bool
|
||||
}
|
||||
|
||||
// Fetch fetch git repo
|
||||
func (c *GitCommand) Fetch(unamePassQuestion func(string) string, runDry bool) error {
|
||||
newCredentials := SavedCredentials{
|
||||
Username: c.SavedCredentials.Username,
|
||||
Password: c.SavedCredentials.Password,
|
||||
}
|
||||
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
|
||||
func (c *GitCommand) Fetch(unamePassQuestion func(string) string, canSskForCredentials bool) error {
|
||||
return c.OSCommand.DetectUnamePass("git fetch", func(question string) string {
|
||||
if canSskForCredentials {
|
||||
return unamePassQuestion(question)
|
||||
}
|
||||
if question == "password" && len(c.SavedCredentials.Password) != 0 {
|
||||
return c.SavedCredentials.Password
|
||||
}
|
||||
output := unamePassQuestion(question)
|
||||
if question == "password" {
|
||||
newCredentials.Password = output
|
||||
} else {
|
||||
newCredentials.Username = output
|
||||
}
|
||||
return output
|
||||
return "-"
|
||||
})
|
||||
if err == nil {
|
||||
c.SavedCredentials = newCredentials
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ResetToCommit reset to commit
|
||||
|
@ -33,6 +33,11 @@ func (gui *Gui) handleCreatePullRequestPress(g *gocui.Gui, v *gocui.View) error
|
||||
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 {
|
||||
branch := gui.getSelectedBranch(v)
|
||||
message := gui.Tr.SLocalize("SureForceCheckout")
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
// "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 {
|
||||
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)
|
||||
}, false)
|
||||
}, canSskForCredentials)
|
||||
|
||||
var reTryErr error
|
||||
if err != nil && strings.Contains(err.Error(), "exit status 128") {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
|
||||
currentView := g.CurrentView()
|
||||
if canSskForCredentials && err != nil && strings.Contains(err.Error(), "exit status 128") {
|
||||
colorFunction := color.New(color.FgRed).SprintFunc()
|
||||
coloredMessage := colorFunction(strings.TrimSpace(gui.Tr.SLocalize("PassUnameWrong")))
|
||||
close := func(g *gocui.Gui, v *gocui.View) error {
|
||||
wg.Done()
|
||||
return nil
|
||||
}
|
||||
_ = gui.createConfirmationPanel(g, currentView, gui.Tr.SLocalize("Error"), coloredMessage, close, close)
|
||||
wg.Wait()
|
||||
reTryErr = gui.fetch(g)
|
||||
_ = gui.createConfirmationPanel(g, g.CurrentView(), gui.Tr.SLocalize("Error"), coloredMessage, close, close)
|
||||
}
|
||||
|
||||
gui.refreshStatus(g)
|
||||
if reTryErr != nil {
|
||||
return reTryErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -451,9 +421,12 @@ func (gui *Gui) Run() error {
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := gui.fetch(g)
|
||||
if err == nil {
|
||||
gui.goEvery(g, time.Second*60, gui.fetch)
|
||||
time.Sleep(time.Second * 60)
|
||||
err := gui.fetch(g, false)
|
||||
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)
|
||||
|
@ -295,6 +295,12 @@ func (gui *Gui) GetKeybindings() []*Binding {
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleForceCheckout,
|
||||
Description: gui.Tr.SLocalize("forceCheckout"),
|
||||
}, {
|
||||
ViewName: "branches",
|
||||
Key: 'f',
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleGitFetch,
|
||||
Description: gui.Tr.SLocalize("fetch"),
|
||||
}, {
|
||||
ViewName: "branches",
|
||||
Key: 'n',
|
||||
|
@ -413,11 +413,8 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
||||
ID: "NoBranchOnRemote",
|
||||
Other: `Deze branch bestaat niet op de remote. U moet het eerst naar de remote pushen.`,
|
||||
}, &i18n.Message{
|
||||
ID: "RepoRequiresCredentialsTitle",
|
||||
Other: `Repo heeft inloggegevens nodig`,
|
||||
}, &i18n.Message{
|
||||
ID: "RepoRequiresCredentialsBody",
|
||||
Other: `Lazygit heeft inloggegevens nodig om git fetch te kunnen gebruiken`,
|
||||
ID: "fetch",
|
||||
Other: `fetch`,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -421,11 +421,8 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
||||
ID: "NoBranchOnRemote",
|
||||
Other: `This branch doesn't exist on remote. You need to push it to remote first.`,
|
||||
}, &i18n.Message{
|
||||
ID: "RepoRequiresCredentialsTitle",
|
||||
Other: `Repo requires credentials`,
|
||||
}, &i18n.Message{
|
||||
ID: "RepoRequiresCredentialsBody",
|
||||
Other: `Lazygit needs credentials to use git fetch`,
|
||||
ID: "fetch",
|
||||
Other: `fetch`,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -396,11 +396,8 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
||||
ID: "NoBranchOnRemote",
|
||||
Other: `Ta gałąź nie istnieje na zdalnym. Najpierw musisz go odepchnąć na odległość.`,
|
||||
}, &i18n.Message{
|
||||
ID: "RepoRequiresCredentialsTitle",
|
||||
Other: `Repo requires credentials`,
|
||||
}, &i18n.Message{
|
||||
ID: "RepoRequiresCredentialsBody",
|
||||
Other: `Lazygit needs credentials to use git fetch`,
|
||||
ID: "fetch",
|
||||
Other: `fetch`,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user