-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: detect target branch using standard Git configuration
The current code forces the user to choose a single target branch which prevents stacks from working on multiple target branches. This leverage the standard git configuration to retrieve the target branch. Change-Id: Ia1455d68eaa76af503b6e6cf4c24c19efcdd9b7b
- Loading branch information
Showing
3 changed files
with
80 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,16 @@ def _change_working_directory( | |
monkeypatch.chdir(tmp_path) | ||
|
||
|
||
@pytest.fixture() | ||
def _git_repo() -> None: | ||
subprocess.call(["git", "init", "--initial-branch=main"]) | ||
subprocess.call(["git", "config", "user.email", "[email protected]"]) | ||
subprocess.call(["git", "config", "user.name", "Test User"]) | ||
subprocess.call(["git", "commit", "--allow-empty", "-m", "Initial commit"]) | ||
subprocess.call(["git", "config", "--add", "branch.main.merge", "refs/heads/main"]) | ||
subprocess.call(["git", "config", "--add", "branch.main.remote", "origin"]) | ||
|
||
|
||
@pytest.fixture() | ||
def git_mock( | ||
tmp_path: pathlib.Path, | ||
|
@@ -58,6 +68,7 @@ def git_mock( | |
yield git_mock_object | ||
|
||
|
||
@pytest.mark.usefixtures("_git_repo") | ||
def test_cli_help(capsys: pytest.CaptureFixture[str]) -> None: | ||
with pytest.raises(SystemExit, match="0"): | ||
mergify_cli.parse_args(["--help"]) | ||
|
@@ -68,6 +79,26 @@ def test_cli_help(capsys: pytest.CaptureFixture[str]) -> None: | |
assert "options:" in stdout | ||
|
||
|
||
@pytest.mark.usefixtures("_git_repo") | ||
def test_get_branch_name() -> None: | ||
assert mergify_cli.git_get_branch_name() == "main" | ||
|
||
|
||
@pytest.mark.usefixtures("_git_repo") | ||
def test_get_target_branch() -> None: | ||
assert mergify_cli.git_get_target_branch("main") == "main" | ||
|
||
|
||
@pytest.mark.usefixtures("_git_repo") | ||
def test_get_remote_for_branch() -> None: | ||
assert mergify_cli.git_get_remote_for_branch("main") == "origin" | ||
|
||
|
||
@pytest.mark.usefixtures("_git_repo") | ||
def test_get_trunk() -> None: | ||
assert mergify_cli.get_trunk() == "origin/main" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"valid_branch_name", | ||
[ | ||
|
@@ -533,7 +564,6 @@ async def test_stack_without_common_commit_raises_an_error( | |
("default_arg_fct", "config_get_result", "expected_default"), | ||
[ | ||
(mergify_cli.get_default_keep_pr_title_body, b"true", True), | ||
(mergify_cli.get_trunk, "dummy-origin/main", "dummy-origin/main"), | ||
(mergify_cli.get_default_branch_prefix, b"dummy-prefix", "dummy-prefix"), | ||
], | ||
) | ||
|
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