summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authormjarkk <mkopenga@gmail.com>2018-12-02 14:58:18 +0100
committermjarkk <mkopenga@gmail.com>2018-12-02 14:58:18 +0100
commit2edd2b74ff68d6f55172c728e9d5f0d2aea69684 (patch)
treec99aadba94b9a30ffe8127c3f8622cf95f4b7f88 /pkg
parentd91493b5876aeb644dab18b4c41b0ae56fb2f94b (diff)
Removed a lot of useless code
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git.go47
-rw-r--r--pkg/gui/branches_panel.go5
-rw-r--r--pkg/gui/gui.go47
-rw-r--r--pkg/gui/keybindings.go6
-rw-r--r--pkg/i18n/dutch.go7
-rw-r--r--pkg/i18n/english.go7
-rw-r--r--pkg/i18n/polish.go7
7 files changed, 32 insertions, 94 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 9fd675baf..2d2710a42 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -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
- }
- if question == "password" && len(c.SavedCredentials.Password) != 0 {
- return c.SavedCredentials.Password
+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)
}
- 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
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index dbf4b007a..c62538d5c 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -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")
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 69343a95d..872a00c37 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -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)
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index e460e4a1c..b926853ba 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -297,6 +297,12 @@ func (gui *Gui) GetKeybindings() []*Binding {
Description: gui.Tr.SLocalize("forceCheckout"),
}, {
ViewName: "branches",
+ Key: 'f',
+ Modifier: gocui.ModNone,
+ Handler: gui.handleGitFetch,
+ Description: gui.Tr.SLocalize("fetch"),
+ }, {
+ ViewName: "branches",
Key: 'n',
Modifier: gocui.ModNone,
Handler: gui.handleNewBranch,
diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go
index 86b679692..5f9e4bf34 100644
--- a/pkg/i18n/dutch.go
+++ b/pkg/i18n/dutch.go
@@ -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`,
},
)
}
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index 07dbeaffe..929e8834d 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -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`,
},
)
}
diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go
index 11c4b574b..ec59288fa 100644
--- a/pkg/i18n/polish.go
+++ b/pkg/i18n/polish.go
@@ -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`,
},
)
}