-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/gui: Allow user to select remote and branch when creating a PR
When creating a PR against a selected branch (via O = "create pull request options"), the user will first be asked to select a remote (if there is more than one). After that, the suggestion area is populated with all remote branches at that origin - instead of all local ones. After all, creating a PR against a branch that doesn't exist on the remote won't work. Please note that for the "PR is not filed against 'origin' remote" use case (e.g. when contributing via a fork that is 'origin' to a GitHub project that is 'upstream'), the opened URL will not be correct. This is not a regression and will be fixed in an upcoming PR. Fixes #1826.
- Loading branch information
1 parent
b62546c
commit 949e131
Showing
6 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
pkg/integration/tests/branch/open_pull_request_invalid_target_remote_name.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package branch | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var OpenPullRequestInvalidTargetRemoteName = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Open up a pull request, specifying a non-existing target remote", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) {}, | ||
SetupRepo: func(shell *Shell) { | ||
// Create an initial commit ('git branch set-upstream-to' bails out otherwise) | ||
shell.CreateFileAndAdd("file", "content1") | ||
shell.Commit("one") | ||
|
||
// Create a new branch | ||
shell.NewBranch("branch-1") | ||
|
||
// Create a couple of remotes | ||
shell.CloneIntoRemote("upstream") | ||
shell.CloneIntoRemote("origin") | ||
|
||
// To allow a pull request to be created from a branch, it must have an upstream set. | ||
shell.SetBranchUpstream("branch-1", "origin/branch-1") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
// Open a PR for the current branch (i.e. 'branch-1') | ||
t.Views(). | ||
Branches(). | ||
Focus(). | ||
Press(keys.Branches.ViewPullRequestOptions) | ||
|
||
t.ExpectPopup(). | ||
Menu(). | ||
Title(Equals("View create pull request options")). | ||
Select(Contains("Select branch")). | ||
Confirm() | ||
|
||
// Verify that we're prompted to enter the remote and enter the name of a non-existing one. | ||
t.ExpectPopup(). | ||
Prompt(). | ||
Title(Equals("Select target remote")). | ||
Type("non-existing-remote"). | ||
Confirm() | ||
|
||
// Verify that this leads to an error being shown (instead of progressing to branch selection). | ||
t.ExpectPopup().Alert(). | ||
Title(Equals("Error")). | ||
Content(Contains("A remote named 'non-existing-remote' does not exist")). | ||
Confirm() | ||
}, | ||
}) |
74 changes: 74 additions & 0 deletions
74
pkg/integration/tests/branch/open_pull_request_select_remote_and_target_branch.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package branch | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var OpenPullRequestSelectRemoteAndTargetBranch = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Open up a pull request, specifying a remote and target branch", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) { | ||
config.GetUserConfig().OS.OpenLink = "echo {{link}} > /tmp/openlink" | ||
}, | ||
SetupRepo: func(shell *Shell) { | ||
// Create an initial commit ('git branch set-upstream-to' bails out otherwise) | ||
shell.CreateFileAndAdd("file", "content1") | ||
shell.Commit("one") | ||
|
||
// Create a new branch and a remote that has that branch | ||
shell.NewBranch("branch-1") | ||
shell.CloneIntoRemote("upstream") | ||
|
||
// Create another branch and a second remote. The first remote doesn't have this branch. | ||
shell.NewBranch("branch-2") | ||
shell.CloneIntoRemote("origin") | ||
|
||
// To allow a pull request to be created from a branch, it must have an upstream set. | ||
shell.SetBranchUpstream("branch-2", "origin/branch-2") | ||
|
||
shell.RunCommand([]string{"git", "remote", "set-url", "origin", "https://github.com/my-personal-fork/lazygit"}) | ||
shell.RunCommand([]string{"git", "remote", "set-url", "upstream", "https://github.com/jesseduffield/lazygit"}) | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
// Open a PR for the current branch (i.e. 'branch-2') | ||
t.Views(). | ||
Branches(). | ||
Focus(). | ||
Press(keys.Branches.ViewPullRequestOptions) | ||
|
||
t.ExpectPopup(). | ||
Menu(). | ||
Title(Equals("View create pull request options")). | ||
Select(Contains("Select branch")). | ||
Confirm() | ||
|
||
// Verify that we're prompted to enter the remote | ||
t.ExpectPopup(). | ||
Prompt(). | ||
Title(Equals("Select target remote")). | ||
SuggestionLines( | ||
Equals("origin"), | ||
Equals("upstream")). | ||
ConfirmSuggestion(Equals("upstream")) | ||
|
||
// Verify that we're prompted to enter the target branch and that only those branches | ||
// present in the selected remote are listed as suggestions (i.e. 'branch-2' is not there). | ||
t.ExpectPopup(). | ||
Prompt(). | ||
Title(Equals("branch-2 → upstream/")). | ||
SuggestionLines( | ||
Equals("branch-1"), | ||
Equals("master")). | ||
ConfirmSuggestion(Equals("master")) | ||
|
||
// Verify that the expected URL is used (by checking the openlink file) | ||
// | ||
// Please note that when targeting a different remote - like it's done here in this test - | ||
// the link is not yet correct. Thus, this test is expected to fail once this is fixed. | ||
t.FileSystem().FileContent( | ||
"/tmp/openlink", | ||
Equals("https://github.com/my-personal-fork/lazygit/compare/master...branch-2?expand=1\n")) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters