-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs with multiple configured remotes; debug-log return code
Pull Request: #18 (main)
- Loading branch information
Showing
4 changed files
with
99 additions
and
33 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from platform import python_version | ||
from shutil import rmtree | ||
from subprocess import Popen, check_output, CalledProcessError, STDOUT, PIPE | ||
from typing import Literal | ||
from unittest import TestCase | ||
|
||
GIT_GROK_PATH = dirname(dirname(realpath(__file__))) + "/git-grok" | ||
|
@@ -42,14 +43,18 @@ def check_output_x(*cmd: str) -> str: | |
) from None | ||
|
||
|
||
def git_init_and_cd_to_test_dir(*, dir: str, initial_branch: str): | ||
def git_init_and_cd_to_test_dir( | ||
*, | ||
dir: str, | ||
initial_branch: str, | ||
method: Literal["push.default", "set-upstream"], | ||
): | ||
rmtree(dir, ignore_errors=True) | ||
mkdir(dir) | ||
chdir(dir) | ||
check_output_x("git", "init", f"--initial-branch={initial_branch}") | ||
check_output_x("git", "config", "user.name", "tests") | ||
check_output_x("git", "config", "user.email", "[email protected]") | ||
check_output_x("git", "config", "push.default", "current") | ||
check_output_x( | ||
"git", | ||
"remote", | ||
|
@@ -73,7 +78,14 @@ def git_init_and_cd_to_test_dir(*, dir: str, initial_branch: str): | |
environ["GH_TOKEN"] = token | ||
|
||
check_output_x("git", "commit", "--allow-empty", "-m", "Initial commit") | ||
git_push() | ||
|
||
if method == "push.default": | ||
check_output_x("git", "config", "push.default", "current") | ||
check_output_x("git", "push", "-f", TEST_REMOTE) | ||
elif method == "set-upstream": | ||
check_output_x( | ||
"git", "push", "-f", "--set-upstream", TEST_REMOTE, initial_branch | ||
) | ||
|
||
check_output_x("git", "fetch") | ||
branches = [ | ||
|
@@ -111,7 +123,7 @@ def git_add_commit(msg: str): | |
|
||
|
||
def git_push(): | ||
check_output_x("git", "push", "-f", TEST_REMOTE) | ||
check_output_x("git", "push", "-f", "--set-upstream", TEST_REMOTE) | ||
|
||
|
||
def git_get_prs(branch: str) -> str: | ||
|
@@ -171,12 +183,20 @@ def setUp(self): | |
) | ||
self.cwd = getcwd() | ||
self.initial_branch = f"{prefix}tests{python_version()}" | ||
git_init_and_cd_to_test_dir( | ||
dir="/tmp/git-grok-tests", initial_branch=self.initial_branch | ||
) | ||
|
||
def tearDown(self): | ||
chdir(self.cwd) | ||
|
||
def git_init_and_cd_to_test_dir( | ||
self, | ||
*, | ||
method: Literal["push.default", "set-upstream"] = "set-upstream", | ||
): | ||
git_init_and_cd_to_test_dir( | ||
dir="/tmp/git-grok-tests", | ||
initial_branch=self.initial_branch, | ||
method=method, | ||
) | ||
|
||
|
||
git_grok = import_path(GIT_GROK_PATH) |
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,26 @@ | ||
__import__("sys").dont_write_bytecode = True | ||
from helpers import ( | ||
TestCaseWithEmptyTestRepo, | ||
git_add_commit, | ||
git_touch, | ||
run_git_grok, | ||
) | ||
from unittest import main | ||
|
||
|
||
class Test(TestCaseWithEmptyTestRepo): | ||
def test_set_upstream(self): | ||
self.git_init_and_cd_to_test_dir(method="set-upstream") | ||
git_touch("commit01") | ||
git_add_commit("commit01") | ||
run_git_grok(skip_update_prs=True) | ||
|
||
def test_push_default(self): | ||
self.git_init_and_cd_to_test_dir(method="push.default") | ||
git_touch("commit01") | ||
git_add_commit("commit01") | ||
run_git_grok(skip_update_prs=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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