diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-09-25 11:03:15 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-25 11:03:15 +1000 |
commit | 41ab7c44a06c128c993fc69a6a4b421b5e2e9405 (patch) | |
tree | 088d292474eef524e1796c18523d6e26f64e12c2 | |
parent | 3589a43682b945cb454715a81a259b8ef2b02e5b (diff) | |
parent | 4d258bd98144eed7c9e955de6f2b8bb6379aa92b (diff) |
Use upstream branch when opening pull requests (#2693)
- **PR Description**
Should probably solve #2691
- **Please check if the PR fulfills these requirements**
* [x] Cheatsheets are up-to-date (run `go run scripts/cheatsheet/main.go
generate`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [x] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [x] Docs (specifically `docs/Config.md`) have been updated if
necessary
* [x] You've read through your own file changes for silly mistakes etc
-rw-r--r-- | pkg/gui/controllers/branches_controller.go | 14 | ||||
-rw-r--r-- | pkg/i18n/english.go | 2 | ||||
-rw-r--r-- | pkg/integration/tests/branch/open_pull_request_no_upstream.go | 25 | ||||
-rw-r--r-- | pkg/integration/tests/test_list.go | 1 |
4 files changed, 38 insertions, 4 deletions
diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index daecc5e38..45f950457 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -318,7 +318,10 @@ func (self *BranchesController) promptToCheckoutWorktree(worktree *models.Worktr } func (self *BranchesController) handleCreatePullRequest(selectedBranch *models.Branch) error { - return self.createPullRequest(selectedBranch.Name, "") + if !selectedBranch.IsTrackingRemote() { + return self.c.ErrorMsg(self.c.Tr.PullRequestNoUpstream) + } + return self.createPullRequest(selectedBranch.UpstreamBranch, "") } func (self *BranchesController) handleCreatePullRequestMenu(selectedBranch *models.Branch) error { @@ -678,7 +681,7 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra { LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.DefaultBranch), OnPress: func() error { - return self.createPullRequest(branch.Name, "") + return self.handleCreatePullRequest(branch) }, }, { @@ -686,7 +689,7 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra OnPress: func() error { return self.c.Prompt(types.PromptOpts{ Title: branch.Name + " →", - FindSuggestionsFunc: self.c.Helpers().Suggestions.GetBranchNameSuggestionsFunc(), + FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRemoteBranchesSuggestionsFunc("/"), HandleConfirm: func(targetBranchName string) error { return self.createPullRequest(branch.Name, targetBranchName) }, @@ -701,7 +704,10 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra &types.MenuItem{ LabelColumns: fromToLabelColumns(checkedOutBranch.Name, selectedBranch.Name), OnPress: func() error { - return self.createPullRequest(checkedOutBranch.Name, selectedBranch.Name) + if !checkedOutBranch.IsTrackingRemote() || !selectedBranch.IsTrackingRemote() { + return self.c.ErrorMsg(self.c.Tr.PullRequestNoUpstream) + } + return self.createPullRequest(checkedOutBranch.UpstreamBranch, selectedBranch.UpstreamBranch) }, }, ) diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index b442af6f6..15deab925 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -221,6 +221,7 @@ type TranslationSet struct { FwdNoUpstream string FwdNoLocalUpstream string FwdCommitsToPush string + PullRequestNoUpstream string ErrorOccurred string NoRoom string YouAreHere string @@ -1019,6 +1020,7 @@ func EnglishTranslationSet() TranslationSet { FwdNoUpstream: "Cannot fast-forward a branch with no upstream", FwdNoLocalUpstream: "Cannot fast-forward a branch whose remote is not registered locally", FwdCommitsToPush: "Cannot fast-forward a branch with commits to push", + PullRequestNoUpstream: "Cannot open a pull request for a branch with no upstream", ErrorOccurred: "An error occurred! Please create an issue at", NoRoom: "Not enough room", YouAreHere: "YOU ARE HERE", diff --git a/pkg/integration/tests/branch/open_pull_request_no_upstream.go b/pkg/integration/tests/branch/open_pull_request_no_upstream.go new file mode 100644 index 000000000..877f0bdde --- /dev/null +++ b/pkg/integration/tests/branch/open_pull_request_no_upstream.go @@ -0,0 +1,25 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var OpenPullRequestNoUpstream = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Open up a pull request with a missing upstream branch", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) {}, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views(). + Branches(). + Focus(). + Press(keys.Branches.CreatePullRequest) + + t.ExpectPopup().Alert(). + Title(Equals("Error")). + Content(Contains("Cannot open a pull request for a branch with no upstream")). + Confirm() + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 535bf55fe..f3b57a5dd 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -40,6 +40,7 @@ var tests = []*components.IntegrationTest{ branch.Delete, branch.DeleteRemoteBranchWithCredentialPrompt, branch.DetachedHead, + branch.OpenPullRequestNoUpstream, branch.OpenWithCliArg, branch.Rebase, branch.RebaseAbortOnConflict, |