From bb1da19878be3e92c7652d999c90eb93fbd8df87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Tue, 24 Oct 2023 09:00:15 +0200 Subject: [PATCH] Push tags (#1279) * Push tags * lint the code --- jupyterlab_git/git.py | 3 +++ jupyterlab_git/tests/test_pushpull.py | 38 ++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/jupyterlab_git/git.py b/jupyterlab_git/git.py index 5454db9f9..63d9f70c3 100644 --- a/jupyterlab_git/git.py +++ b/jupyterlab_git/git.py @@ -1235,11 +1235,14 @@ async def push( auth=None, set_upstream=False, force=False, + tags=True, ): """ Execute `git push $UPSTREAM $BRANCH`. The choice of upstream and branch is up to the caller. """ command = ["git", "push"] + if tags: + command.append("--tags") if force: command.append("--force-with-lease") if set_upstream: diff --git a/jupyterlab_git/tests/test_pushpull.py b/jupyterlab_git/tests/test_pushpull.py index 2ef32e546..290ba8caf 100644 --- a/jupyterlab_git/tests/test_pushpull.py +++ b/jupyterlab_git/tests/test_pushpull.py @@ -313,7 +313,7 @@ async def test_git_push_fail(): # Then mock_execute.assert_called_once_with( - ["git", "push", "test_origin", "HEAD:test_master"], + ["git", "push", "--tags", "test_origin", "HEAD:test_master"], cwd="test_curr_path", timeout=20, env={"TEST": "test", "GIT_TERMINAL_PROMPT": "0"}, @@ -345,7 +345,7 @@ async def test_git_push_with_auth_fail(): # Then mock_execute_with_authentication.assert_called_once_with( - ["git", "push", "test_origin", "HEAD:test_master"], + ["git", "push", "--tags", "test_origin", "HEAD:test_master"], cwd="test_curr_path", timeout=20, env={"TEST": "test", "GIT_TERMINAL_PROMPT": "1"}, @@ -374,7 +374,7 @@ async def test_git_push_success(): # Then mock_execute.assert_called_once_with( - ["git", "push", ".", "HEAD:test_master"], + ["git", "push", "--tags", ".", "HEAD:test_master"], cwd="test_curr_path", timeout=20, env={"TEST": "test", "GIT_TERMINAL_PROMPT": "0"}, @@ -403,7 +403,7 @@ async def test_git_push_with_auth_success(): # Then mock_execute_with_authentication.assert_called_once_with( - ["git", "push", ".", "HEAD:test_master"], + ["git", "push", "--tags", ".", "HEAD:test_master"], cwd="test_curr_path", timeout=20, env={"TEST": "test", "GIT_TERMINAL_PROMPT": "1"}, @@ -466,7 +466,7 @@ async def test_git_push_with_auth_and_cache_credentials(): is_binary=False, ), call( - ["git", "push", ".", "HEAD:test_master"], + ["git", "push", "--tags", ".", "HEAD:test_master"], cwd=test_path, timeout=20, env={**os.environ, "GIT_TERMINAL_PROMPT": "1"}, @@ -511,7 +511,7 @@ async def test_git_push_with_auth_and_cache_credentials_and_existing_credential_ is_binary=False, ), call( - ["git", "push", ".", "HEAD:test_master"], + ["git", "push", "--tags", ".", "HEAD:test_master"], cwd=test_path, timeout=20, env={**os.environ, "GIT_TERMINAL_PROMPT": "1"}, @@ -522,3 +522,29 @@ async def test_git_push_with_auth_and_cache_credentials_and_existing_credential_ ] ) assert {"code": 0, "message": ""} == actual_response + + +@pytest.mark.asyncio +async def test_git_push_no_tags_success(): + with patch("os.environ", {"TEST": "test"}): + with patch("jupyterlab_git.git.execute") as mock_execute: + # Given + output = "output" + mock_execute.return_value = maybe_future((0, output, "does not matter")) + + # When + actual_response = await Git().push( + ".", "HEAD:test_master", "test_curr_path", tags=False + ) + + # Then + mock_execute.assert_called_once_with( + ["git", "push", ".", "HEAD:test_master"], + cwd="test_curr_path", + timeout=20, + env={"TEST": "test", "GIT_TERMINAL_PROMPT": "0"}, + username=None, + password=None, + is_binary=False, + ) + assert {"code": 0, "message": output} == actual_response