From 031e97ef91654a53e7e534e7d4aa032e06eee319 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 12 Oct 2020 19:04:20 +1100 Subject: more password checks on commands that talk to the remote --- pkg/commands/remotes.go | 7 +++++-- pkg/commands/tags.go | 7 +++++-- pkg/gui/remote_branches_panel.go | 5 ++--- pkg/gui/remotes_panel.go | 1 - pkg/gui/tags_panel.go | 10 ++++++---- pkg/i18n/english.go | 2 ++ 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pkg/commands/remotes.go b/pkg/commands/remotes.go index 6d69b37cd..779ce9e2b 100644 --- a/pkg/commands/remotes.go +++ b/pkg/commands/remotes.go @@ -1,6 +1,8 @@ package commands import ( + "fmt" + "github.com/jesseduffield/lazygit/pkg/commands/models" ) @@ -20,8 +22,9 @@ func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error return c.OSCommand.RunCommand("git remote set-url %s %s", remoteName, updatedUrl) } -func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string) error { - return c.OSCommand.RunCommand("git push %s --delete %s", remoteName, branchName) +func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string, promptUserForCredential func(string) string) error { + command := fmt.Sprintf("git push %s --delete %s", remoteName, branchName) + return c.OSCommand.DetectUnamePass(command, promptUserForCredential) } // CheckRemoteBranchExists Returns remote branch diff --git a/pkg/commands/tags.go b/pkg/commands/tags.go index f7b26d8df..121637311 100644 --- a/pkg/commands/tags.go +++ b/pkg/commands/tags.go @@ -1,5 +1,7 @@ package commands +import "fmt" + func (c *GitCommand) CreateLightweightTag(tagName string, commitSha string) error { return c.OSCommand.RunCommand("git tag %s %s", tagName, commitSha) } @@ -8,6 +10,7 @@ func (c *GitCommand) DeleteTag(tagName string) error { return c.OSCommand.RunCommand("git tag -d %s", tagName) } -func (c *GitCommand) PushTag(remoteName string, tagName string) error { - return c.OSCommand.RunCommand("git push %s %s", remoteName, tagName) +func (c *GitCommand) PushTag(remoteName string, tagName string, promptUserForCredential func(string) string) error { + command := fmt.Sprintf("git push %s %s", remoteName, tagName) + return c.OSCommand.DetectUnamePass(command, promptUserForCredential) } diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index 1155529ce..582ed749d 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -60,9 +60,8 @@ func (gui *Gui) handleDeleteRemoteBranch(g *gocui.Gui, v *gocui.View) error { prompt: message, handleConfirm: func() error { return gui.WithWaitingStatus(gui.Tr.DeletingStatus, func() error { - if err := gui.GitCommand.DeleteRemoteBranch(remoteBranch.RemoteName, remoteBranch.Name); err != nil { - return err - } + err := gui.GitCommand.DeleteRemoteBranch(remoteBranch.RemoteName, remoteBranch.Name, gui.promptUserForCredential) + gui.handleCredentialsPopup(err) return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}}) }) diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index f3c984d78..76ca536cb 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -166,7 +166,6 @@ func (gui *Gui) handleFetchRemote(g *gocui.Gui, v *gocui.View) error { gui.Mutexes.FetchMutex.Lock() defer gui.Mutexes.FetchMutex.Unlock() - // TODO: test this err := gui.GitCommand.FetchRemote(remote.Name, gui.promptUserForCredential) gui.handleCredentialsPopup(err) diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go index 6478dc016..6f9004e4d 100644 --- a/pkg/gui/tags_panel.go +++ b/pkg/gui/tags_panel.go @@ -98,10 +98,12 @@ func (gui *Gui) handlePushTag(g *gocui.Gui, v *gocui.View) error { ) return gui.prompt(title, "origin", func(response string) error { - if err := gui.GitCommand.PushTag(response, tag.Name); err != nil { - return gui.surfaceError(err) - } - return nil + return gui.WithWaitingStatus(gui.Tr.PushingTagStatus, func() error { + err := gui.GitCommand.PushTag(response, tag.Name, gui.promptUserForCredential) + gui.handleCredentialsPopup(err) + + return nil + }) }) } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 98d15574e..30548cc0d 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -427,6 +427,7 @@ type TranslationSet struct { SubCommitsTitle string SubmodulesTitle string NavigationTitle string + PushingTagStatus string } const englishReleaseNotes = `## lazygit 0.23.2 Release Notes @@ -924,5 +925,6 @@ func englishTranslationSet() TranslationSet { SubCommitsTitle: "Sub-commits", SubmodulesTitle: "Submodules", NavigationTitle: "List Panel Navigation", + PushingTagStatus: "pushing tag", } } -- cgit v1.2.3