Skip to content

Commit 147f8be

Browse files
authored
refactor: Change git status to skip for unpushed commits check (#175)
1 parent 86c77c0 commit 147f8be

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

plugins/titan-plugin-git/tests/test_git_plugin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# plugins/titan-plugin-git/tests/test_git_plugin.py
22
from unittest.mock import MagicMock
3-
from titan_cli.engine import WorkflowContext, is_success, is_error, is_skip, is_exit, Skip
3+
from titan_cli.engine import WorkflowContext, is_success, is_error, is_skip, Skip
44
from titan_cli.core.result import ClientSuccess, ClientError
55
from titan_plugin_git.steps.status_step import get_git_status_step
66
from titan_plugin_git.steps.commit_step import create_git_commit_step
@@ -40,9 +40,10 @@ def test_get_git_status_step_success():
4040
mock_git_client.get_status.assert_called_once()
4141

4242

43-
def test_get_git_status_step_exit_when_clean():
43+
def test_get_git_status_step_skip_when_clean():
4444
"""
45-
Test that get_git_status_step returns Exit when the working directory is clean.
45+
Test that get_git_status_step returns Skip when the working directory is clean,
46+
allowing the workflow to continue to the push step.
4647
"""
4748
# 1. Arrange
4849
mock_git_client = MagicMock(spec=GitClient)
@@ -68,7 +69,7 @@ def test_get_git_status_step_exit_when_clean():
6869
result = get_git_status_step(mock_context)
6970

7071
# 3. Assert
71-
assert is_exit(result)
72+
assert is_skip(result)
7273
assert "No changes to commit" in result.message
7374
assert result.metadata['git_status'] == mock_status
7475
mock_git_client.get_status.assert_called_once()

plugins/titan-plugin-git/titan_plugin_git/steps/push_step.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# plugins/titan-plugin-git/titan_plugin_git/steps/push_step.py
2-
from titan_cli.engine import WorkflowContext, WorkflowResult, Success, Error
2+
from titan_cli.engine import WorkflowContext, WorkflowResult, Success, Error, Exit
33
from titan_cli.core.result import ClientSuccess, ClientError
44
from titan_plugin_git.messages import msg
55

@@ -57,9 +57,24 @@ def create_git_push_step(ctx: WorkflowContext) -> WorkflowResult:
5757
exists_result = ctx.git.branch_exists_on_remote(branch=branch_to_use, remote=remote_to_use)
5858
match exists_result:
5959
case ClientSuccess(data=exists):
60-
# The first push of a branch should set the upstream
6160
if not exists:
61+
# The first push of a branch should set the upstream
6262
set_upstream = True
63+
else:
64+
# Branch exists on remote — check if there's anything to push
65+
unpushed_result = ctx.git.count_unpushed_commits(branch=branch_to_use, remote=remote_to_use)
66+
match unpushed_result:
67+
case ClientSuccess(data=unpushed_count):
68+
if unpushed_count == 0:
69+
ctx.textual.success_text(f"Branch {branch_to_use} is already up to date with {remote_to_use}")
70+
ctx.textual.end_step("success")
71+
return Exit(
72+
"Branch already pushed",
73+
metadata={"pr_head_branch": branch_to_use}
74+
)
75+
case ClientError():
76+
# If we can't count, proceed with push anyway
77+
pass
6378
case ClientError(error_message=err):
6479
ctx.textual.end_step("error")
6580
return Error(f"Failed to check remote branch: {err}")

plugins/titan-plugin-git/titan_plugin_git/steps/status_step.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
WorkflowResult,
55
Success,
66
Error,
7-
Exit
7+
Skip
88
)
99
from titan_cli.core.result import ClientSuccess, ClientError
1010
from titan_cli.messages import msg as global_msg
@@ -16,7 +16,8 @@ def get_git_status_step(ctx: WorkflowContext) -> WorkflowResult:
1616
1717
Behavior:
1818
- If there are uncommitted changes: Returns Success and continues workflow
19-
- If working directory is clean: Returns Exit (stops workflow - nothing to commit)
19+
- If working directory is clean: Returns Skip so the workflow continues to
20+
the push step, which decides whether to push unpushed commits or exit.
2021
2122
Requires:
2223
ctx.git: An initialized GitClient.
@@ -26,7 +27,7 @@ def get_git_status_step(ctx: WorkflowContext) -> WorkflowResult:
2627
2728
Returns:
2829
Success: If there are changes to commit (workflow continues)
29-
Exit: If working directory is clean (workflow stops - nothing to commit)
30+
Skip: If working directory is clean (workflow continues to push step)
3031
Error: If the GitClient is not available or the git command fails.
3132
"""
3233
if not ctx.textual:
@@ -54,14 +55,11 @@ def get_git_status_step(ctx: WorkflowContext) -> WorkflowResult:
5455
metadata={"git_status": status}
5556
)
5657
else:
57-
# Working directory is clean - exit workflow (nothing to commit)
58+
# Working directory is clean - skip to push step to check for unpushed commits
5859
ctx.textual.success_text(msg.Steps.Status.WORKING_DIRECTORY_IS_CLEAN)
59-
ctx.textual.text("")
60-
ctx.textual.dim_text("Nothing to commit. Skipping workflow.")
6160
ctx.textual.end_step("success")
6261

63-
# Exit workflow early (not an error)
64-
return Exit("No changes to commit", metadata={"git_status": status})
62+
return Skip("No changes to commit", metadata={"git_status": status})
6563

6664
case ClientError(error_message=err):
6765
# End step container with error

0 commit comments

Comments
 (0)