Skip to content

Commit d503664

Browse files
committed
fix: 切换分支前还需要获取远程分支
1 parent 35a7328 commit d503664

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

src/plugins/publish/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,6 @@ async def handle_auto_merge(
270270
).parsed_data
271271

272272
if not pull_request.mergeable:
273-
# 需要先获取远程分支,否则无法切换到对应分支
274-
run_shell_command(
275-
["git", "fetch", "origin", plugin_config.input_config.base]
276-
)
277273
# 尝试处理冲突
278274
await resolve_conflict_pull_requests([pull_request])
279275

src/plugins/publish/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ async def resolve_conflict_pull_requests(
275275

276276
publish_type = get_type_by_labels(pull.labels)
277277
if publish_type:
278+
# 需要先获取远程分支,否则无法切换到对应分支
279+
run_shell_command(["git", "fetch", "origin"])
278280
# 因为当前分支为触发处理冲突的分支,所以需要切换到每个拉取请求对应的分支
279281
run_shell_command(["git", "checkout", pull.head.ref])
280282
# 获取数据

tests/publish/process/test_auto_merge.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ async def test_auto_merge_need_rebase(app: App, mocker: MockerFixture) -> None:
158158
["git", "config", "--global", "safe.directory", "*"],
159159
check=True,
160160
capture_output=True,
161-
),
162-
mocker.call(
163-
["git", "fetch", "origin", "master"],
164-
check=True,
165-
capture_output=True,
166161
), # type: ignore
167162
],
168163
any_order=True,

tests/publish/utils/test_resolve_conflict_pull_requests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ async def test_resolve_conflict_pull_requests_adapter(
6565
# 测试 git 命令
6666
mock_subprocess_run.assert_has_calls(
6767
[
68+
mocker.call(["git", "fetch", "origin"], check=True, capture_output=True),
6869
mocker.call(
6970
["git", "checkout", "publish/issue1"], check=True, capture_output=True
7071
),
@@ -188,6 +189,7 @@ async def test_resolve_conflict_pull_requests_bot(
188189
# 测试 git 命令
189190
mock_subprocess_run.assert_has_calls(
190191
[
192+
mocker.call(["git", "fetch", "origin"], check=True, capture_output=True),
191193
mocker.call(
192194
["git", "checkout", "publish/issue1"], check=True, capture_output=True
193195
),
@@ -311,6 +313,7 @@ async def test_resolve_conflict_pull_requests_plugin(
311313
# 测试 git 命令
312314
mock_subprocess_run.assert_has_calls(
313315
[
316+
mocker.call(["git", "fetch", "origin"], check=True, capture_output=True),
314317
mocker.call(
315318
["git", "checkout", "publish/issue1"], check=True, capture_output=True
316319
),

0 commit comments

Comments
 (0)