gitpane 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gitpane/__init__.py +0 -0
- gitpane/account/__init__.py +0 -0
- gitpane/account/account_choice.py +297 -0
- gitpane/account/address_owner.py +67 -0
- gitpane/account/authentication.py +1811 -0
- gitpane/account/authentication_worker.py +836 -0
- gitpane/account/credential_manager.py +480 -0
- gitpane/account/credential_manager_install.py +171 -0
- gitpane/account/keyring_reader.py +135 -0
- gitpane/account/keyring_state.py +158 -0
- gitpane/account/ssh.py +312 -0
- gitpane/account/ssh_askpass.py +216 -0
- gitpane/account/ssh_prompt.py +222 -0
- gitpane/application.py +684 -0
- gitpane/commit/__init__.py +0 -0
- gitpane/commit/commit_metadata.py +88 -0
- gitpane/commit/commit_push.py +276 -0
- gitpane/commit/commit_write.py +830 -0
- gitpane/config.py +1066 -0
- gitpane/controller/__init__.py +0 -0
- gitpane/controller/account_controller.py +677 -0
- gitpane/controller/clone_controller.py +776 -0
- gitpane/controller/close_readiness.py +212 -0
- gitpane/controller/commit_timing_controller.py +566 -0
- gitpane/controller/conflict_controller.py +885 -0
- gitpane/controller/console_registry.py +38 -0
- gitpane/controller/emoji_window_controller.py +95 -0
- gitpane/controller/file_action_controller.py +479 -0
- gitpane/controller/history_read_controller.py +671 -0
- gitpane/controller/history_rewrite_controller.py +739 -0
- gitpane/controller/navigation_controller.py +658 -0
- gitpane/controller/opening_controller.py +375 -0
- gitpane/controller/operation_policy.py +76 -0
- gitpane/controller/rebase_controller.py +797 -0
- gitpane/controller/rebase_editor_controller.py +309 -0
- gitpane/controller/reference_form_controller.py +1677 -0
- gitpane/controller/reference_read_controller.py +242 -0
- gitpane/controller/refresh_controller.py +477 -0
- gitpane/controller/replay_controller.py +805 -0
- gitpane/controller/session_registry.py +337 -0
- gitpane/controller/setting_controller.py +592 -0
- gitpane/controller/shutdown_controller.py +345 -0
- gitpane/controller/staging_controller.py +199 -0
- gitpane/controller/staging_session_registry.py +47 -0
- gitpane/controller/stash_controller.py +367 -0
- gitpane/controller/transport_controller.py +813 -0
- gitpane/controller/welcome_controller.py +102 -0
- gitpane/controller/window_activation.py +116 -0
- gitpane/controller/worktree_state_controller.py +169 -0
- gitpane/emoji/__init__.py +0 -0
- gitpane/emoji/emoji_catalogue.py +156 -0
- gitpane/git_config/__init__.py +0 -0
- gitpane/git_config/git_setting.py +441 -0
- gitpane/history/__init__.py +0 -0
- gitpane/history/avatar.py +241 -0
- gitpane/history/file_history.py +359 -0
- gitpane/history/graph.py +145 -0
- gitpane/history/history_filter.py +31 -0
- gitpane/history/history_parse.py +605 -0
- gitpane/history/repository.py +1600 -0
- gitpane/history/repository_value.py +341 -0
- gitpane/history/revision.py +180 -0
- gitpane/history/revision_file.py +182 -0
- gitpane/history_rewrite/__init__.py +0 -0
- gitpane/history_rewrite/graph.py +210 -0
- gitpane/history_rewrite/guard.py +288 -0
- gitpane/history_rewrite/index.py +125 -0
- gitpane/history_rewrite/prepare.py +378 -0
- gitpane/history_rewrite/protocol.py +320 -0
- gitpane/history_rewrite/publish.py +444 -0
- gitpane/history_rewrite/recovery.py +481 -0
- gitpane/history_rewrite/value.py +229 -0
- gitpane/operation/__init__.py +0 -0
- gitpane/operation/console_line.py +313 -0
- gitpane/operation/console_tone.py +76 -0
- gitpane/operation/diagnostic.py +954 -0
- gitpane/operation/launch_signature.py +254 -0
- gitpane/operation/operation_status.py +87 -0
- gitpane/operation/operation_trace.py +766 -0
- gitpane/operation/repository_operation.py +781 -0
- gitpane/preference/__init__.py +0 -0
- gitpane/preference/preference_location.py +40 -0
- gitpane/preference/preference_store.py +590 -0
- gitpane/process/__init__.py +0 -0
- gitpane/process/exact_arguments.py +77 -0
- gitpane/process/git_output_text.py +20 -0
- gitpane/process/process_group.py +851 -0
- gitpane/process/process_log.py +114 -0
- gitpane/process/process_runner.py +1033 -0
- gitpane/process/released_child_watch.py +138 -0
- gitpane/recent/__init__.py +0 -0
- gitpane/recent/mount_table.py +422 -0
- gitpane/recent/recent_availability.py +414 -0
- gitpane/recent/recent_name.py +11 -0
- gitpane/recent/recent_search.py +114 -0
- gitpane/reference/__init__.py +0 -0
- gitpane/reference/reference_edit.py +2030 -0
- gitpane/reference/reference_snapshot.py +196 -0
- gitpane/reference/stash.py +730 -0
- gitpane/reference/stash_list.py +164 -0
- gitpane/sequencer/__init__.py +0 -0
- gitpane/sequencer/commit_message_rule.py +154 -0
- gitpane/sequencer/conflict.py +506 -0
- gitpane/sequencer/merge_recovery.py +163 -0
- gitpane/sequencer/merge_state.py +166 -0
- gitpane/sequencer/mergetool.py +856 -0
- gitpane/sequencer/rebase.py +750 -0
- gitpane/sequencer/rebase_edit_file.py +224 -0
- gitpane/sequencer/rebase_state.py +523 -0
- gitpane/sequencer/replay.py +1435 -0
- gitpane/sequencer/replay_legacy.py +253 -0
- gitpane/sequencer/replay_state.py +747 -0
- gitpane/submodule/__init__.py +0 -0
- gitpane/submodule/checkout_refusal.py +102 -0
- gitpane/submodule/checkout_refusal_notice.py +111 -0
- gitpane/submodule/cloned_without_checkout.py +65 -0
- gitpane/submodule/submodule_discovery.py +1180 -0
- gitpane/submodule/submodule_loss.py +218 -0
- gitpane/system/__init__.py +0 -0
- gitpane/system/appearance_portal.py +125 -0
- gitpane/system/application_identity.py +48 -0
- gitpane/system/command_line.py +36 -0
- gitpane/system/desktop_icon_fact.py +128 -0
- gitpane/system/desktop_icon_support.py +270 -0
- gitpane/system/desktop_shortcut.py +536 -0
- gitpane/system/icns_image.py +35 -0
- gitpane/system/installed_launcher.py +136 -0
- gitpane/system/linux_distribution.py +151 -0
- gitpane/system/network_folder.py +46 -0
- gitpane/system/path_identity.py +95 -0
- gitpane/system/private_tree_removal.py +47 -0
- gitpane/system/process_program.py +63 -0
- gitpane/system/qt_folder.py +38 -0
- gitpane/system/ready_channel_watch.py +67 -0
- gitpane/system/startup_activation.py +65 -0
- gitpane/system/terminal_detach.py +384 -0
- gitpane/system/xdg_session.py +85 -0
- gitpane/text/__init__.py +0 -0
- gitpane/text/text_query.py +97 -0
- gitpane/text/typed_path.py +75 -0
- gitpane/text/typed_text.py +17 -0
- gitpane/thread/__init__.py +0 -0
- gitpane/thread/weak_signal.py +93 -0
- gitpane/tool/__init__.py +0 -0
- gitpane/tool/app_bundle.py +164 -0
- gitpane/tool/desktop_text_editor.py +156 -0
- gitpane/tool/difftool.py +429 -0
- gitpane/tool/editor.py +445 -0
- gitpane/tool/editor_bridge.py +193 -0
- gitpane/tool/editor_recipe.py +481 -0
- gitpane/tool/file_reveal.py +94 -0
- gitpane/tool/git_executable.py +264 -0
- gitpane/tool/git_version.py +62 -0
- gitpane/tool/kdiff3.py +41 -0
- gitpane/tool/kdiff3_install.py +162 -0
- gitpane/tool/launch_services_text_editor.py +104 -0
- gitpane/tool/mergetool_recipe.py +84 -0
- gitpane/tool/system_editor_default.py +80 -0
- gitpane/tool/system_text_editor.py +44 -0
- gitpane/tool/system_tool.py +816 -0
- gitpane/tool/terminal_recipe.py +390 -0
- gitpane/transport/__init__.py +0 -0
- gitpane/transport/branch_exchange.py +1690 -0
- gitpane/transport/clone.py +1273 -0
- gitpane/transport/credential_read_retry.py +35 -0
- gitpane/transport/git_refusal.py +207 -0
- gitpane/transport/push_tracking.py +121 -0
- gitpane/transport/refusal_notice.py +225 -0
- gitpane/transport/remote.py +747 -0
- gitpane/transport/remote_config.py +544 -0
- gitpane/ui/__init__.py +0 -0
- gitpane/ui/console/__init__.py +0 -0
- gitpane/ui/console/error_dialog.py +332 -0
- gitpane/ui/console/operation_dialog.py +408 -0
- gitpane/ui/console/operation_output.py +91 -0
- gitpane/ui/console/operation_output_view.py +373 -0
- gitpane/ui/emoji/__init__.py +0 -0
- gitpane/ui/emoji/emoji_font.py +257 -0
- gitpane/ui/emoji/emoji_grid.py +125 -0
- gitpane/ui/emoji/emoji_window.py +154 -0
- gitpane/ui/emoji/file_action_icon.py +131 -0
- gitpane/ui/emoji/opentype_family_name.py +182 -0
- gitpane/ui/history_rewrite/__init__.py +0 -0
- gitpane/ui/history_rewrite/details.py +78 -0
- gitpane/ui/history_rewrite/preview.py +565 -0
- gitpane/ui/history_rewrite/preview_model.py +291 -0
- gitpane/ui/history_rewrite/question.py +87 -0
- gitpane/ui/history_rewrite/recovery_dialog.py +262 -0
- gitpane/ui/look/__init__.py +0 -0
- gitpane/ui/look/action_icon.py +504 -0
- gitpane/ui/look/application_icon.py +78 -0
- gitpane/ui/look/application_style.py +317 -0
- gitpane/ui/look/avatar_label.py +53 -0
- gitpane/ui/look/color_contrast.py +43 -0
- gitpane/ui/look/desktop_appearance_follower.py +118 -0
- gitpane/ui/look/fixed_font.py +21 -0
- gitpane/ui/look/gtk_settings.py +116 -0
- gitpane/ui/look/icon_density.py +16 -0
- gitpane/ui/look/reference_font.py +19 -0
- gitpane/ui/look/theme_color.py +63 -0
- gitpane/ui/look/theme_look.py +95 -0
- gitpane/ui/look/theme_palette.py +173 -0
- gitpane/ui/look/warning_icon.py +86 -0
- gitpane/ui/look/windows_control_look.py +250 -0
- gitpane/ui/reader/__init__.py +0 -0
- gitpane/ui/reader/commit_message.py +129 -0
- gitpane/ui/reader/commit_panel.py +378 -0
- gitpane/ui/reader/diff_panel.py +626 -0
- gitpane/ui/reader/file_action.py +138 -0
- gitpane/ui/reader/file_tree_panel.py +235 -0
- gitpane/ui/reader/reader_toolbar.py +56 -0
- gitpane/ui/reader/revision_tree.py +80 -0
- gitpane/ui/reader/search_result.py +165 -0
- gitpane/ui/reader/source_text.py +134 -0
- gitpane/ui/reader/source_view.py +151 -0
- gitpane/ui/reader/syntax_span.py +67 -0
- gitpane/ui/reference/__init__.py +0 -0
- gitpane/ui/reference/branch_selector.py +106 -0
- gitpane/ui/reference/checkout_dialog.py +419 -0
- gitpane/ui/reference/checkout_revision_dialog.py +182 -0
- gitpane/ui/reference/commit_summary.py +339 -0
- gitpane/ui/reference/create_branch_dialog.py +346 -0
- gitpane/ui/reference/create_tag_dialog.py +283 -0
- gitpane/ui/reference/delete_local_branch_dialog.py +323 -0
- gitpane/ui/reference/delete_tag_dialog.py +394 -0
- gitpane/ui/reference/form_opening.py +53 -0
- gitpane/ui/reference/reference_dialog.py +417 -0
- gitpane/ui/reference/reference_feedback.py +62 -0
- gitpane/ui/reference/reference_form.py +139 -0
- gitpane/ui/reference/rename_branch_dialog.py +179 -0
- gitpane/ui/reference/reset_branch_dialog.py +430 -0
- gitpane/ui/reference/reset_dialog.py +263 -0
- gitpane/ui/reference/revision_dialog.py +121 -0
- gitpane/ui/reference/revision_picker.py +227 -0
- gitpane/ui/reference/select_branches_dialog.py +199 -0
- gitpane/ui/reference/stash_dialog.py +171 -0
- gitpane/ui/repository/__init__.py +0 -0
- gitpane/ui/repository/graph_delegate.py +298 -0
- gitpane/ui/repository/history_avatar.py +130 -0
- gitpane/ui/repository/history_model.py +179 -0
- gitpane/ui/repository/repository_list_popup.py +319 -0
- gitpane/ui/repository/repository_window.py +2580 -0
- gitpane/ui/resource/ArrowDown.png +0 -0
- gitpane/ui/resource/ArrowUp.png +0 -0
- gitpane/ui/resource/BranchCheckout.png +0 -0
- gitpane/ui/resource/BranchCreate.png +0 -0
- gitpane/ui/resource/BranchDelete.png +0 -0
- gitpane/ui/resource/CopyToClipboard.png +0 -0
- gitpane/ui/resource/GitPane-16.png +0 -0
- gitpane/ui/resource/GitPane-24.png +0 -0
- gitpane/ui/resource/GitPane-256.png +0 -0
- gitpane/ui/resource/GitPane-32.png +0 -0
- gitpane/ui/resource/GitPane-48.png +0 -0
- gitpane/ui/resource/GitPane-64.png +0 -0
- gitpane/ui/resource/GitPane.ico +0 -0
- gitpane/ui/resource/NotoColorEmoji-OFL.txt +92 -0
- gitpane/ui/resource/NotoColorEmoji_WindowsCompatible.ttf +0 -0
- gitpane/ui/resource/Renamed.png +0 -0
- gitpane/ui/resource/ResetAnotherBranchToHere.png +0 -0
- gitpane/ui/resource/ResetCurrentBranchToHere.png +0 -0
- gitpane/ui/resource/Stash.png +0 -0
- gitpane/ui/resource/Tag.png +0 -0
- gitpane/ui/resource/TagCreate.png +0 -0
- gitpane/ui/resource/TagDelete.png +0 -0
- gitpane/ui/resource/Unmerged.png +0 -0
- gitpane/ui/resource/checkout.png +0 -0
- gitpane/ui/sequencer/__init__.py +0 -0
- gitpane/ui/sequencer/conflict_dialog.py +532 -0
- gitpane/ui/sequencer/merge_recovery_dialog.py +67 -0
- gitpane/ui/sequencer/rebase_dialog.py +461 -0
- gitpane/ui/sequencer/rebase_editor_window.py +220 -0
- gitpane/ui/sequencer/replay_conflict_prompt.py +105 -0
- gitpane/ui/sequencer/replay_dialog.py +501 -0
- gitpane/ui/setting/__init__.py +0 -0
- gitpane/ui/setting/account_page.py +724 -0
- gitpane/ui/setting/add_account_dialog.py +1005 -0
- gitpane/ui/setting/credential_manager_dialog.py +151 -0
- gitpane/ui/setting/git_setting_widget.py +388 -0
- gitpane/ui/setting/setting_block.py +19 -0
- gitpane/ui/setting/setting_dialog.py +750 -0
- gitpane/ui/setting/ssh_widget.py +232 -0
- gitpane/ui/setting/utility_page.py +240 -0
- gitpane/ui/staging/__init__.py +0 -0
- gitpane/ui/staging/staging_action.py +356 -0
- gitpane/ui/staging/staging_window.py +745 -0
- gitpane/ui/transport/__init__.py +0 -0
- gitpane/ui/transport/clone_dialog.py +879 -0
- gitpane/ui/transport/push_dialog.py +580 -0
- gitpane/ui/transport/push_rejection_prompt.py +100 -0
- gitpane/ui/transport/push_tracking_question.py +88 -0
- gitpane/ui/transport/remote_dialog.py +943 -0
- gitpane/ui/welcome/__init__.py +0 -0
- gitpane/ui/welcome/invalid_repository_prompt.py +114 -0
- gitpane/ui/welcome/welcome_window.py +1137 -0
- gitpane/ui/widget/__init__.py +0 -0
- gitpane/ui/widget/busy_indicator.py +106 -0
- gitpane/ui/widget/commit_date_text.py +55 -0
- gitpane/ui/widget/content_growth.py +262 -0
- gitpane/ui/widget/content_measure.py +99 -0
- gitpane/ui/widget/dialog_layout.py +668 -0
- gitpane/ui/widget/drop_down_wheel_filter.py +32 -0
- gitpane/ui/widget/flow_layout.py +110 -0
- gitpane/ui/widget/long_text.py +542 -0
- gitpane/ui/widget/mnemonic.py +13 -0
- gitpane/ui/widget/numbered_text_edit.py +127 -0
- gitpane/ui/widget/plain_label.py +15 -0
- gitpane/ui/widget/plain_tooltip.py +19 -0
- gitpane/ui/widget/refresh_advice.py +25 -0
- gitpane/ui/widget/result_label.py +227 -0
- gitpane/ui/widget/result_status_bar.py +53 -0
- gitpane/ui/widget/scrolled_text.py +69 -0
- gitpane/ui/widget/shortcut_text.py +31 -0
- gitpane/ui/widget/standard_icon_label.py +55 -0
- gitpane/ui/widget/system_shortcut.py +75 -0
- gitpane/ui/widget/unavailable_reason.py +29 -0
- gitpane/ui/widget/wheel_safe_drop_down.py +24 -0
- gitpane/ui/window_control/__init__.py +0 -0
- gitpane/ui/window_control/button_focus.py +42 -0
- gitpane/ui/window_control/compositor_answer.py +152 -0
- gitpane/ui/window_control/compositor_growth_cap.py +73 -0
- gitpane/ui/window_control/desktop_activation.py +203 -0
- gitpane/ui/window_control/dialog_modality.py +122 -0
- gitpane/ui/window_control/item_activation.py +42 -0
- gitpane/ui/window_control/modal_focus_relay.py +124 -0
- gitpane/ui/window_control/wayland_activation.py +695 -0
- gitpane/ui/window_control/window_placement.py +305 -0
- gitpane/vendor/DISTLIB-LICENSE.txt +284 -0
- gitpane/vendor/w32.exe +0 -0
- gitpane/vendor/w64-arm.exe +0 -0
- gitpane/vendor/w64.exe +0 -0
- gitpane/worktree/__init__.py +0 -0
- gitpane/worktree/command_sequence.py +110 -0
- gitpane/worktree/file_action_target.py +61 -0
- gitpane/worktree/file_menu_action.py +52 -0
- gitpane/worktree/historical_restore.py +361 -0
- gitpane/worktree/ignore_rule.py +266 -0
- gitpane/worktree/mutation.py +1539 -0
- gitpane/worktree/partial_patch.py +435 -0
- gitpane/worktree/staged_reset.py +447 -0
- gitpane/worktree/staging.py +1418 -0
- gitpane/worktree/trash.py +302 -0
- gitpane/worktree/worktree_file.py +406 -0
- gitpane/worktree/worktree_service.py +584 -0
- gitpane/worktree/worktree_snapshot.py +630 -0
- gitpane-1.0.0.dist-info/METADATA +141 -0
- gitpane-1.0.0.dist-info/RECORD +353 -0
- gitpane-1.0.0.dist-info/WHEEL +5 -0
- gitpane-1.0.0.dist-info/entry_points.txt +2 -0
- gitpane-1.0.0.dist-info/licenses/LICENSE +21 -0
- gitpane-1.0.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +109 -0
- gitpane-1.0.0.dist-info/licenses/src/gitpane/ui/resource/NotoColorEmoji-OFL.txt +92 -0
- gitpane-1.0.0.dist-info/licenses/src/gitpane/vendor/DISTLIB-LICENSE.txt +284 -0
- gitpane-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
"""Own repository-wide writes independently of their requesting windows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from dataclasses import dataclass, field, replace
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
from PySide6.QtCore import QObject, QTimer, Signal
|
|
11
|
+
|
|
12
|
+
from gitpane.config import GIT_PATH_SEPARATOR, MERGE_HEAD_BASENAME
|
|
13
|
+
from gitpane.history.file_history import WindowCapability
|
|
14
|
+
from gitpane.operation.diagnostic import Diagnostic
|
|
15
|
+
from gitpane.operation.operation_status import OperationStatus
|
|
16
|
+
from gitpane.process.process_runner import READ_PROFILE
|
|
17
|
+
from gitpane.sequencer.rebase_state import REBASE_STOPPED_STATE_SET, NativeMetadata, RebaseSnapshot, can_abort_rebase, read_metadata, snapshot_from_metadata
|
|
18
|
+
from gitpane.sequencer.replay_state import (
|
|
19
|
+
MERGE_MESSAGE_BASENAME,
|
|
20
|
+
ReplayKind,
|
|
21
|
+
ReplayMetadata,
|
|
22
|
+
ReplaySnapshot,
|
|
23
|
+
read_replay_metadata,
|
|
24
|
+
replay_head_reference_signatures,
|
|
25
|
+
replay_snapshot_from_metadata,
|
|
26
|
+
)
|
|
27
|
+
from gitpane.system.path_identity import canonical_path
|
|
28
|
+
from gitpane.worktree.command_sequence import GitCommand, GitCommandError, ReadBatch
|
|
29
|
+
from gitpane.worktree.worktree_snapshot import WorktreeKey
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
from collections.abc import Callable, Generator
|
|
33
|
+
|
|
34
|
+
from gitpane.history.repository_value import RepositoryContext
|
|
35
|
+
from gitpane.operation.diagnostic import PreparedDiagnostic
|
|
36
|
+
from gitpane.process.process_runner import ProcessStatus
|
|
37
|
+
from gitpane.worktree.worktree_service import WorktreeService
|
|
38
|
+
from gitpane.worktree.worktree_snapshot import WorktreeProbe
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class OperationAction(Enum):
|
|
42
|
+
"""Describe write authority independently of a displayed command label."""
|
|
43
|
+
|
|
44
|
+
READ = "read"
|
|
45
|
+
STAGE = "stage"
|
|
46
|
+
UNSTAGE = "unstage"
|
|
47
|
+
WORKTREE_EDIT = "worktree-edit"
|
|
48
|
+
AMEND = "amend"
|
|
49
|
+
COMMIT = "commit"
|
|
50
|
+
COMMIT_PUSH = "commit-push"
|
|
51
|
+
CONFLICT_TOOL = "conflict-tool"
|
|
52
|
+
CONFLICT_STAGE = "conflict-stage"
|
|
53
|
+
REF_WRITE = "ref-write"
|
|
54
|
+
STASH = "stash"
|
|
55
|
+
REBASE_START = "rebase-start"
|
|
56
|
+
REBASE_CONTINUE = "rebase-continue"
|
|
57
|
+
REBASE_ABORT = "rebase-abort"
|
|
58
|
+
REPLAY_START = "replay-start"
|
|
59
|
+
REPLAY_CONTINUE = "replay-continue"
|
|
60
|
+
REPLAY_ABORT = "replay-abort"
|
|
61
|
+
MERGE_ABORT = "merge-abort"
|
|
62
|
+
REMOTE_WRITE = "remote-write"
|
|
63
|
+
CONFIG_WRITE = "config-write"
|
|
64
|
+
SUBMODULE_INIT = "submodule-init"
|
|
65
|
+
UNKNOWN = "unknown"
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def commit_label(self) -> str | None:
|
|
69
|
+
"""Name the local commit action independently of its write authority."""
|
|
70
|
+
if self == OperationAction.COMMIT:
|
|
71
|
+
return "Commit"
|
|
72
|
+
if self == OperationAction.AMEND:
|
|
73
|
+
return "Amend"
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def commit_progress_text(self) -> str | None:
|
|
78
|
+
"""Describe a local commit while its captured request is still running."""
|
|
79
|
+
if self == OperationAction.COMMIT:
|
|
80
|
+
return "Commit in progress…"
|
|
81
|
+
if self == OperationAction.AMEND:
|
|
82
|
+
return "Amend in progress…"
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class OperationText(Enum):
|
|
87
|
+
"""Provide shared presentation text for repository ownership."""
|
|
88
|
+
|
|
89
|
+
OWNED_REPOSITORY = "{operation} owns this repository. Wait for it to finish."
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass(frozen=True)
|
|
93
|
+
class OperationAvailability:
|
|
94
|
+
"""Explain availability with the identity of a temporary blocking owner."""
|
|
95
|
+
|
|
96
|
+
reason: str = ""
|
|
97
|
+
owner_operation_id: str | None = None
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass(frozen=True)
|
|
101
|
+
class WriteScope:
|
|
102
|
+
"""Identify the worktree and shared references affected by one write."""
|
|
103
|
+
|
|
104
|
+
key: WorktreeKey
|
|
105
|
+
common_git_dir: str
|
|
106
|
+
refs: tuple[str, ...] = ()
|
|
107
|
+
global_configuration: bool = False
|
|
108
|
+
|
|
109
|
+
@classmethod
|
|
110
|
+
def capture(cls, context: RepositoryContext, refs: tuple[str, ...] = ()) -> WriteScope:
|
|
111
|
+
"""Bind affected references to canonical storage and the actual worktree."""
|
|
112
|
+
return cls(WorktreeKey.from_context(context), canonical_path(context.common_git_dir), refs)
|
|
113
|
+
|
|
114
|
+
def touches(self, full_ref: str) -> bool:
|
|
115
|
+
"""Include exact references and Git's single-star refspec namespaces."""
|
|
116
|
+
for pattern in self.refs:
|
|
117
|
+
prefix, separator, suffix = pattern.partition("*")
|
|
118
|
+
if not separator and full_ref == pattern:
|
|
119
|
+
return True
|
|
120
|
+
if separator and full_ref.startswith(prefix) and full_ref.endswith(suffix) and len(full_ref) >= len(prefix) + len(suffix):
|
|
121
|
+
return True
|
|
122
|
+
return False
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# Git leaves one of these directories while a rebase stops.
|
|
126
|
+
REBASE_MARKER_BASENAMES = ("rebase-merge", "rebase-apply")
|
|
127
|
+
# A cherry-pick or revert started without committing stops with neither an operation head nor a sequencer: the prepared
|
|
128
|
+
# message is then the only file it leaves, which is why that message belongs to this list.
|
|
129
|
+
REPLAY_MARKER_BASENAMES = ("CHERRY_PICK_HEAD", "REVERT_HEAD", "sequencer", MERGE_MESSAGE_BASENAME)
|
|
130
|
+
MERGE_MARKER_BASENAMES = (MERGE_HEAD_BASENAME,)
|
|
131
|
+
# Files inside the pause directories that move at each step of a rebase or a sequence while the directories stay.
|
|
132
|
+
PAUSE_PROBE_INNER_GIT_PATHS = ("rebase-merge/done", "rebase-merge/git-rebase-todo", "rebase-merge/stopped-sha", "rebase-merge/msgnum", "sequencer/todo")
|
|
133
|
+
PAUSE_PROBE_GIT_PATHS = REBASE_MARKER_BASENAMES + REPLAY_MARKER_BASENAMES + MERGE_MARKER_BASENAMES + PAUSE_PROBE_INNER_GIT_PATHS
|
|
134
|
+
ABSENT_PATH_SIGNATURE = (False, 0, 0, 0)
|
|
135
|
+
REBASE_PAUSE_OBSERVATION = "rebase"
|
|
136
|
+
REPLAY_PAUSE_OBSERVATION = "replay"
|
|
137
|
+
PAUSE_OBSERVATIONS = (REBASE_PAUSE_OBSERVATION, REPLAY_PAUSE_OBSERVATION)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def native_rebase_capture(context: RepositoryContext) -> tuple[NativeMetadata | None, ...]:
|
|
141
|
+
"""Read bounded native metadata using already resolved, worktree-specific Git paths."""
|
|
142
|
+
if context.is_bare:
|
|
143
|
+
return ()
|
|
144
|
+
observations = []
|
|
145
|
+
for basename in REBASE_MARKER_BASENAMES:
|
|
146
|
+
observations.append(read_metadata(os.path.join(context.git_dir, basename)))
|
|
147
|
+
return tuple(observations)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def rebase_action_diagnostic(action: OperationAction, snapshot: RebaseSnapshot) -> str:
|
|
151
|
+
"""Explain whether a fresh native pause permits this kind of preparation."""
|
|
152
|
+
if action == OperationAction.READ:
|
|
153
|
+
return ""
|
|
154
|
+
if action == OperationAction.REBASE_ABORT and can_abort_rebase(snapshot):
|
|
155
|
+
return ""
|
|
156
|
+
if not snapshot.fresh or snapshot.state in ("unknown", "external-change"):
|
|
157
|
+
return "The rebase state is unknown or changed. Refresh before writing."
|
|
158
|
+
if snapshot.state == "absent":
|
|
159
|
+
return ""
|
|
160
|
+
if snapshot.state in REBASE_STOPPED_STATE_SET:
|
|
161
|
+
if action in (OperationAction.STAGE, OperationAction.UNSTAGE, OperationAction.WORKTREE_EDIT,
|
|
162
|
+
OperationAction.CONFLICT_TOOL, OperationAction.CONFLICT_STAGE, OperationAction.REBASE_ABORT, OperationAction.REBASE_CONTINUE):
|
|
163
|
+
return ""
|
|
164
|
+
if action == OperationAction.AMEND and snapshot.state == "edit":
|
|
165
|
+
return ""
|
|
166
|
+
return "This action is unavailable during the rebase. Prepare changes or refresh its current state."
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def native_replay_capture(context: RepositoryContext) -> tuple[ReplayMetadata, ...]:
|
|
170
|
+
"""Freeze native replay files, excluding unrelated metadata when no replay exists."""
|
|
171
|
+
if context.is_bare:
|
|
172
|
+
return ()
|
|
173
|
+
if not any(os.path.lexists(os.path.join(context.git_dir, basename)) for basename in REPLAY_MARKER_BASENAMES):
|
|
174
|
+
return ()
|
|
175
|
+
metadata = read_replay_metadata(context.git_dir)
|
|
176
|
+
if not metadata.present() and (not metadata.content_by_basename.get(MERGE_MESSAGE_BASENAME)
|
|
177
|
+
or any(os.path.lexists(os.path.join(context.git_dir, name)) for name in MERGE_MARKER_BASENAMES + REBASE_MARKER_BASENAMES)):
|
|
178
|
+
return ()
|
|
179
|
+
return (replace(metadata, head_reference_signatures=replay_head_reference_signatures(context, metadata)),)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def path_signature(filename: str) -> tuple[bool, int, int, int] | None:
|
|
183
|
+
"""Describe one Git state file so two looks at it compare without opening it; None means unknown, to be read again through Git."""
|
|
184
|
+
try:
|
|
185
|
+
status = os.stat(filename)
|
|
186
|
+
except FileNotFoundError:
|
|
187
|
+
return ABSENT_PATH_SIGNATURE
|
|
188
|
+
except OSError:
|
|
189
|
+
return None
|
|
190
|
+
return (True, status.st_ino, status.st_size, status.st_mtime_ns)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@dataclass(frozen=True)
|
|
194
|
+
class PauseSignature:
|
|
195
|
+
"""Everything the pause probe compares between two looks: the pause files and the facts of the last status."""
|
|
196
|
+
|
|
197
|
+
path_signatures: tuple[tuple[bool, int, int, int], ...]
|
|
198
|
+
head_oid: str | None
|
|
199
|
+
branch_head: str | None
|
|
200
|
+
unmerged_records: tuple[bytes, ...]
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _pause_path_belongs_to_worktree(filename: str, git_path: str, key: WorktreeKey) -> bool:
|
|
204
|
+
"""Walk a path Git gave back up by the segments that were asked, and require what is left to be this worktree's Git directory.
|
|
205
|
+
|
|
206
|
+
Nothing is joined: the path is only taken apart, so a name Git would place elsewhere cannot pass for the asked one.
|
|
207
|
+
"""
|
|
208
|
+
directory = filename
|
|
209
|
+
for segment in reversed(git_path.split(GIT_PATH_SEPARATOR)):
|
|
210
|
+
if os.path.basename(directory) != segment:
|
|
211
|
+
return False
|
|
212
|
+
directory = os.path.dirname(directory)
|
|
213
|
+
return canonical_path(directory) == key.git_dir
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def read_pause_probe_filenames(context: RepositoryContext) -> Generator[GitCommand | ReadBatch, object, tuple[str, ...]]:
|
|
217
|
+
"""Ask Git once where this worktree keeps its pause state files; the paths are never derived from the Git directory."""
|
|
218
|
+
if context.is_bare:
|
|
219
|
+
return ()
|
|
220
|
+
# One process answers every path. The index is never asked here: its path follows a private index environment
|
|
221
|
+
# variable, and this command carries no environment of its own.
|
|
222
|
+
arguments = ["rev-parse", "--path-format=absolute"]
|
|
223
|
+
for git_path in PAUSE_PROBE_GIT_PATHS:
|
|
224
|
+
arguments.extend(["--git-path", git_path])
|
|
225
|
+
output = yield GitCommand(arguments, profile=READ_PROFILE)
|
|
226
|
+
outputs = output.removesuffix(b"\n").split(b"\n")
|
|
227
|
+
if len(outputs) != len(PAUSE_PROBE_GIT_PATHS):
|
|
228
|
+
# Newlines are valid in directory names; separate answers keep each path whole.
|
|
229
|
+
commands = []
|
|
230
|
+
for git_path in PAUSE_PROBE_GIT_PATHS:
|
|
231
|
+
commands.append(GitCommand(["rev-parse", "--path-format=absolute", "--git-path", git_path], profile=READ_PROFILE))
|
|
232
|
+
outputs = yield ReadBatch(tuple(commands))
|
|
233
|
+
key = WorktreeKey.from_context(context)
|
|
234
|
+
filenames = []
|
|
235
|
+
for git_path, path_output in zip(PAUSE_PROBE_GIT_PATHS, outputs, strict=True):
|
|
236
|
+
filename = os.fsdecode(path_output).strip()
|
|
237
|
+
if not _pause_path_belongs_to_worktree(filename, git_path, key):
|
|
238
|
+
raise ValueError("Native pause path does not belong to this worktree.")
|
|
239
|
+
filenames.append(filename)
|
|
240
|
+
return tuple(filenames)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
@dataclass
|
|
244
|
+
class PauseProbe:
|
|
245
|
+
"""Process-free probe of one worktree's pause state.
|
|
246
|
+
|
|
247
|
+
It says whether that state deserves to be read again through Git, never what it is, and no write relies on it.
|
|
248
|
+
"""
|
|
249
|
+
|
|
250
|
+
filenames: tuple[str, ...] | None = None
|
|
251
|
+
observed_signature_by_observation: dict[str, PauseSignature | None] = field(default_factory=dict)
|
|
252
|
+
|
|
253
|
+
def filename_for(self, git_path: str) -> str | None:
|
|
254
|
+
"""Answer the path Git gave for one entry of the pause path list, or nothing while the paths are not known."""
|
|
255
|
+
if self.filenames is None:
|
|
256
|
+
return None
|
|
257
|
+
return self.filenames[PAUSE_PROBE_GIT_PATHS.index(git_path)]
|
|
258
|
+
|
|
259
|
+
def filename_by_git_path(self) -> dict[str, str] | None:
|
|
260
|
+
"""Answer the paths Git gave, by the path that was asked, or nothing while they are not read."""
|
|
261
|
+
if self.filenames is None:
|
|
262
|
+
return None
|
|
263
|
+
filename_by_git_path = {}
|
|
264
|
+
for git_path, filename in zip(PAUSE_PROBE_GIT_PATHS, self.filenames, strict=True):
|
|
265
|
+
filename_by_git_path[git_path] = filename
|
|
266
|
+
return filename_by_git_path
|
|
267
|
+
|
|
268
|
+
def signature(self, worktree_probe: WorktreeProbe | None) -> PauseSignature | None:
|
|
269
|
+
"""Describe the pause files and the status facts now, or nothing when any part of it is unknown."""
|
|
270
|
+
if self.filenames is None or worktree_probe is None:
|
|
271
|
+
return None
|
|
272
|
+
path_signatures = []
|
|
273
|
+
for filename in self.filenames:
|
|
274
|
+
signature = path_signature(filename)
|
|
275
|
+
if signature is None:
|
|
276
|
+
return None
|
|
277
|
+
path_signatures.append(signature)
|
|
278
|
+
return PauseSignature(tuple(path_signatures), worktree_probe.head_oid, worktree_probe.branch_head, worktree_probe.unmerged_records)
|
|
279
|
+
|
|
280
|
+
def observation_due(self, worktree_probe: WorktreeProbe | None) -> bool:
|
|
281
|
+
"""Tell whether the pause state must be read again: unknown now, or different from what either kind of observation last covered."""
|
|
282
|
+
current = self.signature(worktree_probe)
|
|
283
|
+
if current is None:
|
|
284
|
+
return True
|
|
285
|
+
for observation in PAUSE_OBSERVATIONS:
|
|
286
|
+
if observation not in self.observed_signature_by_observation:
|
|
287
|
+
return True
|
|
288
|
+
if self.observed_signature_by_observation[observation] != current:
|
|
289
|
+
return True
|
|
290
|
+
return False
|
|
291
|
+
|
|
292
|
+
def mark_observed(self, observation: str, worktree_probe: WorktreeProbe | None) -> None:
|
|
293
|
+
"""Record what one kind of observation covers, at the moment it starts."""
|
|
294
|
+
# The mark is taken as the observation starts, before its reads: anything that moves afterwards differs from it.
|
|
295
|
+
self.observed_signature_by_observation[observation] = self.signature(worktree_probe)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
# Said when a running operation holds the same repository: the write can be sent again once it finishes.
|
|
299
|
+
OWNED_REPOSITORY_TEXT = "Another operation owns this repository. Wait for it to finish."
|
|
300
|
+
# Said when a form's capture is older than the repository: a refresh replaced it, so the form must be reopened.
|
|
301
|
+
REPOSITORY_CHANGED_SINCE_OPENED_TEXT = "The repository changed since this window was opened; close and reopen it."
|
|
302
|
+
# Said when a write captured at the click, with no form keeping it, met a refresh before it was sent: a new click captures it again.
|
|
303
|
+
REPOSITORY_CHANGED_WHILE_PREPARING_TEXT = "The repository changed while this action was being prepared. Try again."
|
|
304
|
+
# Said when the write lost its authority for another reason, for example its window was closed.
|
|
305
|
+
NO_LONGER_AUTHORIZED_TEXT = "This action is no longer authorized. Refresh before writing."
|
|
306
|
+
# Said when a write reaches another submodule or worktree that is paused in a rebase: the rebase must end first.
|
|
307
|
+
AFFECTED_REBASE_TEXT = "An affected submodule or worktree has a rebase. Finish it before recursive writes."
|
|
308
|
+
# Said while GitPane closes: trying the action again later would not help, since GitPane is going away.
|
|
309
|
+
GITPANE_CLOSING_TEXT = "GitPane is closing, so this action was not started."
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def replay_action_diagnostic(action: OperationAction, snapshot: ReplaySnapshot) -> str:
|
|
313
|
+
"""Permit compatible conflict preparation while reserving recovery checks for its service."""
|
|
314
|
+
if action == OperationAction.READ:
|
|
315
|
+
return ""
|
|
316
|
+
if not snapshot.fresh or snapshot.kind == ReplayKind.UNKNOWN:
|
|
317
|
+
return "The replay state is unknown or changed. Refresh before writing."
|
|
318
|
+
if snapshot.kind == ReplayKind.ABSENT:
|
|
319
|
+
return ""
|
|
320
|
+
if action in (OperationAction.STAGE, OperationAction.UNSTAGE, OperationAction.WORKTREE_EDIT, OperationAction.CONFLICT_TOOL,
|
|
321
|
+
OperationAction.CONFLICT_STAGE, OperationAction.REPLAY_CONTINUE, OperationAction.REPLAY_ABORT):
|
|
322
|
+
return ""
|
|
323
|
+
return "This action is unavailable during the cherry-pick or revert. Resolve it or refresh its current state."
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
class StaleCaptureError(ValueError):
|
|
327
|
+
"""A write refused because what it was captured on no longer matches the repository or the window's authority.
|
|
328
|
+
|
|
329
|
+
Sending the same capture again would be refused the same way, unlike a write refused because another operation
|
|
330
|
+
holds the repository for now.
|
|
331
|
+
"""
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
@dataclass(frozen=True)
|
|
335
|
+
class OperationIntent:
|
|
336
|
+
"""Capture the authority and repository identity of one explicit write."""
|
|
337
|
+
|
|
338
|
+
operation_id: str
|
|
339
|
+
context: RepositoryContext
|
|
340
|
+
common_git_dir: str
|
|
341
|
+
key: WorktreeKey
|
|
342
|
+
git_filename: str
|
|
343
|
+
generation: int = 0
|
|
344
|
+
# What the write was captured on: names, commits and the members of the chosen mode. Only ever compared, never written.
|
|
345
|
+
targets: tuple[object, ...] = ()
|
|
346
|
+
session_id: str | None = None
|
|
347
|
+
capability: WindowCapability = WindowCapability.MANAGE
|
|
348
|
+
operation: str = "Repository operation"
|
|
349
|
+
global_configuration: bool = False
|
|
350
|
+
reserved_repository_dirs: tuple[str, ...] = ()
|
|
351
|
+
reserved_contexts: tuple[RepositoryContext, ...] = ()
|
|
352
|
+
action: OperationAction = OperationAction.UNKNOWN
|
|
353
|
+
scope: WriteScope | None = None
|
|
354
|
+
rebase_capture: tuple[NativeMetadata | None, ...] | None = None
|
|
355
|
+
replay_capture: tuple[ReplayMetadata, ...] | None = None
|
|
356
|
+
# Whether a form that stays open holds this capture: a stale one must be closed and reopened, while a write
|
|
357
|
+
# captured at the click is captured again by the next click.
|
|
358
|
+
from_form: bool = False
|
|
359
|
+
|
|
360
|
+
@classmethod
|
|
361
|
+
def capture(cls, operation_id: str, context: RepositoryContext, git_filename: str, **options: object) -> OperationIntent:
|
|
362
|
+
"""Freeze canonical paths while preserving the worktree's separate index identity."""
|
|
363
|
+
common_git_dir = canonical_path(context.common_git_dir)
|
|
364
|
+
key = WorktreeKey.from_context(context)
|
|
365
|
+
options.setdefault("scope", WriteScope(key, common_git_dir, global_configuration=bool(options.get("global_configuration"))))
|
|
366
|
+
try:
|
|
367
|
+
options.setdefault("rebase_capture", native_rebase_capture(context))
|
|
368
|
+
except (OSError, ValueError):
|
|
369
|
+
# Failed observations remain capturable so services can report a normal refusal.
|
|
370
|
+
options.setdefault("rebase_capture", None)
|
|
371
|
+
try:
|
|
372
|
+
options.setdefault("replay_capture", native_replay_capture(context))
|
|
373
|
+
except (OSError, ValueError):
|
|
374
|
+
options.setdefault("replay_capture", None)
|
|
375
|
+
return cls(operation_id, context, common_git_dir, key, git_filename, **options)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
@dataclass(frozen=True)
|
|
379
|
+
class OperationStepResult:
|
|
380
|
+
"""Separate a native command's status from its actually observed repository effect."""
|
|
381
|
+
|
|
382
|
+
operation: str
|
|
383
|
+
status: OperationStatus
|
|
384
|
+
before: object = None
|
|
385
|
+
after: object = None
|
|
386
|
+
process_status: ProcessStatus | None = None
|
|
387
|
+
effect: str = "unknown"
|
|
388
|
+
diagnostic: PreparedDiagnostic | None = None
|
|
389
|
+
return_code: int | None = None
|
|
390
|
+
full_ref: str = ""
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
@dataclass(frozen=True)
|
|
394
|
+
class OperationOutcome:
|
|
395
|
+
"""Retain completed steps and diagnostics without replaying successful writes."""
|
|
396
|
+
|
|
397
|
+
operation_id: str
|
|
398
|
+
status: OperationStatus
|
|
399
|
+
steps: tuple[OperationStepResult, ...] = ()
|
|
400
|
+
diagnostic: PreparedDiagnostic | None = None
|
|
401
|
+
# Set on a refusal whose capture no longer matches the repository: sending the same capture again would only be
|
|
402
|
+
# refused again, so a form must not offer it and the windows must read the repository again. Keyword-only, so the
|
|
403
|
+
# outcomes that extend this one keep their positional fields.
|
|
404
|
+
stale_capture: bool = field(default=False, kw_only=True)
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
class RepositoryOperationService(QObject):
|
|
408
|
+
"""Serialize common Git storage and global configuration until the owner reconciles."""
|
|
409
|
+
|
|
410
|
+
finished = Signal(object)
|
|
411
|
+
idle = Signal()
|
|
412
|
+
changed = Signal()
|
|
413
|
+
|
|
414
|
+
def __init__(self, worktree_service: WorktreeService, parent: QObject | None = None, *, allows: Callable[[OperationIntent], bool] | None = None,
|
|
415
|
+
explains: Callable[[OperationIntent], str] | None = None) -> None:
|
|
416
|
+
"""Inject native sequence execution and the application's current session policy.
|
|
417
|
+
|
|
418
|
+
``explains`` gives the application's reason for a write its policy no longer allows, so a refusal can say
|
|
419
|
+
why instead of guessing between a running operation and a stale window.
|
|
420
|
+
"""
|
|
421
|
+
super().__init__(parent)
|
|
422
|
+
self.worktree_service = worktree_service
|
|
423
|
+
self.allows = allows
|
|
424
|
+
self.explains = explains
|
|
425
|
+
self.active_by_id: dict[str, OperationIntent] = {}
|
|
426
|
+
self.outcome_by_id: dict[str, OperationOutcome] = {}
|
|
427
|
+
self.submitted_id_set: set[str] = set()
|
|
428
|
+
self.context_by_key: dict[WorktreeKey, RepositoryContext] = {}
|
|
429
|
+
self.closed = False
|
|
430
|
+
|
|
431
|
+
def policy_diagnostic(self, intent: OperationIntent) -> str:
|
|
432
|
+
"""Recheck native identity even for callers that have no application session."""
|
|
433
|
+
if intent.action == OperationAction.READ:
|
|
434
|
+
return ""
|
|
435
|
+
if intent.rebase_capture is None:
|
|
436
|
+
return "The captured rebase state is unknown. Refresh before writing."
|
|
437
|
+
if intent.scope is not None and (intent.scope.key != intent.key or intent.scope.common_git_dir != intent.common_git_dir
|
|
438
|
+
or intent.scope.global_configuration != intent.global_configuration):
|
|
439
|
+
return "The write scope changed. Refresh before writing."
|
|
440
|
+
replay_reason = self._replay_policy_diagnostic(intent)
|
|
441
|
+
if replay_reason:
|
|
442
|
+
return replay_reason
|
|
443
|
+
try:
|
|
444
|
+
related_context_by_key = dict(self.context_by_key)
|
|
445
|
+
for context in intent.reserved_contexts:
|
|
446
|
+
related_context_by_key[WorktreeKey.from_context(context)] = context
|
|
447
|
+
for context in related_context_by_key.values():
|
|
448
|
+
if WorktreeKey.from_context(context) == intent.key:
|
|
449
|
+
continue
|
|
450
|
+
reserved = context in intent.reserved_contexts
|
|
451
|
+
for root_dir in intent.reserved_repository_dirs:
|
|
452
|
+
try:
|
|
453
|
+
if os.path.commonpath((canonical_path(root_dir), canonical_path(context.repository_dir))) == canonical_path(root_dir):
|
|
454
|
+
reserved = True
|
|
455
|
+
except ValueError:
|
|
456
|
+
continue
|
|
457
|
+
if reserved and any(native_rebase_capture(context)):
|
|
458
|
+
return AFFECTED_REBASE_TEXT
|
|
459
|
+
for context in self.context_by_key.values():
|
|
460
|
+
if WorktreeKey.from_context(context) == intent.key:
|
|
461
|
+
continue
|
|
462
|
+
shared_configuration = intent.action == OperationAction.CONFIG_WRITE and canonical_path(context.common_git_dir) == intent.common_git_dir
|
|
463
|
+
shared_reference = intent.scope is not None and intent.scope.refs and canonical_path(context.common_git_dir) == intent.common_git_dir
|
|
464
|
+
if not (intent.global_configuration or shared_configuration or shared_reference):
|
|
465
|
+
continue
|
|
466
|
+
related_observations = native_rebase_capture(context)
|
|
467
|
+
if not any(related_observations):
|
|
468
|
+
continue
|
|
469
|
+
if intent.global_configuration or shared_configuration:
|
|
470
|
+
return "Configuration cannot change while an affected worktree has a rebase. Finish the rebase and refresh."
|
|
471
|
+
for observed in related_observations:
|
|
472
|
+
if observed is not None and (not observed.content_by_basename.get("head-name", "").strip()
|
|
473
|
+
or intent.scope.touches(observed.content_by_basename["head-name"].strip())):
|
|
474
|
+
return "This reference belongs to a paused rebase in another worktree. Refresh before writing."
|
|
475
|
+
observations = native_rebase_capture(intent.context)
|
|
476
|
+
if intent.rebase_capture != observations and (intent.rebase_capture is not None or any(observations)):
|
|
477
|
+
return "The native rebase changed since this action was captured. Refresh before writing."
|
|
478
|
+
if not any(observations):
|
|
479
|
+
return ""
|
|
480
|
+
state_dirs = []
|
|
481
|
+
for basename in REBASE_MARKER_BASENAMES:
|
|
482
|
+
state_dirs.append(os.path.join(intent.context.git_dir, basename))
|
|
483
|
+
snapshot = snapshot_from_metadata(intent.key, intent.generation, state_dirs, observations, None, False)
|
|
484
|
+
return rebase_action_diagnostic(intent.action, snapshot)
|
|
485
|
+
except (OSError, ValueError):
|
|
486
|
+
return "Cannot read the native rebase state. Refresh before writing."
|
|
487
|
+
|
|
488
|
+
def _replay_policy_diagnostic(self, intent: OperationIntent) -> str:
|
|
489
|
+
"""Recheck native replay identity and affected linked worktrees at each write boundary."""
|
|
490
|
+
if intent.replay_capture is None:
|
|
491
|
+
return "The captured replay state is unknown. Refresh before writing."
|
|
492
|
+
try:
|
|
493
|
+
related_context_by_key = dict(self.context_by_key)
|
|
494
|
+
for context in intent.reserved_contexts:
|
|
495
|
+
related_context_by_key[WorktreeKey.from_context(context)] = context
|
|
496
|
+
for key, context in related_context_by_key.items():
|
|
497
|
+
if key == intent.key:
|
|
498
|
+
continue
|
|
499
|
+
reserved = context in intent.reserved_contexts
|
|
500
|
+
for root_dir in intent.reserved_repository_dirs:
|
|
501
|
+
try:
|
|
502
|
+
if os.path.commonpath((canonical_path(root_dir), canonical_path(context.repository_dir))) == canonical_path(root_dir):
|
|
503
|
+
reserved = True
|
|
504
|
+
except ValueError:
|
|
505
|
+
continue
|
|
506
|
+
shared = canonical_path(context.common_git_dir) == intent.common_git_dir
|
|
507
|
+
shared_configuration = shared and intent.action == OperationAction.CONFIG_WRITE
|
|
508
|
+
shared_reference = shared and intent.scope is not None and bool(intent.scope.refs)
|
|
509
|
+
if not (reserved or intent.global_configuration or shared_configuration or shared_reference):
|
|
510
|
+
continue
|
|
511
|
+
observations = native_replay_capture(context)
|
|
512
|
+
if not observations:
|
|
513
|
+
continue
|
|
514
|
+
if reserved:
|
|
515
|
+
return "An affected submodule or worktree has a cherry-pick or revert. Finish it before recursive writes."
|
|
516
|
+
if intent.global_configuration or shared_configuration:
|
|
517
|
+
return "Configuration cannot change while an affected worktree has a cherry-pick or revert."
|
|
518
|
+
for metadata in observations:
|
|
519
|
+
snapshot = replay_snapshot_from_metadata(key, intent.generation, metadata)
|
|
520
|
+
if not metadata.present() or not snapshot.fresh or not snapshot.symbolic_ref or intent.scope.touches(snapshot.symbolic_ref):
|
|
521
|
+
return "This reference belongs to a paused cherry-pick or revert in another worktree. Refresh before writing."
|
|
522
|
+
observations = native_replay_capture(intent.context)
|
|
523
|
+
if observations != intent.replay_capture:
|
|
524
|
+
return "The native replay changed since this action was captured. Refresh before writing."
|
|
525
|
+
for metadata in observations:
|
|
526
|
+
if any(native_rebase_capture(intent.context)) or metadata.content_by_basename.get(MERGE_HEAD_BASENAME, "").strip():
|
|
527
|
+
return "Incompatible native operations are present. Refresh before writing."
|
|
528
|
+
snapshot = replay_snapshot_from_metadata(intent.key, intent.generation, metadata)
|
|
529
|
+
if not metadata.present():
|
|
530
|
+
if intent.action in (OperationAction.STAGE, OperationAction.UNSTAGE, OperationAction.WORKTREE_EDIT, OperationAction.CONFLICT_TOOL, OperationAction.CONFLICT_STAGE):
|
|
531
|
+
continue
|
|
532
|
+
return "Native conflict evidence has no operation identity or commit mode. Resolve or refresh before other writes."
|
|
533
|
+
reason = replay_action_diagnostic(intent.action, snapshot)
|
|
534
|
+
if reason:
|
|
535
|
+
return reason
|
|
536
|
+
return ""
|
|
537
|
+
except (OSError, ValueError):
|
|
538
|
+
return "Cannot read the native replay state. Refresh before writing."
|
|
539
|
+
|
|
540
|
+
def availability(self, intent: OperationIntent) -> OperationAvailability:
|
|
541
|
+
"""Describe the same permission and ownership checks without reserving a command.
|
|
542
|
+
|
|
543
|
+
A closing GitPane comes first, as for a refused write: no action is accepted any more, so asking to refresh or
|
|
544
|
+
to wait would not help.
|
|
545
|
+
"""
|
|
546
|
+
if self.closed:
|
|
547
|
+
return OperationAvailability(GITPANE_CLOSING_TEXT)
|
|
548
|
+
reason = self.policy_diagnostic(intent)
|
|
549
|
+
if reason:
|
|
550
|
+
return OperationAvailability(reason)
|
|
551
|
+
if intent.capability != WindowCapability.MANAGE or self.allows is not None and not self.allows(intent):
|
|
552
|
+
return OperationAvailability("The rebase state or this action is no longer current. Refresh before writing.")
|
|
553
|
+
active = self.conflicting_owner(intent)
|
|
554
|
+
if active is not None:
|
|
555
|
+
return OperationAvailability(OperationText.OWNED_REPOSITORY.value.format(operation=active.operation), active.operation_id)
|
|
556
|
+
return OperationAvailability()
|
|
557
|
+
|
|
558
|
+
def conflicting_owner(self, intent: OperationIntent) -> OperationIntent | None:
|
|
559
|
+
"""Find the reserved operation whose scope prevents this intent from writing."""
|
|
560
|
+
for active in self.active_by_id.values():
|
|
561
|
+
if self._conflicts(active, intent):
|
|
562
|
+
return active
|
|
563
|
+
return None
|
|
564
|
+
|
|
565
|
+
def availability_diagnostic(self, intent: OperationIntent) -> str:
|
|
566
|
+
"""Return the presentation reason for callers that do not need ownership identity."""
|
|
567
|
+
return self.availability(intent).reason
|
|
568
|
+
|
|
569
|
+
def availability_reason_by_action(self, intent: OperationIntent, actions: tuple[OperationAction, ...]) -> dict[OperationAction, str]:
|
|
570
|
+
"""Explain several actions from one capture of the native files, for a view that shows them together.
|
|
571
|
+
|
|
572
|
+
Nothing is reserved: a write always captures its own intention when it is clicked.
|
|
573
|
+
"""
|
|
574
|
+
reason_by_action: dict[OperationAction, str] = {}
|
|
575
|
+
for action in actions:
|
|
576
|
+
reason_by_action[action] = self.availability_diagnostic(replace(intent, action=action))
|
|
577
|
+
return reason_by_action
|
|
578
|
+
|
|
579
|
+
def register_context(self, key: WorktreeKey, context: RepositoryContext) -> None:
|
|
580
|
+
"""Remember a worktree whose pause can block a write elsewhere, and tell the availability views only when the register really changed."""
|
|
581
|
+
if self.context_by_key.get(key) == context:
|
|
582
|
+
return
|
|
583
|
+
self.context_by_key[key] = context
|
|
584
|
+
self.changed.emit()
|
|
585
|
+
|
|
586
|
+
def validate(self, intent: OperationIntent) -> None:
|
|
587
|
+
"""Refuse stale authority immediately before a reserved write is published, with the application's reason when it has one.
|
|
588
|
+
|
|
589
|
+
A closing GitPane lets the writes already running finish, but refuses their next command and says that GitPane
|
|
590
|
+
is closing: that is the real reason, and retrying would not help.
|
|
591
|
+
"""
|
|
592
|
+
self.validate_follow_up(intent, intent)
|
|
593
|
+
|
|
594
|
+
def validate_follow_up(self, owner: OperationIntent, follow_up: OperationIntent) -> None:
|
|
595
|
+
"""Refuse the next command of a running reservation when it no longer holds, judged on that command's own capture and action.
|
|
596
|
+
|
|
597
|
+
The command that holds the reservation may itself change the native state the next one starts from: a rebase
|
|
598
|
+
Git leaves paused once the GitPane editor answered Abort is then cancelled by git rebase --abort. That command
|
|
599
|
+
passes, as follow_up, the native state read after the first one and its own action; the reservation stays owner's.
|
|
600
|
+
"""
|
|
601
|
+
if self.closed:
|
|
602
|
+
raise StaleCaptureError(GITPANE_CLOSING_TEXT)
|
|
603
|
+
if self.active_by_id.get(owner.operation_id) is not owner:
|
|
604
|
+
raise StaleCaptureError("This action no longer owns the repository")
|
|
605
|
+
diagnostic = self.policy_diagnostic(follow_up)
|
|
606
|
+
if diagnostic:
|
|
607
|
+
raise StaleCaptureError(diagnostic)
|
|
608
|
+
if self.allows is not None and not self.allows(follow_up):
|
|
609
|
+
raise StaleCaptureError((self.explains(follow_up) if self.explains is not None else "") or NO_LONGER_AUTHORIZED_TEXT)
|
|
610
|
+
|
|
611
|
+
def reserve(self, intent: OperationIntent) -> bool:
|
|
612
|
+
"""Acquire both worktree and common storage in one non-yielding event-loop step."""
|
|
613
|
+
if self.closed or intent.operation_id in self.outcome_by_id:
|
|
614
|
+
return False
|
|
615
|
+
self.context_by_key[intent.key] = intent.context
|
|
616
|
+
if intent.capability != WindowCapability.MANAGE or self.policy_diagnostic(intent) or self.allows is not None and not self.allows(intent):
|
|
617
|
+
return False
|
|
618
|
+
if intent.common_git_dir != canonical_path(intent.context.common_git_dir) or intent.key != WorktreeKey.from_context(intent.context):
|
|
619
|
+
return False
|
|
620
|
+
previous = self.active_by_id.get(intent.operation_id)
|
|
621
|
+
if previous is not None:
|
|
622
|
+
return previous == intent
|
|
623
|
+
for active in self.active_by_id.values():
|
|
624
|
+
if self._conflicts(active, intent):
|
|
625
|
+
return False
|
|
626
|
+
self.active_by_id[intent.operation_id] = intent
|
|
627
|
+
self.changed.emit()
|
|
628
|
+
return True
|
|
629
|
+
|
|
630
|
+
def refusal_cause(self, intent: OperationIntent) -> str:
|
|
631
|
+
"""Say why ``reserve`` refused this write, naming a running operation only when one really holds the repository.
|
|
632
|
+
|
|
633
|
+
A closing GitPane comes before everything else: waiting for a running operation would be useless, since the
|
|
634
|
+
write is never accepted again. Without such an operation, the write lost its authority: the reason is the one
|
|
635
|
+
``authority_cause`` gives.
|
|
636
|
+
"""
|
|
637
|
+
if self.closed:
|
|
638
|
+
return GITPANE_CLOSING_TEXT
|
|
639
|
+
active = self.conflicting_owner(intent)
|
|
640
|
+
if active is not None and active.operation_id != intent.operation_id:
|
|
641
|
+
return OWNED_REPOSITORY_TEXT
|
|
642
|
+
return self.authority_cause(intent)
|
|
643
|
+
|
|
644
|
+
def authority_cause(self, intent: OperationIntent) -> str:
|
|
645
|
+
"""Say why a write lost its authority, without looking at the operations running on the repository.
|
|
646
|
+
|
|
647
|
+
For a caller that already knows its window is stale: naming another running operation would make the user
|
|
648
|
+
wait for nothing, since the write stays refused once that operation finishes. A closing GitPane comes before
|
|
649
|
+
the application's policy, since no write is accepted any more.
|
|
650
|
+
"""
|
|
651
|
+
if self.closed:
|
|
652
|
+
return GITPANE_CLOSING_TEXT
|
|
653
|
+
reason = self.policy_diagnostic(intent)
|
|
654
|
+
if reason:
|
|
655
|
+
return reason
|
|
656
|
+
if self.explains is not None:
|
|
657
|
+
reason = self.explains(intent)
|
|
658
|
+
if reason:
|
|
659
|
+
return reason
|
|
660
|
+
return NO_LONGER_AUTHORIZED_TEXT
|
|
661
|
+
|
|
662
|
+
def extend(self, intent: OperationIntent) -> bool:
|
|
663
|
+
"""Atomically add discovered repository identities without releasing the original scope."""
|
|
664
|
+
from dataclasses import replace
|
|
665
|
+
|
|
666
|
+
previous = self.active_by_id.get(intent.operation_id)
|
|
667
|
+
if previous is None or replace(intent, reserved_repository_dirs=previous.reserved_repository_dirs, reserved_contexts=previous.reserved_contexts, scope=previous.scope) != previous:
|
|
668
|
+
return False
|
|
669
|
+
if previous.scope is None or intent.scope is None or replace(intent.scope, refs=previous.scope.refs) != previous.scope or not set(previous.scope.refs).issubset(intent.scope.refs):
|
|
670
|
+
return False
|
|
671
|
+
if not set(previous.reserved_repository_dirs).issubset(intent.reserved_repository_dirs) or not set(previous.reserved_contexts).issubset(intent.reserved_contexts):
|
|
672
|
+
return False
|
|
673
|
+
if self.policy_diagnostic(intent):
|
|
674
|
+
return False
|
|
675
|
+
for active in self.active_by_id.values():
|
|
676
|
+
if active.operation_id != intent.operation_id and self._conflicts(active, intent):
|
|
677
|
+
return False
|
|
678
|
+
self.active_by_id[intent.operation_id] = intent
|
|
679
|
+
return True
|
|
680
|
+
|
|
681
|
+
def owns_worktree(self, key: WorktreeKey) -> bool:
|
|
682
|
+
"""Tell whether a reserved operation currently holds this working tree, so passive reads can leave it alone."""
|
|
683
|
+
for intent in self.active_by_id.values():
|
|
684
|
+
if intent.key == key:
|
|
685
|
+
return True
|
|
686
|
+
for context in intent.reserved_contexts:
|
|
687
|
+
if WorktreeKey.from_context(context) == key:
|
|
688
|
+
return True
|
|
689
|
+
return False
|
|
690
|
+
|
|
691
|
+
def _conflicts(self, first: OperationIntent, second: OperationIntent) -> bool:
|
|
692
|
+
"""Compare Git storage identities and canonical subtree boundaries in both directions."""
|
|
693
|
+
if first.global_configuration or second.global_configuration:
|
|
694
|
+
return True
|
|
695
|
+
first_contexts = (first.context, *first.reserved_contexts)
|
|
696
|
+
second_contexts = (second.context, *second.reserved_contexts)
|
|
697
|
+
for left in first_contexts:
|
|
698
|
+
for right in second_contexts:
|
|
699
|
+
if canonical_path(left.common_git_dir) == canonical_path(right.common_git_dir) or WorktreeKey.from_context(left) == WorktreeKey.from_context(right):
|
|
700
|
+
return True
|
|
701
|
+
for owner, other, contexts in ((first, second, second_contexts), (second, first, first_contexts)):
|
|
702
|
+
candidate_dirs = (*other.reserved_repository_dirs, *(context.repository_dir for context in contexts))
|
|
703
|
+
for root_dir in owner.reserved_repository_dirs:
|
|
704
|
+
for candidate_dir in candidate_dirs:
|
|
705
|
+
try:
|
|
706
|
+
if os.path.commonpath((canonical_path(root_dir), canonical_path(candidate_dir))) == canonical_path(root_dir):
|
|
707
|
+
return True
|
|
708
|
+
except ValueError:
|
|
709
|
+
continue
|
|
710
|
+
return False
|
|
711
|
+
|
|
712
|
+
def submit(self, intent: OperationIntent, sequence: Generator) -> str:
|
|
713
|
+
"""Run one captured sequence once; its result must include observed effects.
|
|
714
|
+
|
|
715
|
+
The sequence imposes no profile: every command that writes declares its own, and the others start as reads.
|
|
716
|
+
"""
|
|
717
|
+
if intent.operation_id in self.submitted_id_set or intent.operation_id in self.outcome_by_id:
|
|
718
|
+
sequence.close()
|
|
719
|
+
return intent.operation_id
|
|
720
|
+
if intent.operation_id in self.active_by_id:
|
|
721
|
+
sequence.close()
|
|
722
|
+
return intent.operation_id
|
|
723
|
+
if not self.reserve(intent):
|
|
724
|
+
sequence.close()
|
|
725
|
+
availability = self.availability(intent)
|
|
726
|
+
cause = availability.reason if availability.owner_operation_id is not None else self.authority_cause(intent)
|
|
727
|
+
# Only a running operation refuses a write for a reason that passes by itself; every other reason means the
|
|
728
|
+
# capture or its authority no longer holds.
|
|
729
|
+
outcome = OperationOutcome(intent.operation_id, OperationStatus.REFUSED, diagnostic=self._diagnostic(intent, cause), stale_capture=availability.owner_operation_id is None)
|
|
730
|
+
self.outcome_by_id[intent.operation_id] = outcome
|
|
731
|
+
QTimer.singleShot(0, self, lambda: self.finished.emit(outcome))
|
|
732
|
+
return intent.operation_id
|
|
733
|
+
self.submitted_id_set.add(intent.operation_id)
|
|
734
|
+
|
|
735
|
+
def complete(value: object, error: Exception | None) -> None:
|
|
736
|
+
"""Publish after the generator has drained processes and inspected final state."""
|
|
737
|
+
if error is not None:
|
|
738
|
+
diagnostic = error.diagnostic if isinstance(error, GitCommandError) else self._diagnostic(intent, str(error))
|
|
739
|
+
process_status = error.process_status if isinstance(error, GitCommandError) else None
|
|
740
|
+
return_code = error.return_code if isinstance(error, GitCommandError) else None
|
|
741
|
+
step = OperationStepResult(intent.operation, OperationStatus.FAILED, process_status=process_status, diagnostic=diagnostic, return_code=return_code)
|
|
742
|
+
value = OperationOutcome(intent.operation_id, OperationStatus.UNKNOWN, (step,), diagnostic)
|
|
743
|
+
elif not isinstance(value, OperationOutcome) or value.operation_id != intent.operation_id:
|
|
744
|
+
value = OperationOutcome(intent.operation_id, OperationStatus.UNKNOWN, diagnostic=self._diagnostic(intent, "The operation did not provide a reconciled result"))
|
|
745
|
+
self.reconcile(value)
|
|
746
|
+
|
|
747
|
+
self.worktree_service.run(intent.context, intent.git_filename, sequence, complete, operation_id=intent.operation_id)
|
|
748
|
+
return intent.operation_id
|
|
749
|
+
|
|
750
|
+
def reconcile(self, outcome: OperationOutcome) -> None:
|
|
751
|
+
"""Retain the observed terminal result before releasing its exact reservation."""
|
|
752
|
+
if outcome.operation_id in self.outcome_by_id:
|
|
753
|
+
return
|
|
754
|
+
if outcome.operation_id not in self.active_by_id:
|
|
755
|
+
raise ValueError("The operation does not own a reservation")
|
|
756
|
+
self.outcome_by_id[outcome.operation_id] = outcome
|
|
757
|
+
self.submitted_id_set.discard(outcome.operation_id)
|
|
758
|
+
self.release(outcome.operation_id)
|
|
759
|
+
self.finished.emit(outcome)
|
|
760
|
+
|
|
761
|
+
def release(self, operation_id: str) -> None:
|
|
762
|
+
"""Release an external owner's completed work without touching native Git locks."""
|
|
763
|
+
if operation_id in self.submitted_id_set:
|
|
764
|
+
raise ValueError("A running operation must reconcile before release")
|
|
765
|
+
removed = self.active_by_id.pop(operation_id, None)
|
|
766
|
+
if removed is not None:
|
|
767
|
+
self.changed.emit()
|
|
768
|
+
if removed is not None and not self.active_by_id:
|
|
769
|
+
QTimer.singleShot(0, self, self._emit_idle)
|
|
770
|
+
|
|
771
|
+
def _emit_idle(self) -> None:
|
|
772
|
+
"""Notify shutdown after owners have published outcomes and only if still idle."""
|
|
773
|
+
if not self.active_by_id:
|
|
774
|
+
self.idle.emit()
|
|
775
|
+
|
|
776
|
+
def close(self) -> None:
|
|
777
|
+
"""Invalidate new intentions while existing owners finish and preserve their results."""
|
|
778
|
+
self.closed = True
|
|
779
|
+
|
|
780
|
+
def _diagnostic(self, intent: OperationIntent, cause: str) -> PreparedDiagnostic:
|
|
781
|
+
return Diagnostic(intent.operation, intent.context.repository_dir, intent.git_filename, [], cause).prepare()
|