codis 1.1.1__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.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/ui/git_panel.py
ADDED
|
@@ -0,0 +1,1483 @@
|
|
|
1
|
+
"""Painel de controle Git integrado ao Codis.
|
|
2
|
+
|
|
3
|
+
Provê ``GitPanel``, que exibe status, diff, log, branches e permite
|
|
4
|
+
operações de commit, push, pull, stash e merge diretamente na interface,
|
|
5
|
+
sem necessidade de terminal.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import contextlib
|
|
11
|
+
import logging
|
|
12
|
+
import shutil
|
|
13
|
+
import subprocess
|
|
14
|
+
import threading
|
|
15
|
+
import tkinter as tk
|
|
16
|
+
from collections.abc import Callable
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from tkinter import messagebox, simpledialog, ttk
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from src import proc_registry
|
|
22
|
+
from src.config import ConfigManager
|
|
23
|
+
from src.constants import (
|
|
24
|
+
FONT_MONO,
|
|
25
|
+
FONT_UI,
|
|
26
|
+
)
|
|
27
|
+
from src.i18n import _t
|
|
28
|
+
from src.theme.base import Theme
|
|
29
|
+
from src.theme.manager import ThemeManager
|
|
30
|
+
from src.ui.dropdown import DropDown
|
|
31
|
+
from src.ui.git_auth import GitAuthManager, _host_from_url, is_auth_error
|
|
32
|
+
from src.ui.grab_safe import safe_grab_set
|
|
33
|
+
|
|
34
|
+
logger = logging.getLogger("Codis")
|
|
35
|
+
|
|
36
|
+
def _run(*args, **kwargs):
|
|
37
|
+
"""``subprocess.run`` registrado como tarefa do Git, para o Gerenciador de Processos poder encerrá-lo."""
|
|
38
|
+
return proc_registry.run(*args, kind="git", **kwargs)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class _LogTextStub:
|
|
43
|
+
"""Stub que emula a interface mínima de tk.Text usada para o log de commits,
|
|
44
|
+
redirecionando inserções para o Listbox interativo."""
|
|
45
|
+
|
|
46
|
+
def __init__(self, listbox: tk.Listbox, hashes: list) -> None:
|
|
47
|
+
self._lb = listbox
|
|
48
|
+
self._hashes = hashes
|
|
49
|
+
|
|
50
|
+
def config(self, **_kw) -> None:
|
|
51
|
+
"""Absorve chamadas de configuração de estado (ex.: ``state="disabled"``).
|
|
52
|
+
|
|
53
|
+
Este adaptador expõe a interface de um widget ``tk.Text`` sobre um
|
|
54
|
+
``tk.Listbox``; chamadas ``config()`` são ignoradas intencionalmente,
|
|
55
|
+
pois o Listbox não requer gerenciamento de estado externo.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def delete(self, _start: str, _end: str) -> None:
|
|
59
|
+
"""Limpa o conteúdo do Listbox."""
|
|
60
|
+
self._lb.delete(0, "end")
|
|
61
|
+
self._hashes.clear()
|
|
62
|
+
|
|
63
|
+
def insert(self, _index: str, text: str) -> None:
|
|
64
|
+
"""Insere linhas de texto no Listbox."""
|
|
65
|
+
for line in text.strip().splitlines():
|
|
66
|
+
line = line.strip()
|
|
67
|
+
if not line:
|
|
68
|
+
continue
|
|
69
|
+
parts = line.split(" ", 1)
|
|
70
|
+
hash_ = parts[0] if parts else ""
|
|
71
|
+
self._hashes.append(hash_)
|
|
72
|
+
self._lb.insert("end", f" {line}")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class GitPanel(tk.Frame):
|
|
76
|
+
"""
|
|
77
|
+
Controle de Código Fonte:
|
|
78
|
+
- Seções colapsáveis: Staged / Changes / Untracked
|
|
79
|
+
- Stage/unstage/discard individuais e em massa
|
|
80
|
+
- Commit com validação de mensagem (resiste a paste)
|
|
81
|
+
- Push/Pull/Fetch em thread com indicador de progresso
|
|
82
|
+
- Ahead/behind do remote
|
|
83
|
+
- Stash rápido (Stash / Pop Stash)
|
|
84
|
+
- Diff inline ao clicar num arquivo
|
|
85
|
+
- Branch switch/create/delete
|
|
86
|
+
- Log compacto com navegação e exploração de commits
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
def __init__(
|
|
90
|
+
self,
|
|
91
|
+
parent: tk.Widget,
|
|
92
|
+
tmgr: ThemeManager,
|
|
93
|
+
cfg: ConfigManager,
|
|
94
|
+
root_path: Path | None = None,
|
|
95
|
+
on_refresh: Callable | None = None,
|
|
96
|
+
on_show_diff: Callable[[str, str, str, str], None] | None = None,
|
|
97
|
+
root_win: tk.Tk | None = None,
|
|
98
|
+
on_commit: Callable[[str], None] | None = None,
|
|
99
|
+
) -> None:
|
|
100
|
+
"""Cria o painel de integração Git do Codis.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
parent: Widget pai Tkinter.
|
|
104
|
+
tmgr: Instância de ThemeManager.
|
|
105
|
+
cfg: Instância de ConfigManager.
|
|
106
|
+
root_path: Caminho raiz do repositório Git.
|
|
107
|
+
on_refresh: Callback chamado após refresh do status.
|
|
108
|
+
on_show_diff: Callback(orig, mod, label_a, label_b) para exibir diff.
|
|
109
|
+
root_win: Janela raiz Tkinter, necessária para diálogos de autenticação.
|
|
110
|
+
on_commit: Callback(mensagem) chamado depois de um commit bem-sucedido.
|
|
111
|
+
"""
|
|
112
|
+
t = tmgr.theme
|
|
113
|
+
super().__init__(parent, bg=t.panel_bg)
|
|
114
|
+
self._tmgr = tmgr
|
|
115
|
+
self._cfg = cfg
|
|
116
|
+
self._git_root = root_path
|
|
117
|
+
self._on_refresh = on_refresh
|
|
118
|
+
self._on_show_diff = on_show_diff
|
|
119
|
+
self._on_commit = on_commit
|
|
120
|
+
self._busy = False
|
|
121
|
+
self._cached_remote_url: str | None = None
|
|
122
|
+
|
|
123
|
+
_root = root_win or self.winfo_toplevel()
|
|
124
|
+
self._auth = GitAuthManager(cfg, _root)
|
|
125
|
+
self._git_available = shutil.which("git") is not None
|
|
126
|
+
self._build()
|
|
127
|
+
if not self._git_available:
|
|
128
|
+
self.after(
|
|
129
|
+
100,
|
|
130
|
+
lambda: messagebox.showwarning(
|
|
131
|
+
_t("git.no_git_title", "Git não encontrado"),
|
|
132
|
+
_t(
|
|
133
|
+
"git.no_git_msg",
|
|
134
|
+
"O executável 'git' não foi encontrado no PATH do sistema.\n\n"
|
|
135
|
+
"Instale o Git (https://git-scm.com/downloads) para usar o\n"
|
|
136
|
+
"controle de código-fonte no Codis.",
|
|
137
|
+
),
|
|
138
|
+
parent=self,
|
|
139
|
+
),
|
|
140
|
+
)
|
|
141
|
+
elif root_path:
|
|
142
|
+
self.after(100, self.refresh)
|
|
143
|
+
|
|
144
|
+
def _build(self) -> None:
|
|
145
|
+
t = self._tmgr.theme
|
|
146
|
+
|
|
147
|
+
accent_strip = tk.Frame(self, bg=getattr(
|
|
148
|
+
t, "accent", t.t_func), height=2)
|
|
149
|
+
accent_strip.pack(fill="x")
|
|
150
|
+
|
|
151
|
+
hdr = tk.Frame(self, bg=t.panel_bg, height=34)
|
|
152
|
+
hdr.pack(fill="x")
|
|
153
|
+
hdr.pack_propagate(False)
|
|
154
|
+
tk.Label(
|
|
155
|
+
hdr,
|
|
156
|
+
text="🌿 " + _t("hc.git_panel.source_control"),
|
|
157
|
+
bg=t.panel_bg,
|
|
158
|
+
fg=t.sidebar_header_fg,
|
|
159
|
+
font=(FONT_UI, 9, "bold"),
|
|
160
|
+
).pack(side="left", padx=6)
|
|
161
|
+
|
|
162
|
+
def _hbtn(
|
|
163
|
+
text: str, cmd: Any, bg: str | None = None, tooltip: str = ""
|
|
164
|
+
) -> None:
|
|
165
|
+
bg_c = bg or t.btn_bg
|
|
166
|
+
fg_c = "#000" if bg_c == t.accent else t.fg
|
|
167
|
+
b = tk.Label(
|
|
168
|
+
hdr,
|
|
169
|
+
text=text,
|
|
170
|
+
bg=bg_c,
|
|
171
|
+
fg=fg_c,
|
|
172
|
+
font=(FONT_UI, 8),
|
|
173
|
+
cursor="hand2",
|
|
174
|
+
padx=6,
|
|
175
|
+
pady=3,
|
|
176
|
+
relief="flat",
|
|
177
|
+
)
|
|
178
|
+
b.pack(side="right", padx=1, pady=4)
|
|
179
|
+
b.bind("<Button-1>", lambda _: cmd())
|
|
180
|
+
b.bind("<Enter>", lambda _: b.config(bg=t.btn_hover))
|
|
181
|
+
b.bind("<Leave>", lambda _: b.config(bg=bg_c))
|
|
182
|
+
|
|
183
|
+
_hbtn("↻", self.refresh, tooltip="Refresh")
|
|
184
|
+
_hbtn("↑ Push", self._push, bg=t.accent, tooltip="Push para remote")
|
|
185
|
+
_hbtn("↓ Pull", self._pull, tooltip="Pull do remote")
|
|
186
|
+
_hbtn("⟳ Fetch", self._fetch, tooltip="Fetch sem merge")
|
|
187
|
+
_hbtn("📦 Stash", self._stash, tooltip="Guardar alterações")
|
|
188
|
+
_hbtn("↩ Pop", self._pop_stash, tooltip="Restaurar stash")
|
|
189
|
+
_hbtn("🏷 Tag", self._create_tag, tooltip="Criar tag de versão")
|
|
190
|
+
_hbtn("⚙ Rebase", self._interactive_rebase, tooltip="Rebase interativo")
|
|
191
|
+
|
|
192
|
+
self._status_lbl = tk.Label(
|
|
193
|
+
self, text="", bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 8), anchor="w"
|
|
194
|
+
)
|
|
195
|
+
self._status_lbl.pack(fill="x", padx=8)
|
|
196
|
+
|
|
197
|
+
branch_f = tk.Frame(self, bg=t.panel_bg)
|
|
198
|
+
branch_f.pack(fill="x", padx=4, pady=2)
|
|
199
|
+
tk.Label(
|
|
200
|
+
branch_f, text="🌿", bg=t.panel_bg, fg=t.t_func, font=(FONT_UI, 10)
|
|
201
|
+
).pack(side="left")
|
|
202
|
+
self._branch_var = tk.StringVar(value="-")
|
|
203
|
+
self._branch_combo = DropDown(
|
|
204
|
+
branch_f,
|
|
205
|
+
textvariable=self._branch_var,
|
|
206
|
+
width=20,
|
|
207
|
+
font=(FONT_UI, 9),
|
|
208
|
+
state="readonly",
|
|
209
|
+
)
|
|
210
|
+
self._branch_combo.pack(side="left", padx=2)
|
|
211
|
+
self._branch_combo.bind("<<ComboboxSelected>>", self._switch_branch)
|
|
212
|
+
|
|
213
|
+
plus_lbl = tk.Label(
|
|
214
|
+
branch_f,
|
|
215
|
+
text="⊕",
|
|
216
|
+
bg=t.panel_bg,
|
|
217
|
+
fg=t.fg,
|
|
218
|
+
font=(FONT_UI, 11),
|
|
219
|
+
cursor="hand2",
|
|
220
|
+
)
|
|
221
|
+
plus_lbl.pack(side="left", padx=2)
|
|
222
|
+
plus_lbl.bind("<Button-1>", lambda _: self._create_branch())
|
|
223
|
+
|
|
224
|
+
msg_f = tk.Frame(self, bg=t.panel_bg)
|
|
225
|
+
msg_f.pack(fill="x", padx=4, pady=2)
|
|
226
|
+
self._msg_text = tk.Text(
|
|
227
|
+
msg_f,
|
|
228
|
+
bg=t.input_bg,
|
|
229
|
+
fg=t.fg,
|
|
230
|
+
insertbackground=t.cursor,
|
|
231
|
+
relief="flat",
|
|
232
|
+
bd=0,
|
|
233
|
+
height=3,
|
|
234
|
+
font=(FONT_UI, 9),
|
|
235
|
+
highlightthickness=1,
|
|
236
|
+
highlightbackground=t.border,
|
|
237
|
+
wrap="word",
|
|
238
|
+
padx=4,
|
|
239
|
+
pady=2,
|
|
240
|
+
)
|
|
241
|
+
self._msg_text.pack(fill="x")
|
|
242
|
+
self._placeholder = _t("ui.commit_placeholder")
|
|
243
|
+
self._msg_text.insert("1.0", self._placeholder)
|
|
244
|
+
self._msg_text.config(fg=t.fg_muted)
|
|
245
|
+
self._msg_text.bind("<FocusIn>", self._msg_focus_in)
|
|
246
|
+
self._msg_text.bind("<FocusOut>", self._msg_focus_out)
|
|
247
|
+
|
|
248
|
+
self._msg_text.bind("<<Paste>>", self._msg_on_paste)
|
|
249
|
+
|
|
250
|
+
btn_f = tk.Frame(self, bg=t.panel_bg)
|
|
251
|
+
btn_f.pack(fill="x", padx=4, pady=(0, 4))
|
|
252
|
+
self._btn(btn_f, "+ Stage All", self._stage_all, side="left")
|
|
253
|
+
self._btn(btn_f, "Commit", self._commit,
|
|
254
|
+
side="right", bg=t.accent, fg="#000")
|
|
255
|
+
|
|
256
|
+
tk.Frame(self, bg=t.border, height=1).pack(fill="x")
|
|
257
|
+
|
|
258
|
+
style = ttk.Style()
|
|
259
|
+
style.configure(
|
|
260
|
+
"Git.Treeview",
|
|
261
|
+
background=t.panel_bg,
|
|
262
|
+
foreground=t.fg,
|
|
263
|
+
fieldbackground=t.panel_bg,
|
|
264
|
+
borderwidth=0,
|
|
265
|
+
rowheight=20,
|
|
266
|
+
font=(FONT_UI, 9),
|
|
267
|
+
)
|
|
268
|
+
style.map(
|
|
269
|
+
"Git.Treeview",
|
|
270
|
+
background=[("selected", t.sel_bg)],
|
|
271
|
+
foreground=[("selected", t.sel_fg)],
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
tree_f = tk.Frame(self, bg=t.panel_bg)
|
|
275
|
+
tree_f.pack(fill="both", expand=True)
|
|
276
|
+
|
|
277
|
+
self._tree = ttk.Treeview(
|
|
278
|
+
tree_f, columns=(), show="tree", style="Git.Treeview", selectmode="browse"
|
|
279
|
+
)
|
|
280
|
+
vsb = ttk.Scrollbar(
|
|
281
|
+
tree_f,
|
|
282
|
+
orient="vertical",
|
|
283
|
+
command=self._tree.yview,
|
|
284
|
+
style="Thin.Vertical.TScrollbar",
|
|
285
|
+
)
|
|
286
|
+
vsb.pack(side="right", fill="y")
|
|
287
|
+
self._tree.config(yscrollcommand=vsb.set)
|
|
288
|
+
self._tree.pack(fill="both", expand=True)
|
|
289
|
+
|
|
290
|
+
self._tree.tag_configure(
|
|
291
|
+
"section", foreground=t.fg_muted, font=(FONT_UI, 9, "bold")
|
|
292
|
+
)
|
|
293
|
+
self._tree.tag_configure("staged", foreground=t.ok_fg)
|
|
294
|
+
self._tree.tag_configure("modified", foreground=t.warn_fg)
|
|
295
|
+
self._tree.tag_configure("untracked", foreground=t.fg_muted)
|
|
296
|
+
self._tree.tag_configure("deleted", foreground=t.fg_muted)
|
|
297
|
+
|
|
298
|
+
self._tree.bind("<Double-Button-1>", self._on_double)
|
|
299
|
+
self._tree.bind("<Return>", self._on_double)
|
|
300
|
+
self._tree.bind("<Button-3>", self._on_ctx)
|
|
301
|
+
|
|
302
|
+
self._item_meta: dict[str, tuple[str, str]] = {}
|
|
303
|
+
|
|
304
|
+
tk.Frame(self, bg=t.border, height=1).pack(fill="x")
|
|
305
|
+
log_hdr = tk.Frame(self, bg=t.panel_bg, height=22)
|
|
306
|
+
log_hdr.pack(fill="x")
|
|
307
|
+
log_hdr.pack_propagate(False)
|
|
308
|
+
tk.Label(
|
|
309
|
+
log_hdr,
|
|
310
|
+
text=_t("hc.git_panel.recent_commits"),
|
|
311
|
+
bg=t.panel_bg,
|
|
312
|
+
fg=t.sidebar_header_fg,
|
|
313
|
+
font=(FONT_UI, 8, "bold"),
|
|
314
|
+
).pack(side="left", padx=4)
|
|
315
|
+
tk.Label(
|
|
316
|
+
log_hdr,
|
|
317
|
+
text=_t("hc.git_panel.click_to_explore", "clique para explorar"),
|
|
318
|
+
bg=t.panel_bg,
|
|
319
|
+
fg=t.fg_muted,
|
|
320
|
+
font=(FONT_UI, 7),
|
|
321
|
+
).pack(side="right", padx=4)
|
|
322
|
+
|
|
323
|
+
log_frame = tk.Frame(self, bg=t.panel_bg)
|
|
324
|
+
log_frame.pack(fill="x")
|
|
325
|
+
self._log_listbox = tk.Listbox(
|
|
326
|
+
log_frame,
|
|
327
|
+
bg=t.panel_bg,
|
|
328
|
+
fg=t.fg_muted,
|
|
329
|
+
selectbackground=getattr(t, "accent", t.t_func),
|
|
330
|
+
selectforeground=t.editor_bg,
|
|
331
|
+
relief="flat",
|
|
332
|
+
bd=0,
|
|
333
|
+
height=5,
|
|
334
|
+
font=(FONT_MONO, 8),
|
|
335
|
+
highlightthickness=0,
|
|
336
|
+
activestyle="none",
|
|
337
|
+
cursor="hand2",
|
|
338
|
+
)
|
|
339
|
+
self._log_listbox.pack(fill="x", side="left", expand=True)
|
|
340
|
+
self._log_listbox.bind("<ButtonRelease-1>", self._on_commit_click)
|
|
341
|
+
self._log_listbox.bind("<Return>", self._on_commit_click)
|
|
342
|
+
self._commit_hashes: list[str] = []
|
|
343
|
+
|
|
344
|
+
self._log_text = _LogTextStub(self._log_listbox, self._commit_hashes)
|
|
345
|
+
|
|
346
|
+
def _btn(
|
|
347
|
+
self,
|
|
348
|
+
parent: tk.Widget,
|
|
349
|
+
text: str,
|
|
350
|
+
cmd: Callable,
|
|
351
|
+
side: str = "left",
|
|
352
|
+
bg: str | None = None,
|
|
353
|
+
fg: str | None = None,
|
|
354
|
+
) -> tk.Label:
|
|
355
|
+
"""Cria e retorna um botão estilizado.
|
|
356
|
+
|
|
357
|
+
Args:
|
|
358
|
+
parent: Widget pai Tkinter.
|
|
359
|
+
text: Dado textual a processar.
|
|
360
|
+
"""
|
|
361
|
+
t = self._tmgr.theme
|
|
362
|
+
lbl = tk.Label(
|
|
363
|
+
parent,
|
|
364
|
+
text=text,
|
|
365
|
+
bg=bg or t.btn_bg,
|
|
366
|
+
fg=fg or t.fg,
|
|
367
|
+
font=(FONT_UI, 8),
|
|
368
|
+
padx=8,
|
|
369
|
+
pady=2,
|
|
370
|
+
cursor="hand2",
|
|
371
|
+
relief="flat",
|
|
372
|
+
)
|
|
373
|
+
lbl.pack(side=side, padx=2, pady=2)
|
|
374
|
+
lbl.bind("<Button-1>", lambda _: cmd())
|
|
375
|
+
hover = t.btn_hover if bg != t.accent else t.btn_primary
|
|
376
|
+
lbl.bind("<Enter>", lambda _: lbl.config(bg=hover))
|
|
377
|
+
lbl.bind("<Leave>", lambda _: lbl.config(bg=bg or t.btn_bg))
|
|
378
|
+
return lbl
|
|
379
|
+
|
|
380
|
+
def _set_status(self, text: str) -> None:
|
|
381
|
+
"""Mostra uma mensagem curta de resultado (ex.: ``Stash salvo.``) abaixo dos botões."""
|
|
382
|
+
self._status_lbl.config(text=text)
|
|
383
|
+
|
|
384
|
+
def _git(self, *args, timeout: int = 15) -> tuple[int, str, str]:
|
|
385
|
+
"""Executa comando Git e retorna (returncode, stdout, stderr).
|
|
386
|
+
|
|
387
|
+
Injeta variáveis de ambiente de autenticação automaticamente
|
|
388
|
+
quando há credenciais salvas para o remote atual.
|
|
389
|
+
|
|
390
|
+
Args:
|
|
391
|
+
*args: Argumentos do comando Git.
|
|
392
|
+
timeout: Timeout em segundos.
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
tuple[int, str, str]: (returncode, stdout, stderr).
|
|
396
|
+
"""
|
|
397
|
+
if not self._git_root:
|
|
398
|
+
return -1, "", "no root"
|
|
399
|
+
try:
|
|
400
|
+
if self._cached_remote_url is None:
|
|
401
|
+
self._cached_remote_url = self._detect_remote_url() or ""
|
|
402
|
+
remote_url = self._cached_remote_url or None
|
|
403
|
+
env = self._auth.build_env(remote_url) if remote_url else None
|
|
404
|
+
|
|
405
|
+
r = _run(
|
|
406
|
+
["git"] + list(args),
|
|
407
|
+
capture_output=True,
|
|
408
|
+
text=True,
|
|
409
|
+
encoding="utf-8",
|
|
410
|
+
errors="replace",
|
|
411
|
+
cwd=str(self._git_root),
|
|
412
|
+
timeout=timeout,
|
|
413
|
+
check=False,
|
|
414
|
+
**({"env": env} if env else {}),
|
|
415
|
+
)
|
|
416
|
+
return r.returncode, r.stdout, r.stderr
|
|
417
|
+
except FileNotFoundError:
|
|
418
|
+
return (
|
|
419
|
+
-1,
|
|
420
|
+
"",
|
|
421
|
+
_t(
|
|
422
|
+
"git.no_git_msg_short",
|
|
423
|
+
"Git não encontrado. Instale o Git para usar esta função.",
|
|
424
|
+
),
|
|
425
|
+
)
|
|
426
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
427
|
+
return -1, "", str(exc)
|
|
428
|
+
|
|
429
|
+
def _detect_remote_url(self) -> str | None:
|
|
430
|
+
"""Detecta a URL do remote 'origin' do repositório atual.
|
|
431
|
+
|
|
432
|
+
Returns:
|
|
433
|
+
str | None: URL do remote ou None se não encontrado.
|
|
434
|
+
"""
|
|
435
|
+
with contextlib.suppress(OSError, FileNotFoundError):
|
|
436
|
+
r = _run(
|
|
437
|
+
["git", "remote", "get-url", "origin"],
|
|
438
|
+
capture_output=True,
|
|
439
|
+
text=True,
|
|
440
|
+
encoding="utf-8",
|
|
441
|
+
errors="replace",
|
|
442
|
+
cwd=str(self._git_root),
|
|
443
|
+
timeout=5,
|
|
444
|
+
check=False,
|
|
445
|
+
)
|
|
446
|
+
if r.returncode == 0:
|
|
447
|
+
return r.stdout.strip()
|
|
448
|
+
return None
|
|
449
|
+
|
|
450
|
+
def set_root(self, path: Path) -> None:
|
|
451
|
+
"""Aponta o painel para outro repositório e atualiza o status."""
|
|
452
|
+
if self._git_root == path:
|
|
453
|
+
return
|
|
454
|
+
self._git_root = path
|
|
455
|
+
self._cached_remote_url = None
|
|
456
|
+
self.refresh()
|
|
457
|
+
|
|
458
|
+
def refresh(self) -> None:
|
|
459
|
+
"""Atualiza o status do repositório e a lista de arquivos."""
|
|
460
|
+
if not self._git_root:
|
|
461
|
+
return
|
|
462
|
+
|
|
463
|
+
def _work():
|
|
464
|
+
rc_s, out_s, _ = self._git("status", "--porcelain", "-u")
|
|
465
|
+
rc_b, out_b, _ = self._git("branch", "--format=%(refname:short)")
|
|
466
|
+
rc_c, out_c, _ = self._git("branch", "--show-current")
|
|
467
|
+
rc_l, out_l, _ = self._git(
|
|
468
|
+
"log", "--oneline", "-20", "--format=%h %s (%an, %ar)"
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
rc_ab, out_ab, _ = self._git(
|
|
472
|
+
"rev-list", "--left-right", "--count", "@{upstream}...HEAD"
|
|
473
|
+
)
|
|
474
|
+
self.after(
|
|
475
|
+
0,
|
|
476
|
+
lambda: self._apply_refresh(
|
|
477
|
+
out_s if rc_s == 0 else "",
|
|
478
|
+
out_b if rc_b == 0 else "",
|
|
479
|
+
out_c if rc_c == 0 else "",
|
|
480
|
+
out_l if rc_l == 0 else "",
|
|
481
|
+
out_ab if rc_ab == 0 else "",
|
|
482
|
+
),
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
threading.Thread(target=_work, daemon=True).start()
|
|
486
|
+
|
|
487
|
+
def _apply_refresh(
|
|
488
|
+
self,
|
|
489
|
+
status_out: str,
|
|
490
|
+
branches_out: str,
|
|
491
|
+
current_out: str,
|
|
492
|
+
log_out: str,
|
|
493
|
+
ahead_behind: str,
|
|
494
|
+
) -> None:
|
|
495
|
+
"""Atualiza a UI - chamado sempre na main thread via after()."""
|
|
496
|
+
|
|
497
|
+
try:
|
|
498
|
+
if not self.winfo_exists():
|
|
499
|
+
return
|
|
500
|
+
except tk.TclError:
|
|
501
|
+
return
|
|
502
|
+
for item in self._tree.get_children():
|
|
503
|
+
self._tree.delete(item)
|
|
504
|
+
self._item_meta.clear()
|
|
505
|
+
|
|
506
|
+
staged: list[tuple[str, str]] = []
|
|
507
|
+
unstaged: list[tuple[str, str]] = []
|
|
508
|
+
untracked: list[str] = []
|
|
509
|
+
|
|
510
|
+
for line in status_out.splitlines():
|
|
511
|
+
if len(line) < 4:
|
|
512
|
+
continue
|
|
513
|
+
x, y = line[0], line[1]
|
|
514
|
+
|
|
515
|
+
fname = line[3:].strip()
|
|
516
|
+
if " -> " in fname:
|
|
517
|
+
fname = fname.split(" -> ", 1)[1]
|
|
518
|
+
if x not in (" ", "?"):
|
|
519
|
+
staged.append((x, fname))
|
|
520
|
+
if y not in (" ",) or x == "?":
|
|
521
|
+
if x == "?":
|
|
522
|
+
untracked.append(fname)
|
|
523
|
+
else:
|
|
524
|
+
unstaged.append((y, fname))
|
|
525
|
+
|
|
526
|
+
def _section(title: str, count: int) -> str:
|
|
527
|
+
return self._tree.insert(
|
|
528
|
+
"", "end", text=f" {title} ({count})", tags=("section",), open=True
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
if staged:
|
|
532
|
+
node = _section("STAGED CHANGES", len(staged))
|
|
533
|
+
for x, f in staged:
|
|
534
|
+
icon = {"M": "✎", "A": "+", "D": "✖", "R": "➜"}.get(x, x)
|
|
535
|
+
iid = self._tree.insert(
|
|
536
|
+
node, "end", text=f" {icon} {f}", tags=("staged",)
|
|
537
|
+
)
|
|
538
|
+
self._item_meta[iid] = (f, "staged")
|
|
539
|
+
|
|
540
|
+
if unstaged:
|
|
541
|
+
node = _section("CHANGES", len(unstaged))
|
|
542
|
+
for y, f in unstaged:
|
|
543
|
+
icon = {"M": "✎", "D": "✖"}.get(y, y)
|
|
544
|
+
iid = self._tree.insert(
|
|
545
|
+
node, "end", text=f" {icon} {f}", tags=("modified",)
|
|
546
|
+
)
|
|
547
|
+
self._item_meta[iid] = (f, "unstaged")
|
|
548
|
+
|
|
549
|
+
if untracked:
|
|
550
|
+
node = _section("UNTRACKED", len(untracked))
|
|
551
|
+
for f in untracked:
|
|
552
|
+
iid = self._tree.insert(
|
|
553
|
+
node, "end", text=f" ? {f}", tags=("untracked",)
|
|
554
|
+
)
|
|
555
|
+
self._item_meta[iid] = (f, "untracked")
|
|
556
|
+
|
|
557
|
+
if not (staged or unstaged or untracked):
|
|
558
|
+
self._tree.insert(
|
|
559
|
+
"", "end", text=_t("hc.git_panel.no_changes"), tags=("staged",)
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
branches = [b.strip() for b in branches_out.splitlines() if b.strip()]
|
|
563
|
+
self._branch_combo["values"] = branches
|
|
564
|
+
cur = current_out.strip()
|
|
565
|
+
if cur:
|
|
566
|
+
self._branch_var.set(cur)
|
|
567
|
+
elif branches:
|
|
568
|
+
self._branch_var.set(branches[0])
|
|
569
|
+
|
|
570
|
+
ab = ahead_behind.strip()
|
|
571
|
+
if ab:
|
|
572
|
+
parts = ab.split()
|
|
573
|
+
if len(parts) == 2:
|
|
574
|
+
try:
|
|
575
|
+
behind, ahead = int(parts[0]), int(parts[1])
|
|
576
|
+
parts_str = []
|
|
577
|
+
if ahead:
|
|
578
|
+
parts_str.append(f"↑{ahead}")
|
|
579
|
+
if behind:
|
|
580
|
+
parts_str.append(f"↓{behind}")
|
|
581
|
+
self._status_lbl.config(
|
|
582
|
+
text=" " + " ".join(parts_str) if parts_str else ""
|
|
583
|
+
)
|
|
584
|
+
except ValueError:
|
|
585
|
+
self._status_lbl.config(text="")
|
|
586
|
+
|
|
587
|
+
self._log_text.config(state="normal")
|
|
588
|
+
self._log_text.delete("1.0", "end")
|
|
589
|
+
if log_out:
|
|
590
|
+
self._log_text.insert("1.0", log_out.strip())
|
|
591
|
+
self._log_text.config(state="disabled")
|
|
592
|
+
|
|
593
|
+
if self._on_refresh:
|
|
594
|
+
with contextlib.suppress(tk.TclError):
|
|
595
|
+
self._on_refresh()
|
|
596
|
+
|
|
597
|
+
def _stage(self, fname: str) -> None:
|
|
598
|
+
self._git("add", "--", fname)
|
|
599
|
+
self.refresh()
|
|
600
|
+
|
|
601
|
+
def _stage_all(self) -> None:
|
|
602
|
+
"""Adiciona todos os arquivos modificados ao staging area."""
|
|
603
|
+
self._git("add", "-A")
|
|
604
|
+
self.refresh()
|
|
605
|
+
|
|
606
|
+
def _unstage(self, fname: str) -> None:
|
|
607
|
+
self._git("restore", "--staged", "--", fname)
|
|
608
|
+
self.refresh()
|
|
609
|
+
|
|
610
|
+
def _discard(self, fname: str) -> None:
|
|
611
|
+
if messagebox.askyesno(
|
|
612
|
+
_t("hc.git_panel.discard"), f"Discard changes to '{fname}'?", parent=self
|
|
613
|
+
):
|
|
614
|
+
self._git("restore", "--", fname)
|
|
615
|
+
self.refresh()
|
|
616
|
+
|
|
617
|
+
def _commit(self) -> None:
|
|
618
|
+
"""Executa o commit com a mensagem do campo de texto."""
|
|
619
|
+
msg = self._msg_text.get("1.0", "end-1c").strip()
|
|
620
|
+
if not msg or msg == self._placeholder:
|
|
621
|
+
messagebox.showwarning(
|
|
622
|
+
_t("menu.git"), _t("msg.git_commit_empty"), parent=self
|
|
623
|
+
)
|
|
624
|
+
return
|
|
625
|
+
|
|
626
|
+
if self._git_root:
|
|
627
|
+
local_trash = Path(self._git_root) / ".codis_trash"
|
|
628
|
+
gi = local_trash / ".gitignore"
|
|
629
|
+
if local_trash.is_dir() and not gi.exists():
|
|
630
|
+
with contextlib.suppress(OSError):
|
|
631
|
+
gi.write_text("# Lixeira local do Codis - não versionar\n*\n", encoding="utf-8")
|
|
632
|
+
|
|
633
|
+
rc, out, err = self._git("commit", "-m", msg)
|
|
634
|
+
if rc == 0:
|
|
635
|
+
self._msg_text.delete("1.0", "end")
|
|
636
|
+
self._msg_text.insert("1.0", self._placeholder)
|
|
637
|
+
self._msg_text.config(fg=self._tmgr.theme.fg_muted)
|
|
638
|
+
self.refresh()
|
|
639
|
+
if self._on_commit is not None:
|
|
640
|
+
self._on_commit(msg)
|
|
641
|
+
else:
|
|
642
|
+
messagebox.showerror(
|
|
643
|
+
_t("hc.git_panel.commit_failed"), err or out, parent=self
|
|
644
|
+
)
|
|
645
|
+
|
|
646
|
+
def _push(self) -> None:
|
|
647
|
+
"""Executa git push para o remote e branch configurados."""
|
|
648
|
+
self._run_async("push", timeout=30)
|
|
649
|
+
|
|
650
|
+
def _pull(self) -> None:
|
|
651
|
+
"""Executa git pull do remote e branch configurados."""
|
|
652
|
+
self._run_async("pull", timeout=30)
|
|
653
|
+
|
|
654
|
+
def _fetch(self) -> None:
|
|
655
|
+
"""Executa git fetch para atualizar as referências remotas."""
|
|
656
|
+
self._run_async("fetch", timeout=20)
|
|
657
|
+
|
|
658
|
+
def _stash(self) -> None:
|
|
659
|
+
"""Abre painel de gestão completa de stashes."""
|
|
660
|
+
t = self._tmgr.theme
|
|
661
|
+
win = tk.Toplevel(self)
|
|
662
|
+
win.title(_t("hc.git_panel.stash_manager", "Gerenciador de Stash"))
|
|
663
|
+
win.configure(bg=t.floating_bg)
|
|
664
|
+
win.resizable(True, True)
|
|
665
|
+
win.geometry("500x420")
|
|
666
|
+
win.transient(self.winfo_toplevel())
|
|
667
|
+
|
|
668
|
+
hdr = tk.Frame(win, bg=t.floating_bg)
|
|
669
|
+
hdr.pack(fill="x", padx=16, pady=(14, 6))
|
|
670
|
+
tk.Label(
|
|
671
|
+
hdr,
|
|
672
|
+
text="📦 " + _t("hc.git_panel.stash_manager",
|
|
673
|
+
"Gerenciador de Stash"),
|
|
674
|
+
bg=t.floating_bg,
|
|
675
|
+
fg=t.fg,
|
|
676
|
+
font=(FONT_UI, 12, "bold"),
|
|
677
|
+
anchor="w",
|
|
678
|
+
).pack(side="left")
|
|
679
|
+
|
|
680
|
+
act_bar = tk.Frame(win, bg=t.floating_bg)
|
|
681
|
+
act_bar.pack(fill="x", padx=16, pady=(0, 8))
|
|
682
|
+
|
|
683
|
+
stash_msg_var = tk.StringVar()
|
|
684
|
+
msg_ent = tk.Entry(
|
|
685
|
+
act_bar,
|
|
686
|
+
textvariable=stash_msg_var,
|
|
687
|
+
bg=t.input_bg,
|
|
688
|
+
fg=t.fg,
|
|
689
|
+
insertbackground=t.cursor,
|
|
690
|
+
relief="flat",
|
|
691
|
+
bd=0,
|
|
692
|
+
highlightthickness=1,
|
|
693
|
+
highlightbackground=t.border,
|
|
694
|
+
font=(FONT_UI, 9),
|
|
695
|
+
width=26,
|
|
696
|
+
)
|
|
697
|
+
msg_ent.insert(
|
|
698
|
+
0, _t("git.stash_msg_placeholder", "Mensagem (opcional)"))
|
|
699
|
+
msg_ent.config(fg=t.fg_muted)
|
|
700
|
+
|
|
701
|
+
def _msg_focus_in(_e):
|
|
702
|
+
if msg_ent.get() == _t("git.stash_msg_placeholder", "Mensagem (opcional)"):
|
|
703
|
+
msg_ent.delete(0, "end")
|
|
704
|
+
msg_ent.config(fg=t.fg)
|
|
705
|
+
|
|
706
|
+
def _msg_focus_out(_e):
|
|
707
|
+
if not msg_ent.get().strip():
|
|
708
|
+
msg_ent.insert(
|
|
709
|
+
0, _t("git.stash_msg_placeholder", "Mensagem (opcional)")
|
|
710
|
+
)
|
|
711
|
+
msg_ent.config(fg=t.fg_muted)
|
|
712
|
+
|
|
713
|
+
msg_ent.bind("<FocusIn>", _msg_focus_in)
|
|
714
|
+
msg_ent.bind("<FocusOut>", _msg_focus_out)
|
|
715
|
+
msg_ent.pack(side="left", fill="x", expand=True, padx=(0, 6))
|
|
716
|
+
|
|
717
|
+
def _do_stash():
|
|
718
|
+
raw = stash_msg_var.get().strip()
|
|
719
|
+
placeholder = _t("git.stash_msg_placeholder",
|
|
720
|
+
"Mensagem (opcional)")
|
|
721
|
+
msg = raw if raw and raw != placeholder else ""
|
|
722
|
+
args = ["stash", "push"]
|
|
723
|
+
if msg:
|
|
724
|
+
args += ["-m", msg]
|
|
725
|
+
rc, out, err = self._git(*args)
|
|
726
|
+
if rc == 0:
|
|
727
|
+
self._set_status(_t("git.stash_saved", "Stash salvo."))
|
|
728
|
+
_refresh_list()
|
|
729
|
+
self.refresh()
|
|
730
|
+
else:
|
|
731
|
+
messagebox.showerror(
|
|
732
|
+
_t("git.err_title", "Erro"), err or out, parent=win
|
|
733
|
+
)
|
|
734
|
+
|
|
735
|
+
tk.Label(
|
|
736
|
+
act_bar,
|
|
737
|
+
text=_t("hc.git_panel.stash_changes", "📦 Guardar"),
|
|
738
|
+
bg=t.accent,
|
|
739
|
+
fg="#000",
|
|
740
|
+
font=(FONT_UI, 9, "bold"),
|
|
741
|
+
cursor="hand2",
|
|
742
|
+
padx=10,
|
|
743
|
+
pady=4,
|
|
744
|
+
relief="flat",
|
|
745
|
+
).pack(side="left")
|
|
746
|
+
act_bar.winfo_children()[-1].bind("<Button-1>", lambda _: _do_stash())
|
|
747
|
+
|
|
748
|
+
tk.Frame(win, bg=t.border, height=1).pack(
|
|
749
|
+
fill="x", padx=16, pady=(0, 4))
|
|
750
|
+
list_frame = tk.Frame(win, bg=t.floating_bg)
|
|
751
|
+
list_frame.pack(fill="both", expand=True, padx=16, pady=(0, 4))
|
|
752
|
+
|
|
753
|
+
stash_lb = tk.Listbox(
|
|
754
|
+
list_frame,
|
|
755
|
+
bg=t.sidebar_bg,
|
|
756
|
+
fg=t.fg,
|
|
757
|
+
selectbackground=t.sel_bg,
|
|
758
|
+
selectforeground=t.sel_fg,
|
|
759
|
+
relief="flat",
|
|
760
|
+
bd=0,
|
|
761
|
+
font=(FONT_MONO, 9),
|
|
762
|
+
activestyle="none",
|
|
763
|
+
highlightthickness=1,
|
|
764
|
+
highlightbackground=t.border,
|
|
765
|
+
)
|
|
766
|
+
vsb = tk.Scrollbar(
|
|
767
|
+
list_frame,
|
|
768
|
+
orient="vertical",
|
|
769
|
+
command=stash_lb.yview,
|
|
770
|
+
bg=t.scroll_thumb,
|
|
771
|
+
troughcolor=t.scroll_bg,
|
|
772
|
+
relief="flat",
|
|
773
|
+
bd=0,
|
|
774
|
+
width=6,
|
|
775
|
+
)
|
|
776
|
+
vsb.pack(side="right", fill="y")
|
|
777
|
+
stash_lb.config(yscrollcommand=vsb.set)
|
|
778
|
+
stash_lb.pack(fill="both", expand=True)
|
|
779
|
+
|
|
780
|
+
_stash_refs: list[str] = []
|
|
781
|
+
|
|
782
|
+
def _refresh_list():
|
|
783
|
+
stash_lb.delete(0, "end")
|
|
784
|
+
_stash_refs.clear()
|
|
785
|
+
rc, out, _ = self._git("stash", "list")
|
|
786
|
+
if rc == 0 and out.strip():
|
|
787
|
+
for line in out.strip().splitlines():
|
|
788
|
+
parts = line.split(":", 1)
|
|
789
|
+
ref = parts[0].strip()
|
|
790
|
+
label = line.strip()
|
|
791
|
+
_stash_refs.append(ref)
|
|
792
|
+
stash_lb.insert("end", f" {label}")
|
|
793
|
+
else:
|
|
794
|
+
stash_lb.insert(
|
|
795
|
+
"end", _t("git.no_stashes", " Nenhum stash encontrado.")
|
|
796
|
+
)
|
|
797
|
+
|
|
798
|
+
_refresh_list()
|
|
799
|
+
|
|
800
|
+
tk.Frame(win, bg=t.border, height=1).pack(
|
|
801
|
+
fill="x", padx=16, pady=(0, 6))
|
|
802
|
+
btn_bar = tk.Frame(win, bg=t.floating_bg)
|
|
803
|
+
btn_bar.pack(fill="x", padx=16, pady=(0, 12))
|
|
804
|
+
|
|
805
|
+
def _selected_ref() -> str | None:
|
|
806
|
+
sel = stash_lb.curselection()
|
|
807
|
+
if not sel or sel[0] >= len(_stash_refs):
|
|
808
|
+
messagebox.showwarning(
|
|
809
|
+
_t("git.stash_none_sel", "Seleção"),
|
|
810
|
+
_t("git.stash_select_hint", "Selecione um stash na lista."),
|
|
811
|
+
parent=win,
|
|
812
|
+
)
|
|
813
|
+
return None
|
|
814
|
+
return _stash_refs[sel[0]]
|
|
815
|
+
|
|
816
|
+
def _apply_stash():
|
|
817
|
+
ref = _selected_ref()
|
|
818
|
+
if not ref:
|
|
819
|
+
return
|
|
820
|
+
rc, out, err = self._git("stash", "apply", ref)
|
|
821
|
+
if rc == 0:
|
|
822
|
+
self._set_status(_t("git.stash_applied", "Stash aplicado."))
|
|
823
|
+
self.refresh()
|
|
824
|
+
else:
|
|
825
|
+
messagebox.showerror(
|
|
826
|
+
_t("git.err_title", "Erro"), err or out, parent=win
|
|
827
|
+
)
|
|
828
|
+
|
|
829
|
+
def _pop_stash_sel():
|
|
830
|
+
ref = _selected_ref()
|
|
831
|
+
if not ref:
|
|
832
|
+
return
|
|
833
|
+
rc, out, err = self._git("stash", "pop", ref)
|
|
834
|
+
if rc == 0:
|
|
835
|
+
self._set_status(_t("git.stash_popped", "Stash restaurado."))
|
|
836
|
+
_refresh_list()
|
|
837
|
+
self.refresh()
|
|
838
|
+
else:
|
|
839
|
+
messagebox.showerror(
|
|
840
|
+
_t("git.err_title", "Erro"), err or out, parent=win
|
|
841
|
+
)
|
|
842
|
+
|
|
843
|
+
def _drop_stash():
|
|
844
|
+
ref = _selected_ref()
|
|
845
|
+
if not ref:
|
|
846
|
+
return
|
|
847
|
+
if not messagebox.askyesno(
|
|
848
|
+
_t("git.stash_drop_title", "Remover Stash"),
|
|
849
|
+
_t(
|
|
850
|
+
"git.stash_drop_confirm",
|
|
851
|
+
f"Remover {ref}? Esta ação não pode ser desfeita.",
|
|
852
|
+
),
|
|
853
|
+
parent=win,
|
|
854
|
+
):
|
|
855
|
+
return
|
|
856
|
+
rc, out, err = self._git("stash", "drop", ref)
|
|
857
|
+
if rc == 0:
|
|
858
|
+
self._set_status(_t("git.stash_dropped", "Stash removido."))
|
|
859
|
+
_refresh_list()
|
|
860
|
+
else:
|
|
861
|
+
messagebox.showerror(
|
|
862
|
+
_t("git.err_title", "Erro"), err or out, parent=win
|
|
863
|
+
)
|
|
864
|
+
|
|
865
|
+
def _show_stash():
|
|
866
|
+
ref = _selected_ref()
|
|
867
|
+
if not ref:
|
|
868
|
+
return
|
|
869
|
+
rc, out, err = self._git("stash", "show", "-p", ref)
|
|
870
|
+
if rc != 0:
|
|
871
|
+
messagebox.showerror(
|
|
872
|
+
_t("git.err_title", "Erro"), err or out, parent=win
|
|
873
|
+
)
|
|
874
|
+
return
|
|
875
|
+
if self._on_show_diff:
|
|
876
|
+
self._on_show_diff(
|
|
877
|
+
"", out, f"{ref} (anterior)", f"{ref} (diff)")
|
|
878
|
+
else:
|
|
879
|
+
dwin = tk.Toplevel(win)
|
|
880
|
+
dwin.title(f"Stash diff: {ref}")
|
|
881
|
+
dwin.configure(bg=t.editor_bg)
|
|
882
|
+
dwin.geometry("720x500")
|
|
883
|
+
txt = tk.Text(
|
|
884
|
+
dwin,
|
|
885
|
+
bg=t.editor_bg,
|
|
886
|
+
fg=t.fg,
|
|
887
|
+
font=(FONT_MONO, 9),
|
|
888
|
+
relief="flat",
|
|
889
|
+
bd=0,
|
|
890
|
+
wrap="none",
|
|
891
|
+
)
|
|
892
|
+
sby = tk.Scrollbar(dwin, orient="vertical", command=txt.yview)
|
|
893
|
+
sbx = tk.Scrollbar(
|
|
894
|
+
dwin, orient="horizontal", command=txt.xview)
|
|
895
|
+
txt.configure(yscrollcommand=sby.set, xscrollcommand=sbx.set)
|
|
896
|
+
sby.pack(side="right", fill="y")
|
|
897
|
+
sbx.pack(side="bottom", fill="x")
|
|
898
|
+
txt.pack(fill="both", expand=True)
|
|
899
|
+
txt.tag_config("add", foreground="#4caf50")
|
|
900
|
+
txt.tag_config("rem", foreground="#f44336")
|
|
901
|
+
txt.tag_config("hunk", foreground="#64b5f6")
|
|
902
|
+
for line in out.splitlines(keepends=True):
|
|
903
|
+
tag = ""
|
|
904
|
+
if line.startswith("+") and not line.startswith("+++"):
|
|
905
|
+
tag = "add"
|
|
906
|
+
elif line.startswith("-") and not line.startswith("---"):
|
|
907
|
+
tag = "rem"
|
|
908
|
+
elif line.startswith("@@"):
|
|
909
|
+
tag = "hunk"
|
|
910
|
+
txt.insert("end", line, tag)
|
|
911
|
+
txt.config(state="disabled")
|
|
912
|
+
|
|
913
|
+
btn_specs = [
|
|
914
|
+
(
|
|
915
|
+
_t("hc.git_panel.pop_stash", "↩ Pop (aplicar + remover)"),
|
|
916
|
+
_pop_stash_sel,
|
|
917
|
+
t.accent,
|
|
918
|
+
"#000",
|
|
919
|
+
),
|
|
920
|
+
(_t("git.stash_apply", "✅ Aplicar"), _apply_stash, t.btn_bg, t.fg),
|
|
921
|
+
(_t("git.stash_show_diff", "🔍 Ver Diff"), _show_stash, t.btn_bg, t.fg),
|
|
922
|
+
(_t("git.stash_drop", "🗑 Remover"), _drop_stash, t.btn_bg, t.fg),
|
|
923
|
+
]
|
|
924
|
+
for label, cmd, bg, fg in btn_specs:
|
|
925
|
+
b = tk.Label(
|
|
926
|
+
btn_bar,
|
|
927
|
+
text=label,
|
|
928
|
+
bg=bg,
|
|
929
|
+
fg=fg,
|
|
930
|
+
font=(FONT_UI, 9, "bold" if bg == t.accent else "normal"),
|
|
931
|
+
cursor="hand2",
|
|
932
|
+
padx=8,
|
|
933
|
+
pady=4,
|
|
934
|
+
relief="flat",
|
|
935
|
+
)
|
|
936
|
+
b.pack(side="left", padx=(0, 4))
|
|
937
|
+
b.bind("<Button-1>", lambda _, c=cmd: c())
|
|
938
|
+
b.bind(
|
|
939
|
+
"<Enter>",
|
|
940
|
+
lambda _, w=b: w.config(
|
|
941
|
+
bg=t.btn_hover if w.cget("bg") != t.accent else t.accent
|
|
942
|
+
),
|
|
943
|
+
)
|
|
944
|
+
b.bind("<Leave>", lambda _, w=b, ob=bg: w.config(bg=ob))
|
|
945
|
+
|
|
946
|
+
tk.Label(
|
|
947
|
+
btn_bar,
|
|
948
|
+
text=_t("ui.close", "Fechar"),
|
|
949
|
+
bg=t.btn_bg,
|
|
950
|
+
fg=t.fg,
|
|
951
|
+
font=(FONT_UI, 9),
|
|
952
|
+
cursor="hand2",
|
|
953
|
+
padx=10,
|
|
954
|
+
pady=4,
|
|
955
|
+
relief="flat",
|
|
956
|
+
).pack(side="right")
|
|
957
|
+
btn_bar.winfo_children()[-1].bind("<Button-1>",
|
|
958
|
+
lambda _: win.destroy())
|
|
959
|
+
|
|
960
|
+
def _run_async(self, *args, timeout: int = 15) -> None:
|
|
961
|
+
"""Executa comando Git em thread separada com suporte a autenticação.
|
|
962
|
+
|
|
963
|
+
Ao detectar erro de autenticação no stderr, exibe o diálogo de
|
|
964
|
+
credenciais e re-executa o comando automaticamente.
|
|
965
|
+
|
|
966
|
+
Args:
|
|
967
|
+
*args: Argumentos do comando Git.
|
|
968
|
+
timeout: Timeout em segundos.
|
|
969
|
+
"""
|
|
970
|
+
if self._busy:
|
|
971
|
+
return
|
|
972
|
+
self._busy = True
|
|
973
|
+
self._status_lbl.config(text=_t("hc.git_panel.working"))
|
|
974
|
+
|
|
975
|
+
def _work():
|
|
976
|
+
rc, out, err = self._git(*args, timeout=timeout)
|
|
977
|
+
|
|
978
|
+
def _done(rc=rc, out=out, err=err):
|
|
979
|
+
self._busy = False
|
|
980
|
+
self._status_lbl.config(text="")
|
|
981
|
+
if rc != 0:
|
|
982
|
+
combined = (out + err).strip()
|
|
983
|
+
|
|
984
|
+
if is_auth_error(err):
|
|
985
|
+
self._handle_auth_retry(list(args), timeout, err)
|
|
986
|
+
return
|
|
987
|
+
|
|
988
|
+
err_low = err.lower()
|
|
989
|
+
if "host key verification failed" in err_low:
|
|
990
|
+
host = _host_from_url(self._detect_remote_url() or "")
|
|
991
|
+
self._auth.show_host_key_help(self._tmgr.theme, host)
|
|
992
|
+
return
|
|
993
|
+
if "permission denied (publickey" in err_low:
|
|
994
|
+
self._auth.show_ssh_help(self._tmgr.theme)
|
|
995
|
+
return
|
|
996
|
+
if err:
|
|
997
|
+
messagebox.showerror(
|
|
998
|
+
args[0].capitalize() + " failed", combined, parent=self
|
|
999
|
+
)
|
|
1000
|
+
self.refresh()
|
|
1001
|
+
|
|
1002
|
+
self.after(0, _done)
|
|
1003
|
+
|
|
1004
|
+
threading.Thread(target=_work, daemon=True).start()
|
|
1005
|
+
|
|
1006
|
+
_MAX_AUTH_RETRIES = 3
|
|
1007
|
+
|
|
1008
|
+
def _handle_auth_retry(
|
|
1009
|
+
self, git_args: list[str], timeout: int, _err: str, attempt: int = 1
|
|
1010
|
+
) -> None:
|
|
1011
|
+
"""Exibe diálogo de credenciais e re-executa o comando Git.
|
|
1012
|
+
|
|
1013
|
+
Chamado quando _run_async detecta erro de autenticação. Se a nova
|
|
1014
|
+
tentativa também falhar por autenticação, reabre o diálogo de
|
|
1015
|
+
credenciais (até um limite de tentativas) em vez de mostrar apenas
|
|
1016
|
+
um erro genérico cru para o usuário.
|
|
1017
|
+
|
|
1018
|
+
Args:
|
|
1019
|
+
git_args: Argumentos originais do comando Git.
|
|
1020
|
+
timeout: Timeout em segundos.
|
|
1021
|
+
_err: Mensagem de erro original (não usada diretamente).
|
|
1022
|
+
attempt: Número da tentativa atual (para limitar retries).
|
|
1023
|
+
"""
|
|
1024
|
+
if not self._git_root:
|
|
1025
|
+
return
|
|
1026
|
+
remote_url = self._detect_remote_url() or ""
|
|
1027
|
+
|
|
1028
|
+
def _on_done(rc: int, _out: str, err: str) -> None:
|
|
1029
|
+
self._busy = False
|
|
1030
|
+
self._status_lbl.config(text="")
|
|
1031
|
+
if rc != 0 and err:
|
|
1032
|
+
if is_auth_error(err) and attempt < self._MAX_AUTH_RETRIES:
|
|
1033
|
+
self._handle_auth_retry(
|
|
1034
|
+
git_args, timeout, err, attempt + 1)
|
|
1035
|
+
return
|
|
1036
|
+
messagebox.showerror(
|
|
1037
|
+
git_args[0].capitalize() + " failed", err.strip(), parent=self
|
|
1038
|
+
)
|
|
1039
|
+
self.refresh()
|
|
1040
|
+
|
|
1041
|
+
self._auth.prompt_and_retry(
|
|
1042
|
+
remote_url,
|
|
1043
|
+
["git"] + git_args,
|
|
1044
|
+
str(self._git_root),
|
|
1045
|
+
self._tmgr.theme,
|
|
1046
|
+
_on_done,
|
|
1047
|
+
)
|
|
1048
|
+
|
|
1049
|
+
def _switch_branch(self, _e: Any = None) -> None:
|
|
1050
|
+
"""Troca para a branch selecionada no combo de branches."""
|
|
1051
|
+
branch = self._branch_var.get()
|
|
1052
|
+
if not branch or branch == "-":
|
|
1053
|
+
return
|
|
1054
|
+
rc, _, err = self._git("checkout", branch)
|
|
1055
|
+
if rc != 0:
|
|
1056
|
+
messagebox.showerror(
|
|
1057
|
+
_t("hc.git_panel.checkout_failed"), err, parent=self)
|
|
1058
|
+
self.refresh()
|
|
1059
|
+
|
|
1060
|
+
def _on_commit_click(self, _e: Any = None) -> None:
|
|
1061
|
+
"""Abre o diff completo do commit selecionado no painel de diff do Codis."""
|
|
1062
|
+
sel = self._log_listbox.curselection()
|
|
1063
|
+
if not sel:
|
|
1064
|
+
return
|
|
1065
|
+
idx = sel[0]
|
|
1066
|
+
if idx >= len(self._commit_hashes):
|
|
1067
|
+
return
|
|
1068
|
+
commit_hash = self._commit_hashes[idx].strip()
|
|
1069
|
+
if not commit_hash:
|
|
1070
|
+
return
|
|
1071
|
+
|
|
1072
|
+
def _fetch():
|
|
1073
|
+
rc_stat, stat_out, _ = self._git(
|
|
1074
|
+
"show",
|
|
1075
|
+
"--stat",
|
|
1076
|
+
"--format=%H %s",
|
|
1077
|
+
commit_hash,
|
|
1078
|
+
)
|
|
1079
|
+
rc_diff, diff_out, diff_err = self._git(
|
|
1080
|
+
"show",
|
|
1081
|
+
commit_hash,
|
|
1082
|
+
"--format=commit %H%nAuthor: %an <%ae>%nDate: %ad%n%n %s%n",
|
|
1083
|
+
"--unified=3",
|
|
1084
|
+
)
|
|
1085
|
+
if rc_diff != 0:
|
|
1086
|
+
err = diff_err or "Falha ao obter diff do commit."
|
|
1087
|
+
self.after(
|
|
1088
|
+
0, lambda: messagebox.showerror(
|
|
1089
|
+
"Git Show", err, parent=self)
|
|
1090
|
+
)
|
|
1091
|
+
return
|
|
1092
|
+
|
|
1093
|
+
rc_p, parent_out, _ = self._git("rev-parse", f"{commit_hash}^")
|
|
1094
|
+
_ = parent_out.strip() if rc_p == 0 else ""
|
|
1095
|
+
|
|
1096
|
+
label_a = f"{commit_hash[:7]}^ (anterior)"
|
|
1097
|
+
label_b = f"{commit_hash[:7]} (commit)"
|
|
1098
|
+
|
|
1099
|
+
header_lines = [
|
|
1100
|
+
f"# Commit: {commit_hash}",
|
|
1101
|
+
stat_out.strip() if rc_stat == 0 else "",
|
|
1102
|
+
"",
|
|
1103
|
+
"# Diff completo:",
|
|
1104
|
+
"-" * 60,
|
|
1105
|
+
]
|
|
1106
|
+
content_b = "\n".join(header_lines) + "\n" + diff_out
|
|
1107
|
+
content_a = ""
|
|
1108
|
+
|
|
1109
|
+
self.after(
|
|
1110
|
+
0,
|
|
1111
|
+
lambda: self._open_commit_view(
|
|
1112
|
+
content_a,
|
|
1113
|
+
content_b,
|
|
1114
|
+
label_a,
|
|
1115
|
+
label_b,
|
|
1116
|
+
commit_hash,
|
|
1117
|
+
),
|
|
1118
|
+
)
|
|
1119
|
+
|
|
1120
|
+
threading.Thread(target=_fetch, daemon=True).start()
|
|
1121
|
+
|
|
1122
|
+
def _open_commit_view(
|
|
1123
|
+
self,
|
|
1124
|
+
content_a: str,
|
|
1125
|
+
content_b: str,
|
|
1126
|
+
label_a: str,
|
|
1127
|
+
label_b: str,
|
|
1128
|
+
commit_hash: str,
|
|
1129
|
+
) -> None:
|
|
1130
|
+
"""Exibe o conteúdo do commit no diff pane ou num diálogo dedicado."""
|
|
1131
|
+
if self._on_show_diff:
|
|
1132
|
+
self._on_show_diff(content_a, content_b, label_a, label_b)
|
|
1133
|
+
return
|
|
1134
|
+
|
|
1135
|
+
t = self._tmgr.theme
|
|
1136
|
+
win = tk.Toplevel(self)
|
|
1137
|
+
win.title(f"Commit {commit_hash[:12]}")
|
|
1138
|
+
win.configure(bg=t.editor_bg)
|
|
1139
|
+
win.geometry("860x620")
|
|
1140
|
+
|
|
1141
|
+
header = tk.Label(
|
|
1142
|
+
win,
|
|
1143
|
+
text=f"🔍 Explorando commit {commit_hash[:12]}",
|
|
1144
|
+
bg=t.editor_bg,
|
|
1145
|
+
fg=t.fg,
|
|
1146
|
+
font=(FONT_UI, 11, "bold"),
|
|
1147
|
+
anchor="w",
|
|
1148
|
+
padx=12,
|
|
1149
|
+
pady=8,
|
|
1150
|
+
)
|
|
1151
|
+
header.pack(fill="x")
|
|
1152
|
+
tk.Frame(win, bg=t.border, height=1).pack(fill="x")
|
|
1153
|
+
|
|
1154
|
+
txt = tk.Text(
|
|
1155
|
+
win,
|
|
1156
|
+
bg=t.editor_bg,
|
|
1157
|
+
fg=t.fg,
|
|
1158
|
+
font=(FONT_MONO, 9),
|
|
1159
|
+
relief="flat",
|
|
1160
|
+
bd=0,
|
|
1161
|
+
wrap="none",
|
|
1162
|
+
state="normal",
|
|
1163
|
+
)
|
|
1164
|
+
sb_y = tk.Scrollbar(win, orient="vertical", command=txt.yview)
|
|
1165
|
+
sb_x = tk.Scrollbar(win, orient="horizontal", command=txt.xview)
|
|
1166
|
+
txt.configure(yscrollcommand=sb_y.set, xscrollcommand=sb_x.set)
|
|
1167
|
+
sb_y.pack(side="right", fill="y")
|
|
1168
|
+
sb_x.pack(side="bottom", fill="x")
|
|
1169
|
+
txt.pack(fill="both", expand=True, padx=4, pady=4)
|
|
1170
|
+
|
|
1171
|
+
txt.tag_config("add", foreground="#4caf50")
|
|
1172
|
+
txt.tag_config("rem", foreground="#f44336")
|
|
1173
|
+
txt.tag_config("hunk", foreground="#64b5f6")
|
|
1174
|
+
txt.tag_config("header", foreground=t.t_func)
|
|
1175
|
+
|
|
1176
|
+
for line in content_b.splitlines(keepends=True):
|
|
1177
|
+
tag = None
|
|
1178
|
+
if line.startswith("+") and not line.startswith("+++"):
|
|
1179
|
+
tag = "add"
|
|
1180
|
+
elif line.startswith("-") and not line.startswith("---"):
|
|
1181
|
+
tag = "rem"
|
|
1182
|
+
elif line.startswith("@@"):
|
|
1183
|
+
tag = "hunk"
|
|
1184
|
+
elif line.startswith("commit ") or line.startswith("diff "):
|
|
1185
|
+
tag = "header"
|
|
1186
|
+
txt.insert("end", line, tag or "")
|
|
1187
|
+
|
|
1188
|
+
txt.config(state="disabled")
|
|
1189
|
+
tk.Button(
|
|
1190
|
+
win,
|
|
1191
|
+
text=_t("git.btn_close", "Fechar"),
|
|
1192
|
+
command=win.destroy,
|
|
1193
|
+
bg=t.btn_bg,
|
|
1194
|
+
fg=t.btn_fg,
|
|
1195
|
+
relief="flat",
|
|
1196
|
+
padx=16,
|
|
1197
|
+
).pack(pady=6)
|
|
1198
|
+
|
|
1199
|
+
def _pop_stash(self) -> None:
|
|
1200
|
+
"""Restaura o último stash salvo."""
|
|
1201
|
+
rc, out, err = self._git("stash", "pop")
|
|
1202
|
+
if rc == 0:
|
|
1203
|
+
self._set_status(_t("git.stash_popped", "Stash restaurado."))
|
|
1204
|
+
self.refresh()
|
|
1205
|
+
else:
|
|
1206
|
+
messagebox.showerror(
|
|
1207
|
+
_t("git.err_title", "Erro"), err or out, parent=self)
|
|
1208
|
+
|
|
1209
|
+
def _create_tag(self) -> None:
|
|
1210
|
+
"""Cria uma tag anotada no commit atual."""
|
|
1211
|
+
t = self._tmgr.theme
|
|
1212
|
+
win = tk.Toplevel(self)
|
|
1213
|
+
win.title(_t("git.create_tag_title", "Criar Tag"))
|
|
1214
|
+
win.config(bg=t.floating_bg)
|
|
1215
|
+
safe_grab_set(win)
|
|
1216
|
+
win.resizable(False, False)
|
|
1217
|
+
|
|
1218
|
+
tk.Label(
|
|
1219
|
+
win,
|
|
1220
|
+
text=_t("git.tag_name", "Nome da tag (ex: v1.0.0):"),
|
|
1221
|
+
bg=t.floating_bg,
|
|
1222
|
+
fg=t.fg,
|
|
1223
|
+
font=(FONT_UI, 9),
|
|
1224
|
+
).pack(padx=12, pady=(10, 2))
|
|
1225
|
+
tag_var = tk.StringVar()
|
|
1226
|
+
tk.Entry(
|
|
1227
|
+
win,
|
|
1228
|
+
textvariable=tag_var,
|
|
1229
|
+
bg=t.input_bg,
|
|
1230
|
+
fg=t.fg,
|
|
1231
|
+
insertbackground=t.cursor,
|
|
1232
|
+
relief="flat",
|
|
1233
|
+
font=(FONT_UI, 10),
|
|
1234
|
+
width=24,
|
|
1235
|
+
bd=0,
|
|
1236
|
+
highlightthickness=1,
|
|
1237
|
+
highlightbackground=t.border,
|
|
1238
|
+
).pack(padx=12, pady=2)
|
|
1239
|
+
|
|
1240
|
+
tk.Label(
|
|
1241
|
+
win,
|
|
1242
|
+
text=_t("git.tag_msg", "Mensagem (opcional):"),
|
|
1243
|
+
bg=t.floating_bg,
|
|
1244
|
+
fg=t.fg,
|
|
1245
|
+
font=(FONT_UI, 9),
|
|
1246
|
+
).pack(padx=12, pady=(6, 2))
|
|
1247
|
+
msg_var = tk.StringVar()
|
|
1248
|
+
tk.Entry(
|
|
1249
|
+
win,
|
|
1250
|
+
textvariable=msg_var,
|
|
1251
|
+
bg=t.input_bg,
|
|
1252
|
+
fg=t.fg,
|
|
1253
|
+
insertbackground=t.cursor,
|
|
1254
|
+
relief="flat",
|
|
1255
|
+
font=(FONT_UI, 10),
|
|
1256
|
+
width=24,
|
|
1257
|
+
bd=0,
|
|
1258
|
+
highlightthickness=1,
|
|
1259
|
+
highlightbackground=t.border,
|
|
1260
|
+
).pack(padx=12, pady=2)
|
|
1261
|
+
|
|
1262
|
+
def _do_tag() -> None:
|
|
1263
|
+
name = tag_var.get().strip()
|
|
1264
|
+
if not name:
|
|
1265
|
+
return
|
|
1266
|
+
msg = msg_var.get().strip() or f"Release {name}"
|
|
1267
|
+
rc, out, err = self._git("tag", "-a", name, "-m", msg)
|
|
1268
|
+
if rc == 0:
|
|
1269
|
+
self._set_status(
|
|
1270
|
+
_t("git.tag_created", f"Tag '{name}' criada."))
|
|
1271
|
+
self.refresh()
|
|
1272
|
+
else:
|
|
1273
|
+
messagebox.showerror(
|
|
1274
|
+
_t("git.err_title", "Erro"), err or out, parent=self
|
|
1275
|
+
)
|
|
1276
|
+
win.destroy()
|
|
1277
|
+
|
|
1278
|
+
btn_row = tk.Frame(win, bg=t.floating_bg)
|
|
1279
|
+
btn_row.pack(fill="x", padx=8, pady=8)
|
|
1280
|
+
tk.Button(
|
|
1281
|
+
btn_row,
|
|
1282
|
+
text=_t("git.create", "Criar"),
|
|
1283
|
+
command=_do_tag,
|
|
1284
|
+
bg=t.accent,
|
|
1285
|
+
fg="#000",
|
|
1286
|
+
relief="flat",
|
|
1287
|
+
font=(FONT_UI, 9),
|
|
1288
|
+
padx=10,
|
|
1289
|
+
).pack(side="right", padx=2)
|
|
1290
|
+
tk.Button(
|
|
1291
|
+
btn_row,
|
|
1292
|
+
text=_t("git.cancel", "Cancelar"),
|
|
1293
|
+
command=win.destroy,
|
|
1294
|
+
bg=t.sidebar_bg,
|
|
1295
|
+
fg=t.fg,
|
|
1296
|
+
relief="flat",
|
|
1297
|
+
font=(FONT_UI, 9),
|
|
1298
|
+
).pack(side="right")
|
|
1299
|
+
win.update_idletasks()
|
|
1300
|
+
sw, sh = win.winfo_screenwidth(), win.winfo_screenheight()
|
|
1301
|
+
ww, wh = win.winfo_reqwidth(), win.winfo_reqheight()
|
|
1302
|
+
win.geometry(f"{ww}x{wh}+{(sw - ww) // 2}+{(sh - wh) // 2}")
|
|
1303
|
+
|
|
1304
|
+
def _interactive_rebase(self) -> None:
|
|
1305
|
+
"""Rebase interativo nos últimos N commits."""
|
|
1306
|
+
n = simpledialog.askinteger(
|
|
1307
|
+
_t("git.rebase_title", "Rebase Interativo"),
|
|
1308
|
+
_t("git.rebase_prompt", "Quantos commits incluir no rebase?"),
|
|
1309
|
+
minvalue=1,
|
|
1310
|
+
maxvalue=50,
|
|
1311
|
+
initialvalue=3,
|
|
1312
|
+
parent=self,
|
|
1313
|
+
)
|
|
1314
|
+
if not n:
|
|
1315
|
+
return
|
|
1316
|
+
import os
|
|
1317
|
+
|
|
1318
|
+
env = dict(os.environ)
|
|
1319
|
+
env["GIT_SEQUENCE_EDITOR"] = env.get(
|
|
1320
|
+
"VISUAL") or env.get("EDITOR") or "nano"
|
|
1321
|
+
cmd = ["git", "-C", str(self._repo), "rebase", "-i", f"HEAD~{n}"]
|
|
1322
|
+
try:
|
|
1323
|
+
subprocess.Popen(cmd, env=env)
|
|
1324
|
+
self._set_status(
|
|
1325
|
+
_t("git.rebase_launched",
|
|
1326
|
+
f"Rebase interativo lançado (HEAD~{n}).")
|
|
1327
|
+
)
|
|
1328
|
+
except Exception as exc:
|
|
1329
|
+
messagebox.showerror(
|
|
1330
|
+
_t("git.err_title", "Erro"), str(exc), parent=self)
|
|
1331
|
+
|
|
1332
|
+
def _create_branch(self) -> None:
|
|
1333
|
+
"""Cria nova branch Git com o nome digitado e faz checkout nela."""
|
|
1334
|
+
name = simpledialog.askstring(
|
|
1335
|
+
"New Branch", "Branch name:", parent=self)
|
|
1336
|
+
if not name or not name.strip():
|
|
1337
|
+
return
|
|
1338
|
+
name = name.strip()
|
|
1339
|
+
rc, _, err = self._git("checkout", "-b", name)
|
|
1340
|
+
if rc != 0:
|
|
1341
|
+
messagebox.showerror(_t("hc.git_panel.error"), err, parent=self)
|
|
1342
|
+
self.refresh()
|
|
1343
|
+
|
|
1344
|
+
def _on_double(self, _e: Any = None) -> None:
|
|
1345
|
+
sel = self._tree.selection()
|
|
1346
|
+
if not sel:
|
|
1347
|
+
return
|
|
1348
|
+
meta = self._item_meta.get(sel[0])
|
|
1349
|
+
if not meta:
|
|
1350
|
+
return
|
|
1351
|
+
fname, section = meta
|
|
1352
|
+
self._show_diff(fname, section == "staged")
|
|
1353
|
+
|
|
1354
|
+
def _on_ctx(self, e: tk.Event) -> None:
|
|
1355
|
+
item = self._tree.identify_row(e.y)
|
|
1356
|
+
if not item:
|
|
1357
|
+
return
|
|
1358
|
+
self._tree.selection_set(item)
|
|
1359
|
+
meta = self._item_meta.get(item)
|
|
1360
|
+
if not meta:
|
|
1361
|
+
return
|
|
1362
|
+
fname, section = meta
|
|
1363
|
+
staged = section == "staged"
|
|
1364
|
+
|
|
1365
|
+
t = self._tmgr.theme
|
|
1366
|
+
menu = tk.Menu(
|
|
1367
|
+
self,
|
|
1368
|
+
tearoff=False,
|
|
1369
|
+
bg=t.floating_bg,
|
|
1370
|
+
fg=t.fg,
|
|
1371
|
+
activebackground=t.sel_bg,
|
|
1372
|
+
activeforeground=t.sel_fg,
|
|
1373
|
+
)
|
|
1374
|
+
if staged:
|
|
1375
|
+
menu.add_command(
|
|
1376
|
+
label=_t("hc.git_panel.unstage"), command=lambda: self._unstage(fname)
|
|
1377
|
+
)
|
|
1378
|
+
else:
|
|
1379
|
+
menu.add_command(
|
|
1380
|
+
label=_t("hc.git_panel.stage"), command=lambda: self._stage(fname)
|
|
1381
|
+
)
|
|
1382
|
+
if section != "untracked":
|
|
1383
|
+
menu.add_command(
|
|
1384
|
+
label=_t("hc.git_panel.discard_changes"),
|
|
1385
|
+
command=lambda: self._discard(fname),
|
|
1386
|
+
)
|
|
1387
|
+
menu.add_separator()
|
|
1388
|
+
menu.add_command(
|
|
1389
|
+
label=_t("hc.git_panel.view_diff"),
|
|
1390
|
+
command=lambda: self._show_diff(fname, staged),
|
|
1391
|
+
)
|
|
1392
|
+
try:
|
|
1393
|
+
menu.tk_popup(e.x_root, e.y_root)
|
|
1394
|
+
finally:
|
|
1395
|
+
menu.grab_release()
|
|
1396
|
+
|
|
1397
|
+
def _show_diff(self, fname: str, staged: bool) -> None:
|
|
1398
|
+
"""
|
|
1399
|
+
Mostra diff correto.
|
|
1400
|
+
- staged=True -> HEAD vs índice (staged)
|
|
1401
|
+
- staged=False -> índice/HEAD vs working tree
|
|
1402
|
+
|
|
1403
|
+
Garante que orig/mod nunca são None (evita AttributeError em DiffEngine).
|
|
1404
|
+
"""
|
|
1405
|
+
if not self._git_root or not self._on_show_diff:
|
|
1406
|
+
return
|
|
1407
|
+
path = self._git_root / fname
|
|
1408
|
+
try:
|
|
1409
|
+
mod: str = (
|
|
1410
|
+
path.read_text(encoding="utf-8", errors="replace")
|
|
1411
|
+
if path.exists()
|
|
1412
|
+
else ""
|
|
1413
|
+
)
|
|
1414
|
+
except OSError:
|
|
1415
|
+
mod = ""
|
|
1416
|
+
|
|
1417
|
+
if staged:
|
|
1418
|
+
rc, orig, _ = self._git("show", f"HEAD:{fname}")
|
|
1419
|
+
orig = orig if rc == 0 else ""
|
|
1420
|
+
rc2, idx_content, _ = self._git("show", f":{fname}")
|
|
1421
|
+
mod_content = idx_content if rc2 == 0 else mod
|
|
1422
|
+
self._on_show_diff(
|
|
1423
|
+
orig or "",
|
|
1424
|
+
mod_content or "",
|
|
1425
|
+
f"{fname} (HEAD)",
|
|
1426
|
+
f"{fname} (staged index)",
|
|
1427
|
+
)
|
|
1428
|
+
else:
|
|
1429
|
+
rc, orig, _ = self._git("show", f":{fname}")
|
|
1430
|
+
if rc != 0:
|
|
1431
|
+
rc, orig, _ = self._git("show", f"HEAD:{fname}")
|
|
1432
|
+
orig = orig if rc == 0 else ""
|
|
1433
|
+
self._on_show_diff(
|
|
1434
|
+
orig or "",
|
|
1435
|
+
mod or "",
|
|
1436
|
+
f"{fname} (index/HEAD)",
|
|
1437
|
+
f"{fname} (working)",
|
|
1438
|
+
)
|
|
1439
|
+
|
|
1440
|
+
def _msg_focus_in(self, _e: Any) -> None:
|
|
1441
|
+
"""Limpa o placeholder do campo de mensagem de commit ao receber foco."""
|
|
1442
|
+
if self._msg_text.get("1.0", "end-1c") == self._placeholder:
|
|
1443
|
+
self._msg_text.delete("1.0", "end")
|
|
1444
|
+
self._msg_text.config(fg=self._tmgr.theme.fg)
|
|
1445
|
+
|
|
1446
|
+
def _msg_focus_out(self, _e: Any) -> None:
|
|
1447
|
+
"""Restaura o placeholder se o campo de commit estiver vazio ao perder foco."""
|
|
1448
|
+
if not self._msg_text.get("1.0", "end-1c").strip():
|
|
1449
|
+
self._msg_text.delete("1.0", "end")
|
|
1450
|
+
self._msg_text.insert("1.0", self._placeholder)
|
|
1451
|
+
self._msg_text.config(fg=self._tmgr.theme.fg_muted)
|
|
1452
|
+
|
|
1453
|
+
def _msg_on_paste(self, _e: Any) -> None:
|
|
1454
|
+
"""Limpa o placeholder do campo de commit antes de colar o conteúdo."""
|
|
1455
|
+
if self._msg_text.get("1.0", "end-1c") == self._placeholder:
|
|
1456
|
+
self._msg_text.delete("1.0", "end")
|
|
1457
|
+
self._msg_text.config(fg=self._tmgr.theme.fg)
|
|
1458
|
+
|
|
1459
|
+
def apply_theme(self, t: Theme) -> None:
|
|
1460
|
+
"""Aplica o tema de cores ao painel Git (fundo, Treeview, tags de status).
|
|
1461
|
+
|
|
1462
|
+
Args:
|
|
1463
|
+
t: Objeto Theme com as cores do tema ativo.
|
|
1464
|
+
"""
|
|
1465
|
+
self.config(bg=t.panel_bg)
|
|
1466
|
+
style = ttk.Style()
|
|
1467
|
+
style.configure(
|
|
1468
|
+
"Git.Treeview",
|
|
1469
|
+
background=t.panel_bg,
|
|
1470
|
+
foreground=t.fg,
|
|
1471
|
+
fieldbackground=t.panel_bg,
|
|
1472
|
+
font=(FONT_UI, 9),
|
|
1473
|
+
)
|
|
1474
|
+
style.map(
|
|
1475
|
+
"Git.Treeview",
|
|
1476
|
+
background=[("selected", t.sel_bg)],
|
|
1477
|
+
foreground=[("selected", t.sel_fg)],
|
|
1478
|
+
)
|
|
1479
|
+
self._tree.tag_configure("section", foreground=t.fg_muted)
|
|
1480
|
+
self._tree.tag_configure("staged", foreground=t.ok_fg)
|
|
1481
|
+
self._tree.tag_configure("modified", foreground=t.warn_fg)
|
|
1482
|
+
self._tree.tag_configure("untracked", foreground=t.fg_muted)
|
|
1483
|
+
self._tree.tag_configure("deleted", foreground=t.fg_muted)
|