From 85fe316cf1cc37594e0e7e7e1326ad0daa4821b3 Mon Sep 17 00:00:00 2001 From: LZX <1820455493@qq.com> Date: Fri, 18 Sep 2026 13:44:38 +0800 Subject: [PATCH] 1 --- lib/l10n/app_en.arb | 55 ++++++++++++++++++++ lib/main.dart | 6 +++ lib/models/git_model.dart | 102 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 lib/models/git_model.dart diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 5bfd497..798e4e6 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1101,5 +1101,60 @@ "type": "String" } } + }, + "gitNotInstalled": "Git Not Found", + "gitNotInstalledDesc": "Git command-line tool was not found on your system. Please install git in your terminal or Linux container (e.g. apt update && apt install -y git).", + "gitNeedInstall": "Git Installation Required", + "gitInstallAction": "Install Git", + "gitInstallingProgress": "Installing Git...", + "gitInstallSuccess": "Git installed successfully", + "gitInstallFailed": "Failed to install Git: {error}", + "@gitInstallFailed": { + "placeholders": { + "error": { + "type": "String" + } + } + }, + "gitNoRepoFound": "No Git Repository", + "gitNoRepoDesc": "Initialize a Git repository to start version control, branch management, and tracking code changes.", + "gitInitRepo": "Initialize Repository", + "gitInitializing": "Initializing Git repository...", + "gitInitSuccess": "Git repository initialized successfully", + "gitInitFailed": "Failed to initialize Git repository: {error}", + "@gitInitFailed": { + "placeholders": { + "error": { + "type": "String" + } + } + }, + "gitRepository": "Repository", + "gitCurrentBranch": "Branch: {branch}", + "@gitCurrentBranch": { + "placeholders": { + "branch": { + "type": "String" + } + } + }, + "gitSwitchRepo": "Switch Repository", + "gitRefresh": "Refresh Git", + "gitChanges": "Changes", + "gitStagedChanges": "Staged Changes", + "gitNoChanges": "No changes detected", + "gitStatusUntracked": "Untracked", + "gitStatusModified": "Modified", + "gitStatusAdded": "Added", + "gitStatusDeleted": "Deleted", + "gitStatusRenamed": "Renamed", + "gitStatusConflict": "Conflict", + "gitMultipleReposDetected": "Multiple Repositories ({count})", + "@gitMultipleReposDetected": { + "placeholders": { + "count": { + "type": "int" + } + } } } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 69907d5..32f8b75 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'package:code_editor/l10n/app_localizations.dart'; import 'package:code_editor/providers/distro_provider.dart'; +import 'package:code_editor/providers/git_provider.dart'; import 'package:code_editor/providers/notice_center.dart'; import 'package:code_editor/providers/project_provider.dart'; import 'package:code_editor/providers/run_provider.dart'; @@ -51,6 +52,11 @@ class MyApp extends StatelessWidget { update: (_, project, search) => (search ?? SearchProvider())..bindRootPath(project.rootPath), ), + ChangeNotifierProxyProvider( + create: (_) => GitProvider(), + update: (_, project, git) => + (git ?? GitProvider())..bindRootPath(project.rootPath), + ), ChangeNotifierProvider(create: (_) => TerminalProvider()), ChangeNotifierProvider( create: (_) { diff --git a/lib/models/git_model.dart b/lib/models/git_model.dart new file mode 100644 index 0000000..1af508a --- /dev/null +++ b/lib/models/git_model.dart @@ -0,0 +1,102 @@ +import 'package:path/path.dart' as p; + +/// Git 文件状态类别 +enum GitFileStatusType { + untracked, // 未跟踪 (??) + modified, // 已修改 ( M / M ) + added, // 新增 (A ) + deleted, // 已删除 ( D / D ) + renamed, // 重命名 (R ) + copied, // 复制 (C ) + typeChange,// 类型变更 (T ) + unmerged, // 冲突未合并 (UU / AA / DD 等) + ignored, // 忽略 (!!) + unknown, // 未知 +} + +/// Git 文件变更条目 +class GitFileStatus { + final String path; + final String relativePath; + final GitFileStatusType statusType; + final bool isStaged; + final String? originalPath; // 用于重命名/复制的源路径 + + const GitFileStatus({ + required this.path, + required this.relativePath, + required this.statusType, + this.isStaged = false, + this.originalPath, + }); + + String get fileName => p.basename(relativePath); + + String get directoryPath { + final dir = p.dirname(relativePath); + return dir == '.' ? '' : dir; + } +} + +/// Git 仓库信息(支持根仓库及子模块/嵌套仓库) +class GitRepositoryInfo { + final String rootPath; + final String name; + final bool isRoot; + final String? currentBranch; + + const GitRepositoryInfo({ + required this.rootPath, + required this.name, + this.isRoot = false, + this.currentBranch, + }); + + GitRepositoryInfo copyWith({ + String? rootPath, + String? name, + bool? isRoot, + String? currentBranch, + }) { + return GitRepositoryInfo( + rootPath: rootPath ?? this.rootPath, + name: name ?? this.name, + isRoot: isRoot ?? this.isRoot, + currentBranch: currentBranch ?? this.currentBranch, + ); + } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is GitRepositoryInfo && + runtimeType == other.runtimeType && + rootPath == other.rootPath; + + @override + int get hashCode => rootPath.hashCode; +} + +/// Git 命令行执行结果 +class GitCommandResult { + final bool success; + final int exitCode; + final String stdout; + final String stderr; + + const GitCommandResult({ + required this.success, + required this.exitCode, + required this.stdout, + required this.stderr, + }); + + factory GitCommandResult.error(String message, {int exitCode = -1}) { + return GitCommandResult( + success: false, + exitCode: exitCode, + stdout: '', + stderr: message, + ); + } +}