handle when repo is not set

This commit is contained in:
Yuki Osaki 2021-11-03 00:09:56 +09:00
parent 2b8c959cb0
commit 588bd95118
5 changed files with 75 additions and 3 deletions

View file

@ -85,3 +85,18 @@ func (c *GitCommand) GetRemotesToOwnersMap() (map[string]string, error) {
}
return res, nil
}
func (c *GitCommand) GetRemotesToRepositoryMap() (map[string]string, error) {
remotes, err := c.GetRemotes()
if err != nil {
return nil, err
}
res := map[string]string{}
for _, remote := range remotes {
info := GetRepoInfoFromURL(remote.Urls[0])
res[info.Owner] = info.Repository
}
return res, nil
}

View file

@ -76,13 +76,47 @@ func (gui *Gui) refreshBranches() {
}
func (gui *Gui) refreshGithubPullRequests() {
prs, err := gui.GitCommand.GithubMostRecentPRs()
if err != nil {
_ = gui.surfaceError(err)
_, err := gui.GitCommand.RunCommandWithOutput("git config --local --get-regexp .gh-resolved$")
if err == nil {
_ = gui.setGithubPullRequests()
return
}
// when config not exits
_ = gui.refreshRemotes()
_ = gui.prompt(promptOpts{
title: "Select remote Repository",
initialContent: "",
findSuggestionsFunc: gui.getRemoteUrlSuggestionsFunc(),
handleConfirm: func(repository string) error {
return gui.WithWaitingStatus(gui.Tr.SelectRemoteRepository, func() error {
// ex git config --local --add "remote.origin.gh-resolved" "jesseduffield/lazygit"
_, err := gui.GitCommand.RunCommandWithOutput(fmt.Sprintf("git config --local --add \"remote.origin.gh-resolved\" \"%s\"", repository))
if err != nil {
return err
}
err = gui.setGithubPullRequests()
if err != nil {
return err
}
_ = gui.postRefreshUpdate(gui.State.Contexts.Branches)
return nil
})
},
})
}
func (gui *Gui) setGithubPullRequests() error {
prs, err := gui.GitCommand.GithubMostRecentPRs()
if err != nil {
return gui.surfaceError(err)
}
gui.State.GithubState.RecentPRs = prs
return nil
}
// specific functions

View file

@ -29,6 +29,15 @@ func (gui *Gui) getRemoteNames() []string {
return result
}
// func (gui *Gui) getRemoteUrls() []string {
// result := make([]string, len(gui.State.Remotes))
// for i, remote := range gui.State.Remotes {
// result[i] = remote.Urls[0]
// gui.GitCommand.GetRemotesToOwnersMap()
// }
// return result
// }
func matchesToSuggestions(matches []string) []*types.Suggestion {
suggestions := make([]*types.Suggestion, len(matches))
for i, match := range matches {
@ -46,6 +55,17 @@ func (gui *Gui) getRemoteSuggestionsFunc() func(string) []*types.Suggestion {
return fuzzySearchFunc(remoteNames)
}
func (gui *Gui) getRemoteUrlSuggestionsFunc() func(string) []*types.Suggestion {
remotesToOwnersMap, _ := gui.GitCommand.GetRemotesToRepositoryMap()
result := make([]string, len(remotesToOwnersMap))
i := 0
for owner, repository := range remotesToOwnersMap {
result[i] = owner + "/" + repository
i++
}
return fuzzySearchFunc(result)
}
func (gui *Gui) getBranchNames() []string {
result := make([]string, len(gui.State.Branches))
for i, branch := range gui.State.Branches {

View file

@ -433,6 +433,7 @@ func chineseTranslationSet() TranslationSet {
FocusCommandLog: "焦点命令日志",
CommandLogHeader: "您可以通过按 '%s' 隐藏或集中显示该面板,或使用 `gui.showCommandLog: false`\n将其永久隐藏在您的配置中",
RandomTip: "随机提示",
SelectRemoteRepository: "选择存储库",
SelectParentCommitForMerge: "选择父提交进行合并",
ToggleWhitespaceInDiffView: "切换是否在差异视图中显示空白更改",
IgnoringWhitespaceInDiffView: "差异视图中的空格将被忽略",

View file

@ -440,6 +440,7 @@ type TranslationSet struct {
OpenPr string
AbortTitle string
AbortPrompt string
SelectRemoteRepository string
Spans Spans
}
@ -943,6 +944,7 @@ func englishTranslationSet() TranslationSet {
SuggestionsTitle: "Suggestions (press %s to focus)",
ExtrasTitle: "Extras",
PushingTagStatus: "pushing tag",
SelectRemoteRepository: "Select Remote Repository",
PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard",
CommitMessageCopiedToClipboard: "Commit message copied to clipboard",
LcCopiedToClipboard: "copied to clipboard",