2
This commit is contained in:
1 parent
6f5d1ed570
commit
875840147d
17 files changed
+3093
-36
No files matched your search
@@ -1295,6 +1295,77 @@
|
||||
"gitSearchTags": "Search tags...",
|
||||
"gitNoBranches": "No branches",
|
||||
|
||||
"gitConflictTitle": "Resolve Conflicts",
|
||||
"gitConflictRebaseInProgress": "Rebase in progress",
|
||||
"gitConflictMergeInProgress": "Merge in progress",
|
||||
"gitConflictCherryPickInProgress": "Cherry-pick in progress",
|
||||
"gitConflictRevertInProgress": "Revert in progress",
|
||||
"gitConflictRemaining": "{count} file(s) still unresolved",
|
||||
"@gitConflictRemaining": {
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitConflictAllResolved": "All conflicts resolved, ready to continue",
|
||||
"gitConflictResolved": "Marked as resolved: {path}",
|
||||
"@gitConflictResolved": {
|
||||
"placeholders": {
|
||||
"path": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitConflictOpenFile": "Open file to edit",
|
||||
"gitConflictTakeBaseline": "Take version from {name}",
|
||||
"@gitConflictTakeBaseline": {
|
||||
"placeholders": {
|
||||
"name": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitConflictTakeIncoming": "Take version from the commit being applied",
|
||||
"gitConflictTakeBaselineGeneric": "Take the baseline version for the whole file",
|
||||
"gitConflictRecreate": "Regenerate conflict markers",
|
||||
"gitConflictRecreateDone": "Conflict markers regenerated",
|
||||
"gitConflictRemoveFile": "Delete this file",
|
||||
"gitConflictBinaryHint": "Binary files cannot be resolved with markers — choose which side to keep",
|
||||
"gitConflictDeleteHint": "This file was deleted on one side — choose whether to keep or delete it",
|
||||
"gitConflictContinue": "Continue",
|
||||
"gitConflictSkip": "Skip this commit",
|
||||
"gitConflictAbort": "Abort the whole operation",
|
||||
"gitConflictAbortConfirm": "Abort this operation? All resolutions will be discarded.",
|
||||
"gitConflictContinueSuccess": "Operation completed",
|
||||
"gitConflictSkipSuccess": "Commit skipped",
|
||||
"gitConflictAbortSuccess": "Operation aborted",
|
||||
"gitConflictBlockedByUnresolved": "Some conflicts are still unresolved — mark them all resolved first",
|
||||
"gitConflictEmptyCommitNotice": "This commit became empty when applied (its changes already exist in the baseline). You can skip it.",
|
||||
"gitConflictSkipHint": "This commit became empty when applied — its changes usually already exist in the baseline",
|
||||
"gitConflictTypeBothModified": "Both modified",
|
||||
"gitConflictTypeBothAdded": "Both added",
|
||||
"gitConflictTypeDeletedByUs": "Theirs modified, ours deleted",
|
||||
"gitConflictTypeDeletedByThem": "Ours modified, theirs deleted",
|
||||
"gitConflictTypeAddedByUs": "Ours added, theirs exists",
|
||||
"gitConflictTypeAddedByThem": "Theirs added, ours exists",
|
||||
"gitConflictTypeBothDeleted": "Both deleted",
|
||||
"gitConflictTypeUnknown": "Conflict",
|
||||
"gitConflictBaseSegment": "Common ancestor",
|
||||
"gitConflictOursSegment": "Current side",
|
||||
"gitConflictTheirsSegment": "Incoming side",
|
||||
"gitConflictMalformed": "Conflict markers are malformed — edit this file manually",
|
||||
"gitConflictBlockCount": "{count} conflict(s)",
|
||||
"@gitConflictBlockCount": {
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitConflictApplyOurs": "Use this",
|
||||
"gitConflictApplyBoth": "Keep both",
|
||||
|
||||
"gitRemoteBranches": "Remote Branches",
|
||||
"gitLocalBranches": "Local Branches",
|
||||
"gitNoRemoteBranches": "No remote branches yet — fetch first",
|
||||
@@ -1419,6 +1490,8 @@
|
||||
"gitErrWritePermissionDenied": "This account has no write access to this repository",
|
||||
"gitErrWritePermissionDeniedHint": "If this is someone else's repository (upstream), fork it to your own account first, then point the remote at your fork (e.g. https://github.com/your-name/repo.git).",
|
||||
"gitErrRepositoryNotFound": "Repository not found, or this account has no access to it",
|
||||
"gitErrLocalRemoteMissing": "The local remote path does not exist inside the container",
|
||||
"gitErrLocalRemoteMissingHint": "This remote is a local directory (not a network address like GitHub), and it is outside the currently opened project folder. The container only mounts the current project folder, so paths outside it are unreachable. Move the directory into the project, or switch to a network URL.",
|
||||
"gitErrRepositoryNotFoundHint": "GitHub returns 404 for both \"no permission\" and \"does not exist\". Verify the remote URL and that the token can access this repository.",
|
||||
"gitErrProxyAuthRequired": "The network proxy requires authentication",
|
||||
"gitErrProxyAuthRequiredHint": "This network goes through an authenticated proxy (HTTP 407). Check the proxy configuration and credentials inside the container.",
|
||||
|
||||
+264
-12
@@ -3766,6 +3766,258 @@ abstract class AppLocalizations {
|
||||
/// **'暂无分支'**
|
||||
String get gitNoBranches;
|
||||
|
||||
/// No description provided for @gitConflictTitle.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'解决冲突'**
|
||||
String get gitConflictTitle;
|
||||
|
||||
/// No description provided for @gitConflictRebaseInProgress.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'变基进行中'**
|
||||
String get gitConflictRebaseInProgress;
|
||||
|
||||
/// No description provided for @gitConflictMergeInProgress.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'合并进行中'**
|
||||
String get gitConflictMergeInProgress;
|
||||
|
||||
/// No description provided for @gitConflictCherryPickInProgress.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'拣选进行中'**
|
||||
String get gitConflictCherryPickInProgress;
|
||||
|
||||
/// No description provided for @gitConflictRevertInProgress.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'回滚进行中'**
|
||||
String get gitConflictRevertInProgress;
|
||||
|
||||
/// No description provided for @gitConflictRemaining.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'还有 {count} 个文件未解决'**
|
||||
String gitConflictRemaining(int count);
|
||||
|
||||
/// No description provided for @gitConflictAllResolved.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'冲突已全部解决,可以继续'**
|
||||
String get gitConflictAllResolved;
|
||||
|
||||
/// No description provided for @gitConflictResolved.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'已标记为已解决:{path}'**
|
||||
String gitConflictResolved(String path);
|
||||
|
||||
/// No description provided for @gitConflictOpenFile.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'打开文件编辑'**
|
||||
String get gitConflictOpenFile;
|
||||
|
||||
/// No description provided for @gitConflictTakeBaseline.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'采用 {name} 的版本'**
|
||||
String gitConflictTakeBaseline(String name);
|
||||
|
||||
/// No description provided for @gitConflictTakeIncoming.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'采用正在应用的提交版本'**
|
||||
String get gitConflictTakeIncoming;
|
||||
|
||||
/// No description provided for @gitConflictTakeBaselineGeneric.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'整文件采用基线版本'**
|
||||
String get gitConflictTakeBaselineGeneric;
|
||||
|
||||
/// No description provided for @gitConflictRecreate.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'重新生成冲突标记'**
|
||||
String get gitConflictRecreate;
|
||||
|
||||
/// No description provided for @gitConflictRecreateDone.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'已重新生成冲突标记'**
|
||||
String get gitConflictRecreateDone;
|
||||
|
||||
/// No description provided for @gitConflictRemoveFile.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'删除此文件'**
|
||||
String get gitConflictRemoveFile;
|
||||
|
||||
/// No description provided for @gitConflictBinaryHint.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'二进制文件无法用标记解决,请选择保留哪一边'**
|
||||
String get gitConflictBinaryHint;
|
||||
|
||||
/// No description provided for @gitConflictDeleteHint.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'该文件在一侧被删除,请选择保留还是删除'**
|
||||
String get gitConflictDeleteHint;
|
||||
|
||||
/// No description provided for @gitConflictContinue.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'继续'**
|
||||
String get gitConflictContinue;
|
||||
|
||||
/// No description provided for @gitConflictSkip.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'跳过此提交'**
|
||||
String get gitConflictSkip;
|
||||
|
||||
/// No description provided for @gitConflictAbort.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'放弃本次变基'**
|
||||
String get gitConflictAbort;
|
||||
|
||||
/// No description provided for @gitConflictAbortConfirm.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'确定要放弃本次变基操作并回到操作前的状态吗?'**
|
||||
String get gitConflictAbortConfirm;
|
||||
|
||||
/// No description provided for @gitConflictContinueSuccess.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'操作已完成'**
|
||||
String get gitConflictContinueSuccess;
|
||||
|
||||
/// No description provided for @gitConflictSkipSuccess.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'已跳过当前提交'**
|
||||
String get gitConflictSkipSuccess;
|
||||
|
||||
/// No description provided for @gitConflictAbortSuccess.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'已放弃本次操作'**
|
||||
String get gitConflictAbortSuccess;
|
||||
|
||||
/// No description provided for @gitConflictBlockedByUnresolved.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'仍有未解决的冲突文件,请先全部标记为已解决'**
|
||||
String get gitConflictBlockedByUnresolved;
|
||||
|
||||
/// No description provided for @gitConflictEmptyCommitNotice.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'该提交在应用后变为空(内容已存在于基线中),可以跳过它'**
|
||||
String get gitConflictEmptyCommitNotice;
|
||||
|
||||
/// No description provided for @gitConflictSkipHint.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'该提交在应用后变为空,通常表示它的改动已存在于基线中'**
|
||||
String get gitConflictSkipHint;
|
||||
|
||||
/// No description provided for @gitConflictTypeBothModified.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'双方修改'**
|
||||
String get gitConflictTypeBothModified;
|
||||
|
||||
/// No description provided for @gitConflictTypeBothAdded.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'双方新增'**
|
||||
String get gitConflictTypeBothAdded;
|
||||
|
||||
/// No description provided for @gitConflictTypeDeletedByUs.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'对方修改、我方删除'**
|
||||
String get gitConflictTypeDeletedByUs;
|
||||
|
||||
/// No description provided for @gitConflictTypeDeletedByThem.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'我方修改、对方删除'**
|
||||
String get gitConflictTypeDeletedByThem;
|
||||
|
||||
/// No description provided for @gitConflictTypeAddedByUs.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'我方新增、对方已存在'**
|
||||
String get gitConflictTypeAddedByUs;
|
||||
|
||||
/// No description provided for @gitConflictTypeAddedByThem.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'对方新增、我方已存在'**
|
||||
String get gitConflictTypeAddedByThem;
|
||||
|
||||
/// No description provided for @gitConflictTypeBothDeleted.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'双方删除'**
|
||||
String get gitConflictTypeBothDeleted;
|
||||
|
||||
/// No description provided for @gitConflictTypeUnknown.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'冲突'**
|
||||
String get gitConflictTypeUnknown;
|
||||
|
||||
/// No description provided for @gitConflictBaseSegment.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'共同祖先'**
|
||||
String get gitConflictBaseSegment;
|
||||
|
||||
/// No description provided for @gitConflictOursSegment.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'当前侧'**
|
||||
String get gitConflictOursSegment;
|
||||
|
||||
/// No description provided for @gitConflictTheirsSegment.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'传入侧'**
|
||||
String get gitConflictTheirsSegment;
|
||||
|
||||
/// No description provided for @gitConflictMalformed.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'冲突标记结构异常,请手工编辑该文件'**
|
||||
String get gitConflictMalformed;
|
||||
|
||||
/// No description provided for @gitConflictBlockCount.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'{count} 处冲突'**
|
||||
String gitConflictBlockCount(int count);
|
||||
|
||||
/// No description provided for @gitConflictApplyOurs.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'采用此段'**
|
||||
String get gitConflictApplyOurs;
|
||||
|
||||
/// No description provided for @gitConflictApplyBoth.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'两段都要'**
|
||||
String get gitConflictApplyBoth;
|
||||
|
||||
/// No description provided for @gitRemoteBranches.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
@@ -4096,6 +4348,18 @@ abstract class AppLocalizations {
|
||||
/// **'仓库不存在,或当前账号无权访问'**
|
||||
String get gitErrRepositoryNotFound;
|
||||
|
||||
/// No description provided for @gitErrLocalRemoteMissing.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'本地远端路径在容器内不存在'**
|
||||
String get gitErrLocalRemoteMissing;
|
||||
|
||||
/// No description provided for @gitErrLocalRemoteMissingHint.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'该远端是一个本地目录(不是 GitHub 等网络地址),但它不在当前打开的项目目录内。容器只挂载当前项目目录,因此项目外的路径无法访问。请把该目录移到项目内,或改用网络地址。'**
|
||||
String get gitErrLocalRemoteMissingHint;
|
||||
|
||||
/// No description provided for @gitErrRepositoryNotFoundHint.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
@@ -4684,18 +4948,6 @@ abstract class AppLocalizations {
|
||||
/// **'远端存在本地没有的提交,先拉取合并后再推送。'**
|
||||
String get gitPullThenPushDesc;
|
||||
|
||||
/// No description provided for @gitConflictAbort.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'放弃本次变基'**
|
||||
String get gitConflictAbort;
|
||||
|
||||
/// No description provided for @gitConflictAbortConfirm.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'确定要放弃本次变基操作并回到操作前的状态吗?'**
|
||||
String get gitConflictAbortConfirm;
|
||||
|
||||
/// No description provided for @gitUncommittedChangesTitle.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
|
||||
@@ -2250,6 +2250,150 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get gitNoBranches => 'No branches';
|
||||
|
||||
@override
|
||||
String get gitConflictTitle => 'Resolve Conflicts';
|
||||
|
||||
@override
|
||||
String get gitConflictRebaseInProgress => 'Rebase in progress';
|
||||
|
||||
@override
|
||||
String get gitConflictMergeInProgress => 'Merge in progress';
|
||||
|
||||
@override
|
||||
String get gitConflictCherryPickInProgress => 'Cherry-pick in progress';
|
||||
|
||||
@override
|
||||
String get gitConflictRevertInProgress => 'Revert in progress';
|
||||
|
||||
@override
|
||||
String gitConflictRemaining(int count) {
|
||||
return '$count file(s) still unresolved';
|
||||
}
|
||||
|
||||
@override
|
||||
String get gitConflictAllResolved =>
|
||||
'All conflicts resolved, ready to continue';
|
||||
|
||||
@override
|
||||
String gitConflictResolved(String path) {
|
||||
return 'Marked as resolved: $path';
|
||||
}
|
||||
|
||||
@override
|
||||
String get gitConflictOpenFile => 'Open file to edit';
|
||||
|
||||
@override
|
||||
String gitConflictTakeBaseline(String name) {
|
||||
return 'Take version from $name';
|
||||
}
|
||||
|
||||
@override
|
||||
String get gitConflictTakeIncoming =>
|
||||
'Take version from the commit being applied';
|
||||
|
||||
@override
|
||||
String get gitConflictTakeBaselineGeneric =>
|
||||
'Take the baseline version for the whole file';
|
||||
|
||||
@override
|
||||
String get gitConflictRecreate => 'Regenerate conflict markers';
|
||||
|
||||
@override
|
||||
String get gitConflictRecreateDone => 'Conflict markers regenerated';
|
||||
|
||||
@override
|
||||
String get gitConflictRemoveFile => 'Delete this file';
|
||||
|
||||
@override
|
||||
String get gitConflictBinaryHint =>
|
||||
'Binary files cannot be resolved with markers — choose which side to keep';
|
||||
|
||||
@override
|
||||
String get gitConflictDeleteHint =>
|
||||
'This file was deleted on one side — choose whether to keep or delete it';
|
||||
|
||||
@override
|
||||
String get gitConflictContinue => 'Continue';
|
||||
|
||||
@override
|
||||
String get gitConflictSkip => 'Skip this commit';
|
||||
|
||||
@override
|
||||
String get gitConflictAbort => 'Abort Rebase';
|
||||
|
||||
@override
|
||||
String get gitConflictAbortConfirm =>
|
||||
'Abort this rebase and return to the state before it started?';
|
||||
|
||||
@override
|
||||
String get gitConflictContinueSuccess => 'Operation completed';
|
||||
|
||||
@override
|
||||
String get gitConflictSkipSuccess => 'Commit skipped';
|
||||
|
||||
@override
|
||||
String get gitConflictAbortSuccess => 'Operation aborted';
|
||||
|
||||
@override
|
||||
String get gitConflictBlockedByUnresolved =>
|
||||
'Some conflicts are still unresolved — mark them all resolved first';
|
||||
|
||||
@override
|
||||
String get gitConflictEmptyCommitNotice =>
|
||||
'This commit became empty when applied (its changes already exist in the baseline). You can skip it.';
|
||||
|
||||
@override
|
||||
String get gitConflictSkipHint =>
|
||||
'This commit became empty when applied — its changes usually already exist in the baseline';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeBothModified => 'Both modified';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeBothAdded => 'Both added';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeDeletedByUs => 'Theirs modified, ours deleted';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeDeletedByThem => 'Ours modified, theirs deleted';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeAddedByUs => 'Ours added, theirs exists';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeAddedByThem => 'Theirs added, ours exists';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeBothDeleted => 'Both deleted';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeUnknown => 'Conflict';
|
||||
|
||||
@override
|
||||
String get gitConflictBaseSegment => 'Common ancestor';
|
||||
|
||||
@override
|
||||
String get gitConflictOursSegment => 'Current side';
|
||||
|
||||
@override
|
||||
String get gitConflictTheirsSegment => 'Incoming side';
|
||||
|
||||
@override
|
||||
String get gitConflictMalformed =>
|
||||
'Conflict markers are malformed — edit this file manually';
|
||||
|
||||
@override
|
||||
String gitConflictBlockCount(int count) {
|
||||
return '$count conflict(s)';
|
||||
}
|
||||
|
||||
@override
|
||||
String get gitConflictApplyOurs => 'Use this';
|
||||
|
||||
@override
|
||||
String get gitConflictApplyBoth => 'Keep both';
|
||||
|
||||
@override
|
||||
String get gitRemoteBranches => 'Remote Branches';
|
||||
|
||||
@@ -2448,6 +2592,14 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get gitErrRepositoryNotFound =>
|
||||
'Repository not found, or this account has no access to it';
|
||||
|
||||
@override
|
||||
String get gitErrLocalRemoteMissing =>
|
||||
'The local remote path does not exist inside the container';
|
||||
|
||||
@override
|
||||
String get gitErrLocalRemoteMissingHint =>
|
||||
'This remote is a local directory (not a network address like GitHub), and it is outside the currently opened project folder. The container only mounts the current project folder, so paths outside it are unreachable. Move the directory into the project, or switch to a network URL.';
|
||||
|
||||
@override
|
||||
String get gitErrRepositoryNotFoundHint =>
|
||||
'GitHub returns 404 for both \"no permission\" and \"does not exist\". Verify the remote URL and that the token can access this repository.';
|
||||
@@ -2798,13 +2950,6 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get gitPullThenPushDesc =>
|
||||
'The remote has commits you do not have. Pull and merge them before pushing.';
|
||||
|
||||
@override
|
||||
String get gitConflictAbort => 'Abort Rebase';
|
||||
|
||||
@override
|
||||
String get gitConflictAbortConfirm =>
|
||||
'Abort this rebase and return to the state before it started?';
|
||||
|
||||
@override
|
||||
String get gitUncommittedChangesTitle => 'Uncommitted Changes';
|
||||
|
||||
|
||||
@@ -2187,6 +2187,140 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
@override
|
||||
String get gitNoBranches => '暂无分支';
|
||||
|
||||
@override
|
||||
String get gitConflictTitle => '解决冲突';
|
||||
|
||||
@override
|
||||
String get gitConflictRebaseInProgress => '变基进行中';
|
||||
|
||||
@override
|
||||
String get gitConflictMergeInProgress => '合并进行中';
|
||||
|
||||
@override
|
||||
String get gitConflictCherryPickInProgress => '拣选进行中';
|
||||
|
||||
@override
|
||||
String get gitConflictRevertInProgress => '回滚进行中';
|
||||
|
||||
@override
|
||||
String gitConflictRemaining(int count) {
|
||||
return '还有 $count 个文件未解决';
|
||||
}
|
||||
|
||||
@override
|
||||
String get gitConflictAllResolved => '冲突已全部解决,可以继续';
|
||||
|
||||
@override
|
||||
String gitConflictResolved(String path) {
|
||||
return '已标记为已解决:$path';
|
||||
}
|
||||
|
||||
@override
|
||||
String get gitConflictOpenFile => '打开文件编辑';
|
||||
|
||||
@override
|
||||
String gitConflictTakeBaseline(String name) {
|
||||
return '采用 $name 的版本';
|
||||
}
|
||||
|
||||
@override
|
||||
String get gitConflictTakeIncoming => '采用正在应用的提交版本';
|
||||
|
||||
@override
|
||||
String get gitConflictTakeBaselineGeneric => '整文件采用基线版本';
|
||||
|
||||
@override
|
||||
String get gitConflictRecreate => '重新生成冲突标记';
|
||||
|
||||
@override
|
||||
String get gitConflictRecreateDone => '已重新生成冲突标记';
|
||||
|
||||
@override
|
||||
String get gitConflictRemoveFile => '删除此文件';
|
||||
|
||||
@override
|
||||
String get gitConflictBinaryHint => '二进制文件无法用标记解决,请选择保留哪一边';
|
||||
|
||||
@override
|
||||
String get gitConflictDeleteHint => '该文件在一侧被删除,请选择保留还是删除';
|
||||
|
||||
@override
|
||||
String get gitConflictContinue => '继续';
|
||||
|
||||
@override
|
||||
String get gitConflictSkip => '跳过此提交';
|
||||
|
||||
@override
|
||||
String get gitConflictAbort => '放弃本次变基';
|
||||
|
||||
@override
|
||||
String get gitConflictAbortConfirm => '确定要放弃本次变基操作并回到操作前的状态吗?';
|
||||
|
||||
@override
|
||||
String get gitConflictContinueSuccess => '操作已完成';
|
||||
|
||||
@override
|
||||
String get gitConflictSkipSuccess => '已跳过当前提交';
|
||||
|
||||
@override
|
||||
String get gitConflictAbortSuccess => '已放弃本次操作';
|
||||
|
||||
@override
|
||||
String get gitConflictBlockedByUnresolved => '仍有未解决的冲突文件,请先全部标记为已解决';
|
||||
|
||||
@override
|
||||
String get gitConflictEmptyCommitNotice => '该提交在应用后变为空(内容已存在于基线中),可以跳过它';
|
||||
|
||||
@override
|
||||
String get gitConflictSkipHint => '该提交在应用后变为空,通常表示它的改动已存在于基线中';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeBothModified => '双方修改';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeBothAdded => '双方新增';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeDeletedByUs => '对方修改、我方删除';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeDeletedByThem => '我方修改、对方删除';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeAddedByUs => '我方新增、对方已存在';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeAddedByThem => '对方新增、我方已存在';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeBothDeleted => '双方删除';
|
||||
|
||||
@override
|
||||
String get gitConflictTypeUnknown => '冲突';
|
||||
|
||||
@override
|
||||
String get gitConflictBaseSegment => '共同祖先';
|
||||
|
||||
@override
|
||||
String get gitConflictOursSegment => '当前侧';
|
||||
|
||||
@override
|
||||
String get gitConflictTheirsSegment => '传入侧';
|
||||
|
||||
@override
|
||||
String get gitConflictMalformed => '冲突标记结构异常,请手工编辑该文件';
|
||||
|
||||
@override
|
||||
String gitConflictBlockCount(int count) {
|
||||
return '$count 处冲突';
|
||||
}
|
||||
|
||||
@override
|
||||
String get gitConflictApplyOurs => '采用此段';
|
||||
|
||||
@override
|
||||
String get gitConflictApplyBoth => '两段都要';
|
||||
|
||||
@override
|
||||
String get gitRemoteBranches => '远端分支';
|
||||
|
||||
@@ -2371,6 +2505,13 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
@override
|
||||
String get gitErrRepositoryNotFound => '仓库不存在,或当前账号无权访问';
|
||||
|
||||
@override
|
||||
String get gitErrLocalRemoteMissing => '本地远端路径在容器内不存在';
|
||||
|
||||
@override
|
||||
String get gitErrLocalRemoteMissingHint =>
|
||||
'该远端是一个本地目录(不是 GitHub 等网络地址),但它不在当前打开的项目目录内。容器只挂载当前项目目录,因此项目外的路径无法访问。请把该目录移到项目内,或改用网络地址。';
|
||||
|
||||
@override
|
||||
String get gitErrRepositoryNotFoundHint =>
|
||||
'GitHub 对「无权限」和「不存在」都返回 404。请确认远端地址拼写正确,且该令牌有权访问该仓库。';
|
||||
@@ -2691,12 +2832,6 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
@override
|
||||
String get gitPullThenPushDesc => '远端存在本地没有的提交,先拉取合并后再推送。';
|
||||
|
||||
@override
|
||||
String get gitConflictAbort => '放弃本次变基';
|
||||
|
||||
@override
|
||||
String get gitConflictAbortConfirm => '确定要放弃本次变基操作并回到操作前的状态吗?';
|
||||
|
||||
@override
|
||||
String get gitUncommittedChangesTitle => '存在未提交的改动';
|
||||
|
||||
|
||||
@@ -1295,6 +1295,77 @@
|
||||
"gitSearchTags": "搜索标签...",
|
||||
"gitNoBranches": "暂无分支",
|
||||
|
||||
"gitConflictTitle": "解决冲突",
|
||||
"gitConflictRebaseInProgress": "变基进行中",
|
||||
"gitConflictMergeInProgress": "合并进行中",
|
||||
"gitConflictCherryPickInProgress": "拣选进行中",
|
||||
"gitConflictRevertInProgress": "回滚进行中",
|
||||
"gitConflictRemaining": "还有 {count} 个文件未解决",
|
||||
"@gitConflictRemaining": {
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitConflictAllResolved": "冲突已全部解决,可以继续",
|
||||
"gitConflictResolved": "已标记为已解决:{path}",
|
||||
"@gitConflictResolved": {
|
||||
"placeholders": {
|
||||
"path": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitConflictOpenFile": "打开文件编辑",
|
||||
"gitConflictTakeBaseline": "采用 {name} 的版本",
|
||||
"@gitConflictTakeBaseline": {
|
||||
"placeholders": {
|
||||
"name": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitConflictTakeIncoming": "采用正在应用的提交版本",
|
||||
"gitConflictTakeBaselineGeneric": "整文件采用基线版本",
|
||||
"gitConflictRecreate": "重新生成冲突标记",
|
||||
"gitConflictRecreateDone": "已重新生成冲突标记",
|
||||
"gitConflictRemoveFile": "删除此文件",
|
||||
"gitConflictBinaryHint": "二进制文件无法用标记解决,请选择保留哪一边",
|
||||
"gitConflictDeleteHint": "该文件在一侧被删除,请选择保留还是删除",
|
||||
"gitConflictContinue": "继续",
|
||||
"gitConflictSkip": "跳过此提交",
|
||||
"gitConflictAbort": "放弃整个操作",
|
||||
"gitConflictAbortConfirm": "确定放弃本次操作吗?所有已解决的冲突都会回退。",
|
||||
"gitConflictContinueSuccess": "操作已完成",
|
||||
"gitConflictSkipSuccess": "已跳过当前提交",
|
||||
"gitConflictAbortSuccess": "已放弃本次操作",
|
||||
"gitConflictBlockedByUnresolved": "仍有未解决的冲突文件,请先全部标记为已解决",
|
||||
"gitConflictEmptyCommitNotice": "该提交在应用后变为空(内容已存在于基线中),可以跳过它",
|
||||
"gitConflictSkipHint": "该提交在应用后变为空,通常表示它的改动已存在于基线中",
|
||||
"gitConflictTypeBothModified": "双方修改",
|
||||
"gitConflictTypeBothAdded": "双方新增",
|
||||
"gitConflictTypeDeletedByUs": "对方修改、我方删除",
|
||||
"gitConflictTypeDeletedByThem": "我方修改、对方删除",
|
||||
"gitConflictTypeAddedByUs": "我方新增、对方已存在",
|
||||
"gitConflictTypeAddedByThem": "对方新增、我方已存在",
|
||||
"gitConflictTypeBothDeleted": "双方删除",
|
||||
"gitConflictTypeUnknown": "冲突",
|
||||
"gitConflictBaseSegment": "共同祖先",
|
||||
"gitConflictOursSegment": "当前侧",
|
||||
"gitConflictTheirsSegment": "传入侧",
|
||||
"gitConflictMalformed": "冲突标记结构异常,请手工编辑该文件",
|
||||
"gitConflictBlockCount": "{count} 处冲突",
|
||||
"@gitConflictBlockCount": {
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gitConflictApplyOurs": "采用此段",
|
||||
"gitConflictApplyBoth": "两段都要",
|
||||
|
||||
"gitRemoteBranches": "远端分支",
|
||||
"gitLocalBranches": "本地分支",
|
||||
"gitNoRemoteBranches": "暂无远端分支,请先执行抓取",
|
||||
@@ -1419,6 +1490,8 @@
|
||||
"gitErrWritePermissionDenied": "当前账号对该仓库没有写权限",
|
||||
"gitErrWritePermissionDeniedHint": "若这是别人的仓库(上游),请先 Fork 到你自己的账号,再把远端地址改为你的 Fork(如 https://github.com/你的用户名/仓库.git)。",
|
||||
"gitErrRepositoryNotFound": "仓库不存在,或当前账号无权访问",
|
||||
"gitErrLocalRemoteMissing": "本地远端路径在容器内不存在",
|
||||
"gitErrLocalRemoteMissingHint": "该远端是一个本地目录(不是 GitHub 等网络地址),但它不在当前打开的项目目录内。容器只挂载当前项目目录,因此项目外的路径无法访问。请把该目录移到项目内,或改用网络地址。",
|
||||
"gitErrRepositoryNotFoundHint": "GitHub 对「无权限」和「不存在」都返回 404。请确认远端地址拼写正确,且该令牌有权访问该仓库。",
|
||||
"gitErrProxyAuthRequired": "网络代理需要认证",
|
||||
"gitErrProxyAuthRequiredHint": "当前网络经过需要认证的代理(HTTP 407)。请检查容器内代理配置与凭据。",
|
||||
|
||||
@@ -65,6 +65,106 @@ enum GitRemoteSource {
|
||||
manualOverride,
|
||||
}
|
||||
|
||||
/// 处于中断状态的 Git 操作(决定「继续」到底指什么)
|
||||
enum GitPendingOperation {
|
||||
none,
|
||||
rebase,
|
||||
merge,
|
||||
cherryPick,
|
||||
revert,
|
||||
}
|
||||
|
||||
/// 冲突类型(对应 `git status --porcelain` 的 XY 两位状态组合)
|
||||
enum GitConflictType {
|
||||
/// UU —— 双方都修改了同一文件的同一区域,最常见
|
||||
bothModified,
|
||||
|
||||
/// AA —— 双方都新增了同一文件
|
||||
bothAdded,
|
||||
|
||||
/// DU —— 对方删除、我们修改
|
||||
deletedByUs,
|
||||
|
||||
/// UD —— 我们删除、对方修改
|
||||
deletedByThem,
|
||||
|
||||
/// AU —— 我们新增、对方已存在
|
||||
addedByUs,
|
||||
|
||||
/// UA —— 对方新增、我们已存在
|
||||
addedByThem,
|
||||
|
||||
/// DD —— 双方都删除(少见)
|
||||
bothDeleted,
|
||||
|
||||
unknown,
|
||||
}
|
||||
|
||||
/// 一个存在冲突的文件
|
||||
class GitConflictedFile {
|
||||
final String relativePath;
|
||||
final String absolutePath;
|
||||
final GitConflictType type;
|
||||
|
||||
/// 二进制文件无法用 `<<<<<<<` 标记表达,只能整文件选一边
|
||||
final bool isBinary;
|
||||
|
||||
const GitConflictedFile({
|
||||
required this.relativePath,
|
||||
required this.absolutePath,
|
||||
required this.type,
|
||||
this.isBinary = false,
|
||||
});
|
||||
|
||||
/// 是否可通过编辑文本标记来解决
|
||||
bool get canEditManually => !isBinary && type != GitConflictType.bothDeleted;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is GitConflictedFile &&
|
||||
runtimeType == other.runtimeType &&
|
||||
relativePath == other.relativePath &&
|
||||
type == other.type;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(relativePath, type);
|
||||
|
||||
@override
|
||||
String toString() => 'GitConflictedFile($relativePath, ${type.name})';
|
||||
}
|
||||
|
||||
/// 冲突整体状态
|
||||
class GitConflictState {
|
||||
final GitPendingOperation operation;
|
||||
final List<GitConflictedFile> files;
|
||||
|
||||
const GitConflictState({
|
||||
required this.operation,
|
||||
this.files = const [],
|
||||
});
|
||||
|
||||
static const GitConflictState idle = GitConflictState(
|
||||
operation: GitPendingOperation.none,
|
||||
);
|
||||
|
||||
/// 是否有操作处于中断状态(未必有冲突文件:可能冲突已解决待继续)
|
||||
bool get isPending => operation != GitPendingOperation.none;
|
||||
|
||||
/// 是否仍有未解决的文件
|
||||
bool get hasUnresolvedFiles => files.isNotEmpty;
|
||||
|
||||
/// 冲突文件数
|
||||
int get conflictCount => files.length;
|
||||
|
||||
/// 全部解决后才可以「继续」
|
||||
bool get canContinue => isPending && files.isEmpty;
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'GitConflictState(${operation.name}, files=${files.length})';
|
||||
}
|
||||
|
||||
/// 远端追踪分支(`origin/feature-x` 这类)
|
||||
///
|
||||
/// 与 [GitRemote] 不同:后者是"远程仓库"(一个名字 + 地址),
|
||||
|
||||
@@ -55,6 +55,12 @@ class GitProvider extends ChangeNotifier {
|
||||
|
||||
bool _isCloning = false;
|
||||
|
||||
/// 冲突/中断操作状态
|
||||
GitConflictState _conflictState = GitConflictState.idle;
|
||||
|
||||
/// 最近一次冲突操作的结果说明(供 UI 提示,如"因提交为空而停下")
|
||||
String? _conflictNotice;
|
||||
|
||||
bool _isFetching = false;
|
||||
bool _isPulling = false;
|
||||
bool _isPushing = false;
|
||||
@@ -117,6 +123,18 @@ class GitProvider extends ChangeNotifier {
|
||||
bool get isFsckRunning => _isFsckRunning;
|
||||
bool get isCloning => _isCloning;
|
||||
GitOperationProgress? get cloneProgress => _cloneProgress;
|
||||
|
||||
/// 冲突/中断操作状态
|
||||
GitConflictState get conflictState => _conflictState;
|
||||
|
||||
/// 是否有未解决的冲突
|
||||
bool get hasConflicts => _conflictState.hasUnresolvedFiles;
|
||||
|
||||
/// 是否有操作处于中断状态(含"冲突已解决待继续")
|
||||
bool get hasPendingOperation => _conflictState.isPending;
|
||||
|
||||
/// 冲突相关的提示信息(一次性,读取后由 UI 清除)
|
||||
String? get conflictNotice => _conflictNotice;
|
||||
bool get isFetching => _isFetching;
|
||||
bool get isPulling => _isPulling;
|
||||
bool get isPushing => _isPushing;
|
||||
@@ -364,6 +382,8 @@ class GitProvider extends ChangeNotifier {
|
||||
_isFsckRunning = false;
|
||||
_cloneProgress = null;
|
||||
_isCloning = false;
|
||||
_conflictState = GitConflictState.idle;
|
||||
_conflictNotice = null;
|
||||
_isFetching = false;
|
||||
_isPulling = false;
|
||||
_isPushing = false;
|
||||
@@ -823,6 +843,8 @@ class GitProvider extends ChangeNotifier {
|
||||
_remoteBranches = await _gitService.getRemoteBranches(_currentRepoPath!);
|
||||
// 远程目标解析依赖 branch.<name>.* 与 remote.pushDefault
|
||||
await _loadRemoteTargetConfig();
|
||||
// 冲突/中断状态:pull 撞冲突后必须立刻能呈现给用户
|
||||
await _loadConflictState();
|
||||
|
||||
// 同步更新 repositories 列表中当前项的分支信息
|
||||
final idx = _repositories.indexWhere((r) => r.rootPath == _currentRepoPath);
|
||||
@@ -930,6 +952,8 @@ class GitProvider extends ChangeNotifier {
|
||||
if (res.success) _lastFetchAt = DateTime.now();
|
||||
// fetch 会改变 ahead/behind,必须即时刷新远端状态
|
||||
await _loadRemoteStateOnly();
|
||||
// fetch 本身不产生冲突,但用户可能在中断状态下点它,这里顺带校正状态
|
||||
await _reloadConflictStateAndNotify();
|
||||
return res;
|
||||
} finally {
|
||||
_isFetching = false;
|
||||
@@ -976,6 +1000,9 @@ class GitProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
} else {
|
||||
await _loadRemoteStateOnly();
|
||||
// 失败很可能正是因为撞了冲突:必须立刻探测,否则冲突横幅不会出现,
|
||||
// 用户根本找不到解决入口(只有下次完整刷新才会暴露)
|
||||
await _reloadConflictStateAndNotify();
|
||||
}
|
||||
return res;
|
||||
} finally {
|
||||
@@ -1025,6 +1052,9 @@ class GitProvider extends ChangeNotifier {
|
||||
_recordRemoteResult(res);
|
||||
if (res.success) {
|
||||
await _loadRemoteStateOnly();
|
||||
} else {
|
||||
// 推送失败也可能是中断状态导致的,同样校正一次
|
||||
await _reloadConflictStateAndNotify();
|
||||
}
|
||||
return res;
|
||||
} finally {
|
||||
@@ -1161,6 +1191,182 @@ class GitProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// 冲突解决
|
||||
// ==========================================================================
|
||||
|
||||
/// 重新读取冲突与中断操作状态
|
||||
Future<void> _loadConflictState() async {
|
||||
if (_currentRepoPath == null) {
|
||||
_conflictState = GitConflictState.idle;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final operation = _gitService.getPendingOperation(_currentRepoPath!);
|
||||
if (operation == GitPendingOperation.none) {
|
||||
_conflictState = GitConflictState.idle;
|
||||
return;
|
||||
}
|
||||
final files = await _gitService.getConflictedFiles(_currentRepoPath!);
|
||||
_conflictState = GitConflictState(operation: operation, files: files);
|
||||
} catch (e) {
|
||||
debugPrint('[GitProvider] 读取冲突状态异常: $e');
|
||||
_conflictState = GitConflictState.idle;
|
||||
}
|
||||
}
|
||||
|
||||
/// 手动刷新冲突状态(冲突面板打开时调用)
|
||||
Future<void> refreshConflictState() async {
|
||||
await _loadConflictState();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 重新探测冲突状态并通知 UI
|
||||
///
|
||||
/// 先做一次极轻量的文件系统探测(无进程开销),只有确实处于中断状态时
|
||||
/// 才去解析冲突文件列表 —— 这样可以挂在每次网络操作失败之后而不付代价。
|
||||
Future<void> _reloadConflictStateAndNotify() async {
|
||||
if (_currentRepoPath == null) return;
|
||||
final operation = _gitService.getPendingOperation(_currentRepoPath!);
|
||||
if (operation == GitPendingOperation.none) {
|
||||
if (_conflictState.isPending) {
|
||||
_conflictState = GitConflictState.idle;
|
||||
notifyListeners();
|
||||
}
|
||||
return;
|
||||
}
|
||||
await _loadConflictState();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 把文件标记为已解决(`git add`)
|
||||
Future<GitCommandResult> markConflictResolved(GitConflictedFile file) async {
|
||||
if (_currentRepoPath == null) return GitCommandResult.error('未选择仓库');
|
||||
final res = await _gitService.markResolved(
|
||||
_currentRepoPath!,
|
||||
file.relativePath,
|
||||
);
|
||||
await _afterConflictAction(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 整文件采用某一侧
|
||||
///
|
||||
/// [useOurs] 的含义随操作类型变化(rebase 下 ours 是基线),
|
||||
/// 文案由 UI 按 [conflictState] 的 operation 决定。
|
||||
Future<GitCommandResult> takeConflictSide(
|
||||
GitConflictedFile file, {
|
||||
required bool useOurs,
|
||||
}) async {
|
||||
if (_currentRepoPath == null) return GitCommandResult.error('未选择仓库');
|
||||
final res = await _gitService.checkoutConflictSide(
|
||||
_currentRepoPath!,
|
||||
file.relativePath,
|
||||
useOurs: useOurs,
|
||||
);
|
||||
await _afterConflictAction(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 重新生成冲突标记(改坏了用它恢复)
|
||||
Future<GitCommandResult> recreateConflictMarkers(
|
||||
GitConflictedFile file,
|
||||
) async {
|
||||
if (_currentRepoPath == null) return GitCommandResult.error('未选择仓库');
|
||||
final res = await _gitService.recreateConflictMarkers(
|
||||
_currentRepoPath!,
|
||||
file.relativePath,
|
||||
);
|
||||
if (res.success) {
|
||||
await _loadConflictState();
|
||||
notifyListeners();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 删除冲突文件(modify/delete 冲突中选择"确认删除")
|
||||
Future<GitCommandResult> removeConflictedFile(GitConflictedFile file) async {
|
||||
if (_currentRepoPath == null) return GitCommandResult.error('未选择仓库');
|
||||
final res = await _gitService.removeConflictedFile(
|
||||
_currentRepoPath!,
|
||||
file.relativePath,
|
||||
);
|
||||
await _afterConflictAction(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 继续被中断的操作
|
||||
///
|
||||
/// 若仍有未解决文件,直接拒绝 —— 否则 git 会立刻再次停下,
|
||||
/// 用户会以为是"继续没生效"。
|
||||
Future<GitCommandResult> continueOperation() async {
|
||||
if (_currentRepoPath == null) return GitCommandResult.error('未选择仓库');
|
||||
if (_conflictState.files.isNotEmpty) {
|
||||
return GitCommandResult.error('仍有未解决的冲突文件,请先全部标记为已解决');
|
||||
}
|
||||
final res = await _gitService.continueOperation(
|
||||
_currentRepoPath!,
|
||||
_conflictState.operation,
|
||||
);
|
||||
|
||||
if (!res.success &&
|
||||
_gitService.isOperationStoppedForEmptyCommit(res.stderr + res.stdout)) {
|
||||
// 提交为空导致再次停下:这是正常现象,但必须明确告诉用户可以跳过
|
||||
_conflictNotice = 'emptyCommit';
|
||||
await _loadConflictState();
|
||||
notifyListeners();
|
||||
return res;
|
||||
}
|
||||
|
||||
await _afterConflictAction(res, fullReload: true);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 跳过当前提交
|
||||
Future<GitCommandResult> skipOperation() async {
|
||||
if (_currentRepoPath == null) return GitCommandResult.error('未选择仓库');
|
||||
final res = await _gitService.skipOperation(
|
||||
_currentRepoPath!,
|
||||
_conflictState.operation,
|
||||
);
|
||||
await _afterConflictAction(res, fullReload: true);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 放弃被中断的操作
|
||||
Future<GitCommandResult> abortOperation() async {
|
||||
if (_currentRepoPath == null) return GitCommandResult.error('未选择仓库');
|
||||
final res = await _gitService.abortOperation(
|
||||
_currentRepoPath!,
|
||||
_conflictState.operation,
|
||||
);
|
||||
await _afterConflictAction(res, fullReload: true);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// 清除一次性提示
|
||||
void clearConflictNotice() {
|
||||
_conflictNotice = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 冲突操作后的统一刷新
|
||||
///
|
||||
/// [fullReload] 表示操作可能改写了提交历史(continue/skip/abort),
|
||||
/// 此时必须完整刷新而非只刷新远端状态。
|
||||
Future<void> _afterConflictAction(
|
||||
GitCommandResult res, {
|
||||
bool fullReload = false,
|
||||
}) async {
|
||||
if (!res.success) return;
|
||||
if (fullReload) {
|
||||
await _loadCurrentRepoDetails();
|
||||
} else {
|
||||
await _loadConflictState();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// ---------------------------- 远端分支检出 ----------------------------
|
||||
|
||||
/// 基于远端分支检出(或切换到已有的)本地分支
|
||||
|
||||
@@ -234,6 +234,39 @@ class TabProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 强制从磁盘重新加载指定文件的内容(丢弃内存中的编辑)
|
||||
///
|
||||
/// 冲突解决必须用它而不是 [openFile]:Git 在冲突时**直接改写了工作区文件**
|
||||
/// 并写入 `<<<<<<<` 标记,而 [openFile] 对已打开的 tab 不会重载内容 ——
|
||||
/// 那样用户会看到没有标记的旧内存版本,改完保存还会把标记覆盖掉,
|
||||
/// 索引却仍是 unmerged,状态彻底错乱。
|
||||
///
|
||||
/// 返回是否成功找到并重载了该 tab。
|
||||
Future<bool> reloadTabFromDisk(String path) async {
|
||||
final cleanPath = p.normalize(path.trim());
|
||||
final index = _openTabs.indexWhere((tab) => p.equals(tab.path, cleanPath));
|
||||
if (index == -1) return false;
|
||||
|
||||
try {
|
||||
final raw = await FileService.instance.readFileContent(cleanPath);
|
||||
final diskContent = raw.replaceAll('\r\n', '\n');
|
||||
final tab = _openTabs[index];
|
||||
tab.content = diskContent;
|
||||
tab.originalContent = diskContent;
|
||||
tab.isModified = false;
|
||||
tab.hasExternalConflict = false;
|
||||
tab.isDeletedOnDisk = false;
|
||||
if (_activeFilePath == tab.path) {
|
||||
_isModified = false;
|
||||
}
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
debugPrint('强制重载文件失败: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 解决外部文件冲突
|
||||
Future<void> resolveConflict(EditorTabItem tab, {required bool reloadFromDisk}) async {
|
||||
tab.hasExternalConflict = false;
|
||||
|
||||
@@ -31,12 +31,35 @@ class GitRemoteCommandResult {
|
||||
/// 命令是否因用户取消而中止
|
||||
final bool cancelled;
|
||||
|
||||
/// 实际执行的完整命令串(含环境前缀),仅用于排查环境差异问题
|
||||
final String? executedCommand;
|
||||
|
||||
/// 实际使用的容器内工作目录
|
||||
final String? containerWorkDir;
|
||||
|
||||
/// 传给 proot 的宿主仓库路径 —— 它就挂载为容器内的 `/workspace`
|
||||
final String? hostRepoPath;
|
||||
|
||||
/// 传给 proot 的宿主工程根路径(决定 `mapToContainerPath` 的结果)
|
||||
final String? hostRootPath;
|
||||
|
||||
/// 实际作为 `/workspace` 挂载源的宿主路径
|
||||
///
|
||||
/// 正常情况下应等于工程根 —— 若它等于某个仓库路径,说明在 Source Control
|
||||
/// 里切换仓库会改变 `/workspace` 的含义,远程 URL 将随之失效。
|
||||
final String? mountSource;
|
||||
|
||||
const GitRemoteCommandResult({
|
||||
required this.success,
|
||||
required this.exitCode,
|
||||
required this.stdout,
|
||||
required this.stderr,
|
||||
this.cancelled = false,
|
||||
this.executedCommand,
|
||||
this.containerWorkDir,
|
||||
this.hostRepoPath,
|
||||
this.hostRootPath,
|
||||
this.mountSource,
|
||||
});
|
||||
|
||||
factory GitRemoteCommandResult.error(String message, {int exitCode = -1}) {
|
||||
@@ -56,8 +79,34 @@ class GitRemoteCommandResult {
|
||||
cancelled: true,
|
||||
);
|
||||
|
||||
/// 合并后的输出,供错误映射使用
|
||||
String get combinedOutput => '$stderr\n$stdout';
|
||||
/// 合并后的输出,供错误映射与详情展示使用
|
||||
///
|
||||
/// 把实际执行环境一并带上:定位"同一路径在终端能用、在面板不能用"这类
|
||||
/// 差异时,缺少这些值就只能靠猜 —— 而 proot 的挂载源正是 [hostRepoPath],
|
||||
/// 它一旦不对,容器内 `/workspace` 的内容就会和终端看到的完全不同。
|
||||
String get combinedOutput {
|
||||
final buffer = StringBuffer();
|
||||
if (mountSource != null && mountSource!.isNotEmpty) {
|
||||
buffer.writeln('# mount: $mountSource -> /workspace');
|
||||
}
|
||||
if (hostRepoPath != null &&
|
||||
hostRepoPath!.isNotEmpty &&
|
||||
hostRepoPath != mountSource) {
|
||||
buffer.writeln('# repo: $hostRepoPath');
|
||||
}
|
||||
if (hostRootPath != null && hostRootPath!.isNotEmpty) {
|
||||
buffer.writeln('# root: $hostRootPath');
|
||||
}
|
||||
if (containerWorkDir != null && containerWorkDir!.isNotEmpty) {
|
||||
buffer.writeln('# cwd: $containerWorkDir');
|
||||
}
|
||||
if (executedCommand != null && executedCommand!.isNotEmpty) {
|
||||
buffer.writeln('# cmd: $executedCommand');
|
||||
}
|
||||
if (buffer.isNotEmpty) buffer.writeln();
|
||||
buffer.write('$stderr\n$stdout');
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/// 需要实时输出回调与取消能力的命令执行器签名(可注入以便测试)
|
||||
@@ -238,6 +287,12 @@ class GitService {
|
||||
if (emailCheck.stdout.toString().trim().isEmpty) {
|
||||
await _runProcess('git', ['config', '--global', 'user.email', 'user@codeeditor.local']);
|
||||
}
|
||||
// 冲突时保留「共同祖先」段:只有 base 才能让用户看出两边各自改了什么,
|
||||
// 默认风格只给两个版本,用户只能靠猜。这是全局配置,配一次长期生效。
|
||||
final styleCheck = await _runProcess('git', ['config', '--global', 'merge.conflictStyle']);
|
||||
if (styleCheck.stdout.toString().trim().isEmpty) {
|
||||
await _runProcess('git', ['config', '--global', 'merge.conflictStyle', 'diff3']);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@@ -1229,6 +1284,66 @@ class GitService {
|
||||
'git -c safe.directory=* -c credential.interactive=false -c core.askPass= $body';
|
||||
}
|
||||
|
||||
/// 把参数里的**本地文件路径型远程地址**换算成容器内路径
|
||||
///
|
||||
/// 只处理确实指向宿主文件系统上存在路径的参数,其余(子命令、选项、
|
||||
/// 分支名、网络地址)一律原样返回。
|
||||
///
|
||||
/// 必须如此保守:`git push --progress origin master` 里的每个词都是普通
|
||||
/// 字符串,一旦按"相对路径"去拼就会变成 `<工程根>/fetch` 这类垃圾路径,
|
||||
/// 把命令整个写坏。
|
||||
@visibleForTesting
|
||||
String mapRemoteArgToContainer(String url, String rootPath) {
|
||||
final trimmed = url.trim();
|
||||
if (trimmed.isEmpty) return url;
|
||||
|
||||
// 网络地址与选项不需处理
|
||||
if (trimmed.startsWith('-')) return url;
|
||||
if (trimmed.startsWith('http://') ||
|
||||
trimmed.startsWith('https://') ||
|
||||
trimmed.startsWith('ssh://') ||
|
||||
trimmed.startsWith('git://') ||
|
||||
RegExp(r'^[^/\\@]+@[^:]+:').hasMatch(trimmed)) {
|
||||
return url;
|
||||
}
|
||||
|
||||
final hostPath = _resolveHostLocalPath(trimmed);
|
||||
// 只有宿主上真实存在才认定为"路径型远程":
|
||||
// 这是区分 `origin`(远程名)与 `../server.git`(路径)的唯一可靠依据。
|
||||
if (hostPath == null || !_hostPathExists(hostPath)) return url;
|
||||
|
||||
final hostRoot = p.normalize(rootPath);
|
||||
final normalizedTarget = p.normalize(hostPath);
|
||||
// 只映射工程目录内的路径:工程根挂载为 /workspace,
|
||||
// 目录之外的宿主路径在容器内不存在,映射过去只会误导。
|
||||
if (normalizedTarget == hostRoot || p.isWithin(hostRoot, normalizedTarget)) {
|
||||
return mapToContainerPath(normalizedTarget, rootPath);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/// 把本地路径型地址解析为宿主的绝对路径;无法解析时返回 null
|
||||
String? _resolveHostLocalPath(String url) {
|
||||
try {
|
||||
if (url.startsWith('file://')) {
|
||||
final uri = Uri.tryParse(url);
|
||||
if (uri == null) return null;
|
||||
return p.normalize(uri.toFilePath());
|
||||
}
|
||||
return p.normalize(url);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
bool _hostPathExists(String hostPath) {
|
||||
try {
|
||||
return Directory(hostPath).existsSync() || File(hostPath).existsSync();
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 从 git 进度输出行解析阶段名与百分比
|
||||
///
|
||||
/// 形如 `Receiving objects: 45% (450/1000), 1.2 MiB | 300 KiB/s`。
|
||||
@@ -1278,9 +1393,40 @@ class GitService {
|
||||
);
|
||||
}
|
||||
|
||||
final containerCmd = buildGuestGitCommand(args);
|
||||
// 参数里的本地路径型远程地址(如 /root/demo/server.git 或 file://…)
|
||||
// 必须一并映射进容器;否则容器内工作目录对了,URL 指向的路径却不存在,
|
||||
// 表现为 "'/workspace/xxx' does not appear to be a git repository"。
|
||||
final effectiveRoot = rootPath ?? repoPath;
|
||||
final mappedArgs = args
|
||||
.map((a) => mapRemoteArgToContainer(a, effectiveRoot))
|
||||
.toList();
|
||||
|
||||
final containerCmd = buildGuestGitCommand(mappedArgs);
|
||||
final containerWorkDir = mapToContainerPath(repoPath, rootPath);
|
||||
|
||||
// 挂载源必须是**项目根**而不是当前选中的仓库:
|
||||
// /workspace 固定对应项目根,仓库位置由工作目录(cwd)表达。
|
||||
// 若挂载源取 repoPath,那么在 Source Control 里切换仓库就会改变
|
||||
// /workspace 的含义 —— 同一个容器路径 `/workspace/server.git` 会时有时无,
|
||||
// 远程 URL 也随之失效。项目根在整个会话中是稳定的,正确。
|
||||
final mountSource = (rootPath != null && rootPath.trim().isNotEmpty)
|
||||
? rootPath
|
||||
: repoPath;
|
||||
|
||||
// 把 cd 拼进命令串本身,而不是依赖 proot 的 `-w`:
|
||||
// proot 按参数顺序处理,`-w` 位于 `-b` 之后、挂载尚未生效,
|
||||
// 指向挂载点内部的路径(如 /workspace/work)会 chdir 失败,
|
||||
// 表现为 git 在容器的 `/` 下执行并报 "not a git repository"。
|
||||
//
|
||||
// 在此处拼装而非在执行器内部:这样 `# cmd:` 诊断显示的就是真实命令,
|
||||
// 且注入式测试也能断言到它。
|
||||
// 容器内是 Linux,路径必须用正斜杠:p.join/p.normalize 在 Windows 上
|
||||
// 会产出反斜杠,直接拼进命令会变成 `cd /workspace\work` 而失败。
|
||||
final effectiveWorkDir = (containerWorkDir.isNotEmpty && containerWorkDir.startsWith('/'))
|
||||
? containerWorkDir.replaceAll(r'\', '/')
|
||||
: '/workspace';
|
||||
final commandWithCd = 'cd $effectiveWorkDir && $containerCmd';
|
||||
|
||||
void emit(String chunk) {
|
||||
if (onProgress == null) return;
|
||||
for (final line in chunk.split('\n')) {
|
||||
@@ -1297,9 +1443,9 @@ class GitService {
|
||||
final ProcessResult? res;
|
||||
if (streamRunner != null) {
|
||||
res = await streamRunner!(
|
||||
executable: containerCmd,
|
||||
executable: commandWithCd,
|
||||
arguments: const [],
|
||||
workspacePath: repoPath,
|
||||
workspacePath: mountSource,
|
||||
containerWorkDir: containerWorkDir,
|
||||
onOutput: emit,
|
||||
cancelToken: cancelToken,
|
||||
@@ -1308,9 +1454,9 @@ class GitService {
|
||||
} else {
|
||||
final runner = _defaultStreamRunner;
|
||||
res = await runner(
|
||||
executable: containerCmd,
|
||||
executable: commandWithCd,
|
||||
arguments: const [],
|
||||
workspacePath: repoPath,
|
||||
workspacePath: mountSource,
|
||||
containerWorkDir: containerWorkDir,
|
||||
onOutput: emit,
|
||||
cancelToken: cancelToken,
|
||||
@@ -1331,6 +1477,11 @@ class GitService {
|
||||
exitCode: res.exitCode,
|
||||
stdout: res.stdout.toString(),
|
||||
stderr: res.stderr.toString(),
|
||||
executedCommand: commandWithCd,
|
||||
containerWorkDir: containerWorkDir,
|
||||
hostRepoPath: repoPath,
|
||||
hostRootPath: rootPath,
|
||||
mountSource: mountSource,
|
||||
);
|
||||
} catch (e) {
|
||||
return GitRemoteCommandResult.error('云端命令异常: $e');
|
||||
@@ -1362,6 +1513,8 @@ class GitService {
|
||||
HeadlessCancelToken? cancelToken,
|
||||
Duration timeout = remoteNetworkTimeout,
|
||||
}) async {
|
||||
// executable 已是可直接执行的完整命令(含 cd 与 git 全局选项),
|
||||
// 由 runRemoteGitCommand 统一拼装 —— 那里同时是诊断显示的来源。
|
||||
final fullCommand = arguments.isEmpty
|
||||
? executable
|
||||
: '$executable ${arguments.map(_escapeShellArg).join(' ')}';
|
||||
@@ -1901,6 +2054,284 @@ class GitService {
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------- 冲突解决 ----------------------------
|
||||
|
||||
/// 探测当前是否存在中断的 Git 操作
|
||||
///
|
||||
/// 纯文件系统探测(毫秒级、无进程开销),并区分具体是哪种操作 ——
|
||||
/// 因为「继续」按钮的含义完全取决于它是 rebase 还是 merge:
|
||||
/// `git rebase --continue` 与 `git merge --continue` 是不同命令。
|
||||
GitPendingOperation getPendingOperation(String repoPath) {
|
||||
try {
|
||||
final gitDir = Directory(p.join(repoPath, '.git'));
|
||||
if (!gitDir.existsSync()) return GitPendingOperation.none;
|
||||
|
||||
// cherry-pick / revert 都使用 sequencer 目录,需再读 todo 文件区分
|
||||
if (Directory(p.join(gitDir.path, 'sequencer')).existsSync()) {
|
||||
final todo = File(p.join(gitDir.path, 'sequencer', 'todo'));
|
||||
if (todo.existsSync()) {
|
||||
final first = todo.readAsStringSync().split('\n').first.trim();
|
||||
if (first.startsWith('pick')) return GitPendingOperation.cherryPick;
|
||||
if (first.startsWith('revert')) return GitPendingOperation.revert;
|
||||
}
|
||||
// todo 读不到时按 cherry-pick 处理(更常见)
|
||||
return GitPendingOperation.cherryPick;
|
||||
}
|
||||
|
||||
if (Directory(p.join(gitDir.path, 'rebase-merge')).existsSync() ||
|
||||
Directory(p.join(gitDir.path, 'rebase-apply')).existsSync()) {
|
||||
return GitPendingOperation.rebase;
|
||||
}
|
||||
|
||||
if (File(p.join(gitDir.path, 'MERGE_HEAD')).existsSync()) {
|
||||
return GitPendingOperation.merge;
|
||||
}
|
||||
|
||||
return GitPendingOperation.none;
|
||||
} catch (_) {
|
||||
return GitPendingOperation.none;
|
||||
}
|
||||
}
|
||||
|
||||
/// 读取所有存在冲突的文件 (`git diff --name-only --diff-filter=U`)
|
||||
///
|
||||
/// 用 `-z` 以 NUL 分隔:文件路径可能含空格或特殊字符,按行切会解析错。
|
||||
/// 用 `--diff-filter=U` 而不是 `git status --porcelain`:后者同一文件可能
|
||||
/// 产生多行(暂存/工作区各一行),这里要的是"未合并"的准确集合。
|
||||
Future<List<GitConflictedFile>> getConflictedFiles(String repoPath) async {
|
||||
final res = await runGitCommand(
|
||||
['diff', '--name-only', '--diff-filter=U', '-z'],
|
||||
workingDir: repoPath,
|
||||
);
|
||||
if (!res.success) return [];
|
||||
|
||||
final paths = res.stdout
|
||||
.split('\x00')
|
||||
.map((s) => s.trim())
|
||||
.where((s) => s.isNotEmpty)
|
||||
.toList();
|
||||
if (paths.isEmpty) return [];
|
||||
|
||||
// 一次性拿到所有文件的两位数冲突类型
|
||||
final types = await _getConflictTypes(repoPath);
|
||||
|
||||
final files = <GitConflictedFile>[];
|
||||
for (final path in paths) {
|
||||
final normalized = path.replaceAll('\\', '/');
|
||||
files.add(GitConflictedFile(
|
||||
relativePath: normalized,
|
||||
absolutePath: p.normalize(p.join(repoPath, normalized)),
|
||||
type: types[normalized] ?? GitConflictType.unknown,
|
||||
isBinary: await _isBinaryPath(repoPath, normalized),
|
||||
));
|
||||
}
|
||||
files.sort((a, b) => a.relativePath.compareTo(b.relativePath));
|
||||
return files;
|
||||
}
|
||||
|
||||
/// 解析 `git status --porcelain` 中的未合并类型映射
|
||||
Future<Map<String, GitConflictType>> _getConflictTypes(String repoPath) async {
|
||||
final res = await runGitCommand(
|
||||
['status', '--porcelain', '-uall', '-z'],
|
||||
workingDir: repoPath,
|
||||
);
|
||||
if (!res.success) return const {};
|
||||
return parseUnmergedTypes(res.stdout);
|
||||
}
|
||||
|
||||
/// 从 porcelain 输出解析出 `路径 → 冲突类型`
|
||||
///
|
||||
/// 处理 `-z` 格式:条目以 NUL 分隔,重命名条目的原路径作为**独立字段**
|
||||
/// 紧随其后(因此遇到 R/C 状态需要多跳一个字段)。
|
||||
@visibleForTesting
|
||||
Map<String, GitConflictType> parseUnmergedTypes(String stdout) {
|
||||
final result = <String, GitConflictType>{};
|
||||
final entries = stdout.split('\x00');
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
final entry = entries[i];
|
||||
if (entry.length < 4) continue;
|
||||
|
||||
final x = entry[0];
|
||||
final y = entry[1];
|
||||
final path = entry.substring(3);
|
||||
if (path.isEmpty) continue;
|
||||
|
||||
// 重命名/复制会额外带一个原路径字段,跳过它避免被当成下一个条目
|
||||
if (x == 'R' || x == 'C') i++;
|
||||
|
||||
final type = _mapConflictType(x, y);
|
||||
if (type != null) {
|
||||
result[path] = type;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// 映射 XY 两位状态到冲突类型;非未合并组合返回 null
|
||||
GitConflictType? _mapConflictType(String x, String y) {
|
||||
return switch ('$x$y') {
|
||||
'UU' => GitConflictType.bothModified,
|
||||
'AA' => GitConflictType.bothAdded,
|
||||
'DU' => GitConflictType.deletedByUs,
|
||||
'UD' => GitConflictType.deletedByThem,
|
||||
'AU' => GitConflictType.addedByUs,
|
||||
'UA' => GitConflictType.addedByThem,
|
||||
'DD' => GitConflictType.bothDeleted,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// 判断某路径是否为二进制(用 `git diff --numstat` 的 `-` 标记)
|
||||
Future<bool> _isBinaryPath(String repoPath, String relativePath) async {
|
||||
try {
|
||||
final res = await runGitCommand(
|
||||
['diff', '--numstat', '--diff-filter=U', '--', relativePath],
|
||||
workingDir: repoPath,
|
||||
);
|
||||
if (!res.success) return false;
|
||||
// 二进制文件的 added/deleted 列为 `-`
|
||||
return RegExp(r'^-\s+-\s', multiLine: true).hasMatch(res.stdout);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 冲突三方内容(共同祖先 / ours / theirs)
|
||||
///
|
||||
/// 直接复用 `git show :<stage>:<path>`:
|
||||
/// stage 1 = 共同祖先,stage 2 = ours,stage 3 = theirs。
|
||||
Future<({String? base, String? ours, String? theirs})> getConflictContents(
|
||||
String repoPath,
|
||||
String relativePath,
|
||||
) async {
|
||||
final normalized = relativePath.replaceAll('\\', '/');
|
||||
final base = await getFileContentAtRef(repoPath, ':1', normalized);
|
||||
final ours = await getFileContentAtRef(repoPath, ':2', normalized);
|
||||
final theirs = await getFileContentAtRef(repoPath, ':3', normalized);
|
||||
return (base: base, ours: ours, theirs: theirs);
|
||||
}
|
||||
|
||||
/// 把某个冲突文件标记为已解决 (`git add`)
|
||||
///
|
||||
/// 这一步的实质是:把索引里的 stage 1/2/3 合并回 stage 0,
|
||||
/// 也就是"以当前工作区内容为准,冲突结束"。
|
||||
Future<GitCommandResult> markResolved(String repoPath, String relativePath) async {
|
||||
return runGitCommand(['add', '--', relativePath], workingDir: repoPath);
|
||||
}
|
||||
|
||||
/// 整文件采用某一侧
|
||||
///
|
||||
/// [useOurs] 对应 `--ours`(stage 2)、否则 `--theirs`(stage 3)。
|
||||
/// ⚠️ 在 rebase 语境下 ours 指的是**被变基到的基线**、theirs 是**正在应用的
|
||||
/// 提交**,与直觉相反,因此 UI 文案必须按实际操作类型翻译,不能写"我的/对方的"。
|
||||
Future<GitCommandResult> checkoutConflictSide(
|
||||
String repoPath,
|
||||
String relativePath, {
|
||||
required bool useOurs,
|
||||
}) async {
|
||||
final res = await runGitCommand(
|
||||
['checkout', useOurs ? '--ours' : '--theirs', '--', relativePath],
|
||||
workingDir: repoPath,
|
||||
);
|
||||
if (!res.success) return res;
|
||||
// 选边后必须加入索引,否则冲突仍未解决
|
||||
return runGitCommand(['add', '--', relativePath], workingDir: repoPath);
|
||||
}
|
||||
|
||||
/// 重新生成标记 (`git checkout --merge`)
|
||||
///
|
||||
/// 用户把标记删坏后用它恢复,比手动撤销可靠。
|
||||
Future<GitCommandResult> recreateConflictMarkers(
|
||||
String repoPath,
|
||||
String relativePath,
|
||||
) async {
|
||||
return runGitCommand(
|
||||
['checkout', '--merge', '--', relativePath],
|
||||
workingDir: repoPath,
|
||||
);
|
||||
}
|
||||
|
||||
/// 从版本库中删除冲突文件 (`git rm -f`)
|
||||
///
|
||||
/// 用于 modify/delete 冲突中选择"确认删除"。
|
||||
Future<GitCommandResult> removeConflictedFile(
|
||||
String repoPath,
|
||||
String relativePath,
|
||||
) async {
|
||||
return runGitCommand(['rm', '-f', '--', relativePath], workingDir: repoPath);
|
||||
}
|
||||
|
||||
/// 继续被中断的操作
|
||||
///
|
||||
/// 显式禁用编辑器:非交互环境下 `--continue` 会沿用原提交信息,
|
||||
/// 若 git 试图拉起编辑器会直接挂死(没有 TTY)。
|
||||
Future<GitCommandResult> continueOperation(
|
||||
String repoPath,
|
||||
GitPendingOperation operation,
|
||||
) async {
|
||||
final args = switch (operation) {
|
||||
GitPendingOperation.rebase => ['-c', 'core.editor=true', 'rebase', '--continue'],
|
||||
GitPendingOperation.merge => ['-c', 'core.editor=true', 'merge', '--continue'],
|
||||
GitPendingOperation.cherryPick => [
|
||||
'-c',
|
||||
'core.editor=true',
|
||||
'cherry-pick',
|
||||
'--continue',
|
||||
],
|
||||
GitPendingOperation.revert => ['-c', 'core.editor=true', 'revert', '--continue'],
|
||||
GitPendingOperation.none => <String>[],
|
||||
};
|
||||
if (args.isEmpty) {
|
||||
return GitCommandResult.error('当前没有需要继续的操作');
|
||||
}
|
||||
return runGitCommand(args, workingDir: repoPath);
|
||||
}
|
||||
|
||||
/// 跳过当前提交(仅 rebase / cherry-pick / revert 有意义)
|
||||
Future<GitCommandResult> skipOperation(
|
||||
String repoPath,
|
||||
GitPendingOperation operation,
|
||||
) async {
|
||||
final args = switch (operation) {
|
||||
GitPendingOperation.rebase => ['rebase', '--skip'],
|
||||
GitPendingOperation.cherryPick => ['cherry-pick', '--skip'],
|
||||
GitPendingOperation.revert => ['revert', '--skip'],
|
||||
// merge 没有 skip 语义:跳过等于放弃整个合并
|
||||
_ => <String>[],
|
||||
};
|
||||
if (args.isEmpty) {
|
||||
return GitCommandResult.error('当前操作不支持跳过');
|
||||
}
|
||||
return runGitCommand(args, workingDir: repoPath);
|
||||
}
|
||||
|
||||
/// 放弃被中断的操作
|
||||
Future<GitCommandResult> abortOperation(
|
||||
String repoPath,
|
||||
GitPendingOperation operation,
|
||||
) async {
|
||||
final args = switch (operation) {
|
||||
GitPendingOperation.rebase => ['rebase', '--abort'],
|
||||
GitPendingOperation.merge => ['merge', '--abort'],
|
||||
GitPendingOperation.cherryPick => ['cherry-pick', '--abort'],
|
||||
GitPendingOperation.revert => ['revert', '--abort'],
|
||||
GitPendingOperation.none => <String>[],
|
||||
};
|
||||
if (args.isEmpty) {
|
||||
return GitCommandResult.error('当前没有需要放弃的操作');
|
||||
}
|
||||
return runGitCommand(args, workingDir: repoPath);
|
||||
}
|
||||
|
||||
/// 检测「继续」后是否因提交为空而再次停下(需要用户选择 skip)
|
||||
bool isOperationStoppedForEmptyCommit(String stderr) {
|
||||
final t = stderr.toLowerCase();
|
||||
return t.contains('nothing to commit') ||
|
||||
t.contains('no changes') ||
|
||||
t.contains('patch is empty') ||
|
||||
t.contains('previous cherry-pick is now empty');
|
||||
}
|
||||
|
||||
// ---------------------------- 上游追踪与领先/落后 ----------------------------
|
||||
|
||||
/// 读取当前分支的上游追踪状态 (`git status -sb --porcelain=v2 --branch`)
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
/// 冲突块中的一段内容
|
||||
class GitConflictSegment {
|
||||
/// 在 [GitConflictBlock] 内的起始行号(0-based,含)
|
||||
final int startLine;
|
||||
|
||||
/// 结束行号(0-based,不含)
|
||||
final int endLine;
|
||||
|
||||
const GitConflictSegment({required this.startLine, required this.endLine});
|
||||
|
||||
/// 行数(可能为 0,表示这一段是空的)
|
||||
int get lineCount => endLine - startLine;
|
||||
}
|
||||
|
||||
/// 文件中的一个冲突块
|
||||
///
|
||||
/// 只记录**位置**,内容由调用方按行号自行取用(避免重复持有全文副本)。
|
||||
class GitConflictBlock {
|
||||
/// `<<<<<<<` 所在行号(0-based,含)
|
||||
final int startLine;
|
||||
|
||||
/// `>>>>>>>` 所在行号(0-based,含)
|
||||
final int endLine;
|
||||
|
||||
/// `<<<<<<<` 后标注的来源(rebase 下是**基线**侧,merge 下是当前分支)
|
||||
final String oursLabel;
|
||||
|
||||
/// `>>>>>>>` 后标注的来源
|
||||
final String theirsLabel;
|
||||
|
||||
final GitConflictSegment ours;
|
||||
final GitConflictSegment theirs;
|
||||
|
||||
/// 共同祖先段;仅 `merge.conflictStyle=diff3` 时存在
|
||||
final GitConflictSegment? base;
|
||||
|
||||
const GitConflictBlock({
|
||||
required this.startLine,
|
||||
required this.endLine,
|
||||
required this.oursLabel,
|
||||
required this.theirsLabel,
|
||||
required this.ours,
|
||||
required this.theirs,
|
||||
this.base,
|
||||
});
|
||||
|
||||
/// 是否为 diff3 风格(带基线段)
|
||||
bool get hasBaseSegment => base != null;
|
||||
|
||||
/// 该块跨越的总行数(含标记行),用于计算替换范围
|
||||
int get replacedLineCount => endLine - startLine + 1;
|
||||
}
|
||||
|
||||
/// 冲突标记解析结果
|
||||
class GitConflictParseResult {
|
||||
final List<GitConflictBlock> blocks;
|
||||
|
||||
/// 格式是否可疑(标记不成对、嵌套、顺序错乱)
|
||||
///
|
||||
/// 为真时**不要**对文件做任何自动替换:宁可退化成"手工编辑",
|
||||
/// 也不能按错误的位置改写用户的代码。
|
||||
final bool isMalformed;
|
||||
|
||||
/// 可疑原因,供 UI 提示
|
||||
final String? malformedReason;
|
||||
|
||||
const GitConflictParseResult({
|
||||
this.blocks = const [],
|
||||
this.isMalformed = false,
|
||||
this.malformedReason,
|
||||
});
|
||||
|
||||
bool get hasConflicts => blocks.isNotEmpty;
|
||||
|
||||
static const GitConflictParseResult none = GitConflictParseResult();
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'GitConflictParseResult(blocks=${blocks.length}, malformed=$isMalformed)';
|
||||
}
|
||||
|
||||
/// 解析文件中的 Git 冲突标记
|
||||
///
|
||||
/// 支持标准风格(`<<<<<<<` / `=======` / `>>>>>>>`)与 diff3 风格
|
||||
/// (额外含 `|||||||` 基线段)。
|
||||
///
|
||||
/// 关键设计:**只信任成对且顺序正确的标记**。文件正文里本来就可能出现
|
||||
/// 类似标记的文本(比如正在编辑这段解析代码本身),一旦结构可疑就整体
|
||||
/// 标记为 malformed,由调用方退化为手工编辑。
|
||||
class GitConflictParser {
|
||||
GitConflictParser._();
|
||||
|
||||
static const String _oursMarker = '<<<<<<<';
|
||||
static const String _baseMarker = '|||||||';
|
||||
static const String _separator = '=======';
|
||||
static const String _theirsMarker = '>>>>>>>';
|
||||
|
||||
static GitConflictParseResult parse(String content) {
|
||||
final lines = content.split('\n');
|
||||
final blocks = <GitConflictBlock>[];
|
||||
|
||||
int? blockStart;
|
||||
String oursLabel = '';
|
||||
String theirsLabel = '';
|
||||
int? oursStart;
|
||||
int? baseStart;
|
||||
int? theirsStart;
|
||||
int? sepLine;
|
||||
bool sawBase = false;
|
||||
|
||||
String? malformedReason;
|
||||
void markMalformed(String reason) {
|
||||
malformedReason ??= reason;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
blockStart = null;
|
||||
oursLabel = '';
|
||||
theirsLabel = '';
|
||||
oursStart = null;
|
||||
baseStart = null;
|
||||
theirsStart = null;
|
||||
sepLine = null;
|
||||
sawBase = false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
final line = lines[i];
|
||||
|
||||
if (line.startsWith(_oursMarker)) {
|
||||
if (blockStart != null) {
|
||||
// 上一个块还没结束就来了新的起始标记 → 嵌套,不可信任
|
||||
markMalformed('检测到嵌套的冲突标记,无法安全自动解析');
|
||||
}
|
||||
reset();
|
||||
blockStart = i;
|
||||
oursLabel = _labelOf(line, _oursMarker);
|
||||
oursStart = i + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (blockStart == null) continue;
|
||||
|
||||
if (line.startsWith(_baseMarker)) {
|
||||
sawBase = true;
|
||||
baseStart = i + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.startsWith(_separator)) {
|
||||
if (sepLine != null) {
|
||||
markMalformed('同一个冲突块内出现多个分隔线');
|
||||
}
|
||||
sepLine = i;
|
||||
theirsStart = i + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.startsWith(_theirsMarker)) {
|
||||
theirsLabel = _labelOf(line, _theirsMarker);
|
||||
final start = blockStart!;
|
||||
final sep = sepLine;
|
||||
final oursEnd = sawBase ? baseStart! - 1 : sep;
|
||||
|
||||
if (sep == null || oursEnd == null) {
|
||||
// 缺少分隔线 → 结构不完整
|
||||
markMalformed('冲突块缺少 ======= 分隔线');
|
||||
} else {
|
||||
blocks.add(GitConflictBlock(
|
||||
startLine: start,
|
||||
endLine: i,
|
||||
oursLabel: oursLabel,
|
||||
theirsLabel: theirsLabel,
|
||||
ours: GitConflictSegment(startLine: oursStart!, endLine: oursEnd),
|
||||
theirs: GitConflictSegment(startLine: theirsStart!, endLine: i),
|
||||
base: sawBase
|
||||
? GitConflictSegment(startLine: baseStart!, endLine: sep)
|
||||
: null,
|
||||
));
|
||||
}
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
// 走到文件末尾仍在块内 → 标记不成对
|
||||
if (blockStart != null) {
|
||||
markMalformed('冲突标记未闭合');
|
||||
}
|
||||
|
||||
if (malformedReason != null) {
|
||||
return GitConflictParseResult(
|
||||
blocks: const [],
|
||||
isMalformed: true,
|
||||
malformedReason: malformedReason,
|
||||
);
|
||||
}
|
||||
return GitConflictParseResult(blocks: List.unmodifiable(blocks));
|
||||
}
|
||||
|
||||
/// 快速判断文件里是否含冲突标记(不做完整解析,用于列表标注)
|
||||
static bool containsMarkers(String content) {
|
||||
return content.contains(_oursMarker) && content.contains(_theirsMarker);
|
||||
}
|
||||
|
||||
/// 取出标记行后面的来源标注(`<<<<<<< HEAD` → `HEAD`)
|
||||
static String _labelOf(String line, String marker) {
|
||||
return line.length > marker.length ? line.substring(marker.length).trim() : '';
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,9 @@ enum GitOperationErrorKind {
|
||||
/// 目标仓库不存在,或当前账号无权访问(HTTP 404)
|
||||
repositoryNotFound,
|
||||
|
||||
/// 本地路径型远端在容器内不存在(本地裸仓库/目录型 remote 的路径失效)
|
||||
localRemotePathMissing,
|
||||
|
||||
/// 需要代理认证(HTTP 407)
|
||||
proxyAuthRequired,
|
||||
|
||||
@@ -220,10 +223,19 @@ class GitErrorMapper {
|
||||
return const GitErrorInfo(kind: GitOperationErrorKind.requestRejected);
|
||||
}
|
||||
|
||||
// 2h. 仓库不存在 / 无权访问(HTTP 404 或 GitHub 文案)
|
||||
if (text.contains('repository not found') ||
|
||||
text.contains('does not appear to be a git repository') ||
|
||||
text.contains('404')) {
|
||||
// 2h. 本地路径型远端不存在(必须先于通用 404 判断)
|
||||
// 典型输出:`fatal: '/workspace/xxx.git' does not appear to be a git repository`
|
||||
// 这跟账号、令牌、GitHub 完全无关,归到"仓库不存在"会把用户带偏。
|
||||
if (text.contains('does not appear to be a git repository') ||
|
||||
text.contains('could not read from remote repository') ||
|
||||
RegExp(r"fatal: '.*' does not exist").hasMatch(text)) {
|
||||
return const GitErrorInfo(
|
||||
kind: GitOperationErrorKind.localRemotePathMissing,
|
||||
);
|
||||
}
|
||||
|
||||
// 2i. 仓库不存在 / 无权访问(HTTP 404 或 GitHub 文案)
|
||||
if (text.contains('repository not found') || text.contains('404')) {
|
||||
return const GitErrorInfo(
|
||||
kind: GitOperationErrorKind.repositoryNotFound,
|
||||
fixAction: GitErrorFixAction.openAccountManagement,
|
||||
@@ -417,6 +429,8 @@ extension GitOperationErrorKindL10n on GitOperationErrorKind {
|
||||
return l10n.gitErrWritePermissionDenied;
|
||||
case GitOperationErrorKind.repositoryNotFound:
|
||||
return l10n.gitErrRepositoryNotFound;
|
||||
case GitOperationErrorKind.localRemotePathMissing:
|
||||
return l10n.gitErrLocalRemoteMissing;
|
||||
case GitOperationErrorKind.proxyAuthRequired:
|
||||
return l10n.gitErrProxyAuthRequired;
|
||||
case GitOperationErrorKind.requestRejected:
|
||||
@@ -469,6 +483,8 @@ extension GitOperationErrorKindL10n on GitOperationErrorKind {
|
||||
return l10n.gitErrWritePermissionDeniedHint;
|
||||
case GitOperationErrorKind.repositoryNotFound:
|
||||
return l10n.gitErrRepositoryNotFoundHint;
|
||||
case GitOperationErrorKind.localRemotePathMissing:
|
||||
return l10n.gitErrLocalRemoteMissingHint;
|
||||
case GitOperationErrorKind.proxyAuthRequired:
|
||||
return l10n.gitErrProxyAuthRequiredHint;
|
||||
case GitOperationErrorKind.requestRejected:
|
||||
|
||||
@@ -0,0 +1,533 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../../models/git_model.dart';
|
||||
import '../../providers/git_provider.dart';
|
||||
import '../../providers/tab_provider.dart';
|
||||
import '../../utils/dialog_utils.dart';
|
||||
import '../../utils/git_error_mapper.dart';
|
||||
|
||||
/// 冲突解决面板(底部弹出)
|
||||
///
|
||||
/// 设计要点:
|
||||
/// 1. 解决冲突的本质就是「改文件 + `git add`」,因此打开文件一律**强制从磁盘
|
||||
/// 重载**(Git 在冲突时直接改写了工作区文件并写入标记)。
|
||||
/// 2. `--ours/--theirs` 在 rebase 下含义与直觉相反,因此按钮文案按**实际操作
|
||||
/// 类型**翻译,绝不写「我的 / 对方的」。
|
||||
/// 3. 「继续」在仍有未解决文件时禁用,避免 git 立刻再次停下造成误解。
|
||||
class GitConflictPanel extends StatelessWidget {
|
||||
const GitConflictPanel({super.key});
|
||||
|
||||
static Future<void> show(BuildContext context) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: true,
|
||||
builder: (_) => const GitConflictPanel(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final provider = context.watch<GitProvider>();
|
||||
final state = provider.conflictState;
|
||||
|
||||
if (!state.isPending) {
|
||||
// 面板打开期间操作已完成(例如用户点了继续)→ 自动关闭
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (context.mounted) Navigator.of(context).maybePop();
|
||||
});
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final baselineLabel = _baselineLabel(provider, l10n);
|
||||
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 12,
|
||||
right: 12,
|
||||
bottom: 12 + MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.merge_type,
|
||||
size: 18,
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
l10n.gitConflictTitle,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_operationLabel(l10n, state.operation),
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// 状态条:未解决 / 可继续
|
||||
_buildStatusBar(theme, l10n, provider),
|
||||
|
||||
// 「提交为空」提示:明确告诉用户可以跳过,而不是让用户猜
|
||||
if (provider.conflictNotice == 'emptyCommit') ...[
|
||||
const SizedBox(height: 6),
|
||||
_buildEmptyCommitHint(theme, l10n, provider),
|
||||
],
|
||||
|
||||
const SizedBox(height: 8),
|
||||
if (state.files.isNotEmpty)
|
||||
Flexible(
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
itemCount: state.files.length,
|
||||
separatorBuilder: (_, _) => const Divider(height: 1),
|
||||
itemBuilder: (ctx, index) => _ConflictFileTile(
|
||||
file: state.files[index],
|
||||
baselineLabel: baselineLabel,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 10),
|
||||
_buildActions(context, theme, l10n, provider),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 基线侧的名称 —— 用实际来源代替「我的/对方的」,避免 rebase 下误导
|
||||
String _baselineLabel(GitProvider provider, AppLocalizations l10n) {
|
||||
final upstream = provider.tracking?.upstream;
|
||||
if (upstream != null && upstream.isNotEmpty) return upstream;
|
||||
return l10n.gitConflictTakeBaselineGeneric;
|
||||
}
|
||||
|
||||
String _operationLabel(AppLocalizations l10n, GitPendingOperation op) {
|
||||
return switch (op) {
|
||||
GitPendingOperation.rebase => l10n.gitConflictRebaseInProgress,
|
||||
GitPendingOperation.merge => l10n.gitConflictMergeInProgress,
|
||||
GitPendingOperation.cherryPick => l10n.gitConflictCherryPickInProgress,
|
||||
GitPendingOperation.revert => l10n.gitConflictRevertInProgress,
|
||||
GitPendingOperation.none => '',
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildStatusBar(
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider,
|
||||
) {
|
||||
final remaining = provider.conflictState.conflictCount;
|
||||
final done = remaining == 0;
|
||||
final colorScheme = theme.colorScheme;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: done
|
||||
? colorScheme.primaryContainer.withValues(alpha: 0.5)
|
||||
: colorScheme.errorContainer.withValues(alpha: 0.5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
done ? Icons.check_circle_outline : Icons.error_outline,
|
||||
size: 16,
|
||||
color: done
|
||||
? colorScheme.onPrimaryContainer
|
||||
: colorScheme.onErrorContainer,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
done
|
||||
? l10n.gitConflictAllResolved
|
||||
: l10n.gitConflictRemaining(remaining),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: done
|
||||
? colorScheme.onPrimaryContainer
|
||||
: colorScheme.onErrorContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyCommitHint(
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.tertiaryContainer.withValues(alpha: 0.5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 15,
|
||||
color: theme.colorScheme.onTertiaryContainer,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.gitConflictEmptyCommitNotice,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: theme.colorScheme.onTertiaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: provider.clearConflictNotice,
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
size: 14,
|
||||
color: theme.colorScheme.onTertiaryContainer,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActions(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider,
|
||||
) {
|
||||
final state = provider.conflictState;
|
||||
final canContinue = state.canContinue;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
// 放弃:始终可用
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
key: const ValueKey('git_conflict_abort_button'),
|
||||
onPressed: () => _abort(context, l10n, provider),
|
||||
icon: const Icon(Icons.undo, size: 15),
|
||||
label: Text(
|
||||
l10n.gitConflictAbort,
|
||||
style: const TextStyle(fontSize: 11.5),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
// 跳过:仅 rebase / cherry-pick / revert 有意义
|
||||
if (state.operation != GitPendingOperation.merge)
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
key: const ValueKey('git_conflict_skip_button'),
|
||||
onPressed: () => _skip(context, l10n, provider),
|
||||
icon: const Icon(Icons.skip_next, size: 15),
|
||||
label: Text(
|
||||
l10n.gitConflictSkip,
|
||||
style: const TextStyle(fontSize: 11.5),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
// 继续:仍有未解决文件时禁用
|
||||
Expanded(
|
||||
child: FilledButton.icon(
|
||||
key: const ValueKey('git_conflict_continue_button'),
|
||||
onPressed: canContinue ? () => _continue(context, l10n, provider) : null,
|
||||
icon: const Icon(Icons.play_arrow, size: 15),
|
||||
label: Text(
|
||||
l10n.gitConflictContinue,
|
||||
style: const TextStyle(fontSize: 11.5),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _continue(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider,
|
||||
) async {
|
||||
final res = await provider.continueOperation();
|
||||
if (!context.mounted) return;
|
||||
if (res.success) {
|
||||
DialogUtils.showToast(context, l10n.gitConflictContinueSuccess, type: ToastType.success);
|
||||
} else if (provider.conflictNotice != 'emptyCommit') {
|
||||
// 失败原因优先用结构化错误;无结构化错误时退回原文
|
||||
final err = provider.lastRemoteError;
|
||||
DialogUtils.showToast(
|
||||
context,
|
||||
err != null ? err.kind.message(l10n) : res.stderr,
|
||||
type: ToastType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _skip(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider,
|
||||
) async {
|
||||
final res = await provider.skipOperation();
|
||||
if (!context.mounted) return;
|
||||
DialogUtils.showToast(
|
||||
context,
|
||||
res.success ? l10n.gitConflictSkipSuccess : res.stderr,
|
||||
type: res.success ? ToastType.success : ToastType.error,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _abort(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider,
|
||||
) async {
|
||||
final confirmed = await DialogUtils.showDestructiveConfirmDialog(
|
||||
context,
|
||||
title: l10n.gitConflictAbort,
|
||||
message: l10n.gitConflictAbortConfirm,
|
||||
confirmText: l10n.gitConflictAbort,
|
||||
icon: Icons.undo,
|
||||
);
|
||||
if (!confirmed || !context.mounted) return;
|
||||
|
||||
final res = await provider.abortOperation();
|
||||
if (!context.mounted) return;
|
||||
DialogUtils.showToast(
|
||||
context,
|
||||
res.success ? l10n.gitConflictAbortSuccess : res.stderr,
|
||||
type: res.success ? ToastType.success : ToastType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 单个冲突文件条目
|
||||
class _ConflictFileTile extends StatelessWidget {
|
||||
const _ConflictFileTile({required this.file, required this.baselineLabel});
|
||||
|
||||
final GitConflictedFile file;
|
||||
final String baselineLabel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final provider = context.watch<GitProvider>();
|
||||
final colorScheme = theme.colorScheme;
|
||||
|
||||
return ListTile(
|
||||
key: ValueKey('git_conflict_file_${file.relativePath}'),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
leading: Icon(
|
||||
file.isBinary ? Icons.data_object : Icons.description_outlined,
|
||||
size: 18,
|
||||
color: colorScheme.error,
|
||||
),
|
||||
title: Text(
|
||||
file.relativePath,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12.5, fontFamily: 'JetBrains Mono'),
|
||||
),
|
||||
subtitle: Text(
|
||||
_typeLabel(l10n, file.type),
|
||||
style: TextStyle(fontSize: 10.5, color: colorScheme.onSurfaceVariant),
|
||||
),
|
||||
trailing: PopupMenuButton<String>(
|
||||
key: ValueKey('git_conflict_actions_${file.relativePath}'),
|
||||
tooltip: l10n.gitConflictTitle,
|
||||
onSelected: (action) => _handle(context, l10n, provider, action),
|
||||
itemBuilder: (_) => [
|
||||
if (file.canEditManually)
|
||||
PopupMenuItem(
|
||||
value: 'open',
|
||||
child: _menuRow(Icons.open_in_new_rounded, l10n.gitConflictOpenFile),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'ours',
|
||||
child: _menuRow(
|
||||
Icons.arrow_downward_rounded,
|
||||
l10n.gitConflictTakeBaseline(baselineLabel),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'theirs',
|
||||
child: _menuRow(
|
||||
Icons.arrow_upward_rounded,
|
||||
l10n.gitConflictTakeIncoming,
|
||||
),
|
||||
),
|
||||
if (file.canEditManually)
|
||||
PopupMenuItem(
|
||||
value: 'recreate',
|
||||
child: _menuRow(Icons.refresh, l10n.gitConflictRecreate),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'resolved',
|
||||
child: _menuRow(Icons.check, l10n.gitConflictContinue),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem(
|
||||
value: 'remove',
|
||||
child: _menuRow(Icons.delete_outline, l10n.gitConflictRemoveFile),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: file.canEditManually
|
||||
? () => _handle(context, l10n, provider, 'open')
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _menuRow(IconData icon, String label) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 16),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 12.5),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _typeLabel(AppLocalizations l10n, GitConflictType type) {
|
||||
return switch (type) {
|
||||
GitConflictType.bothModified => l10n.gitConflictTypeBothModified,
|
||||
GitConflictType.bothAdded => l10n.gitConflictTypeBothAdded,
|
||||
GitConflictType.deletedByUs => l10n.gitConflictTypeDeletedByUs,
|
||||
GitConflictType.deletedByThem => l10n.gitConflictTypeDeletedByThem,
|
||||
GitConflictType.addedByUs => l10n.gitConflictTypeAddedByUs,
|
||||
GitConflictType.addedByThem => l10n.gitConflictTypeAddedByThem,
|
||||
GitConflictType.bothDeleted => l10n.gitConflictTypeBothDeleted,
|
||||
GitConflictType.unknown => l10n.gitConflictTypeUnknown,
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> _handle(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider,
|
||||
String action,
|
||||
) async {
|
||||
switch (action) {
|
||||
case 'open':
|
||||
await _openInEditor(context, provider);
|
||||
break;
|
||||
case 'ours':
|
||||
await _takeSide(context, l10n, provider, useOurs: true);
|
||||
break;
|
||||
case 'theirs':
|
||||
await _takeSide(context, l10n, provider, useOurs: false);
|
||||
break;
|
||||
case 'recreate':
|
||||
final res = await provider.recreateConflictMarkers(file);
|
||||
if (!context.mounted) return;
|
||||
DialogUtils.showToast(
|
||||
context,
|
||||
res.success ? l10n.gitConflictRecreateDone : res.stderr,
|
||||
type: res.success ? ToastType.success : ToastType.error,
|
||||
);
|
||||
break;
|
||||
case 'resolved':
|
||||
final res = await provider.markConflictResolved(file);
|
||||
if (!context.mounted) return;
|
||||
DialogUtils.showToast(
|
||||
context,
|
||||
res.success
|
||||
? l10n.gitConflictResolved(file.relativePath)
|
||||
: res.stderr,
|
||||
type: res.success ? ToastType.success : ToastType.error,
|
||||
);
|
||||
break;
|
||||
case 'remove':
|
||||
final confirmed = await DialogUtils.showDestructiveConfirmDialog(
|
||||
context,
|
||||
title: l10n.gitConflictRemoveFile,
|
||||
message: file.relativePath,
|
||||
icon: Icons.delete_outline,
|
||||
);
|
||||
if (!confirmed || !context.mounted) return;
|
||||
await provider.removeConflictedFile(file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// 在编辑器中打开冲突文件
|
||||
///
|
||||
/// **必须先强制从磁盘重载**:Git 冲突时直接改写了工作区文件并写入标记,
|
||||
/// 而 openFile 对已打开的 tab 不会重载,用户会看到没有标记的旧内容。
|
||||
Future<void> _openInEditor(BuildContext context, GitProvider provider) async {
|
||||
final tabProvider = context.read<TabProvider>();
|
||||
await provider.refreshConflictState();
|
||||
await tabProvider.reloadTabFromDisk(file.absolutePath);
|
||||
await tabProvider.openFile(file.absolutePath);
|
||||
if (context.mounted) {
|
||||
// 关闭面板并退出抽屉,把焦点交给编辑器
|
||||
Navigator.of(context).maybePop();
|
||||
Navigator.of(context).maybePop();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _takeSide(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider, {
|
||||
required bool useOurs,
|
||||
}) async {
|
||||
final res = await provider.takeConflictSide(file, useOurs: useOurs);
|
||||
if (!context.mounted) return;
|
||||
DialogUtils.showToast(
|
||||
context,
|
||||
res.success ? l10n.gitConflictResolved(file.relativePath) : res.stderr,
|
||||
type: res.success ? ToastType.success : ToastType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import '../../providers/project_provider.dart';
|
||||
import '../../providers/tab_provider.dart';
|
||||
import '../../utils/dialog_utils.dart';
|
||||
import '../../utils/file_icon_utils.dart';
|
||||
import 'git_conflict_panel.dart';
|
||||
import 'git_diff_page.dart';
|
||||
import 'git_graph_painter.dart';
|
||||
import 'git_remote_management_sheet.dart';
|
||||
@@ -579,9 +580,29 @@ class _GitPanelWidgetState extends State<GitPanelWidget> {
|
||||
case 'force_push':
|
||||
_handleForcePush(context, l10n, gitProvider);
|
||||
break;
|
||||
case 'resolve_conflict':
|
||||
GitConflictPanel.show(context);
|
||||
break;
|
||||
}
|
||||
},
|
||||
itemBuilder: (ctx) => [
|
||||
// 冲突时置顶:此时其它操作基本都无法推进,必须先解决它
|
||||
if (gitProvider.hasPendingOperation) ...[
|
||||
PopupMenuItem(
|
||||
value: 'resolve_conflict',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.merge_type, size: 16, color: theme.colorScheme.error),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
l10n.gitConflictTitle,
|
||||
style: TextStyle(fontSize: 13, color: theme.colorScheme.error),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
],
|
||||
if (gitProvider.hasRepository) ...[
|
||||
PopupMenuItem(
|
||||
value: 'undo_commit',
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../../providers/git_provider.dart';
|
||||
import '../../utils/dialog_utils.dart';
|
||||
import '../../utils/git_error_mapper.dart';
|
||||
import '../../views/git_account_management_view.dart';
|
||||
import 'git_conflict_panel.dart';
|
||||
import 'git_remote_management_sheet.dart';
|
||||
|
||||
/// Git 云端同步工具条
|
||||
@@ -97,6 +98,11 @@ class _GitSyncBarState extends State<GitSyncBar> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 冲突优先于一切:此时同步动作都无法继续,必须先把冲突摆到最前面
|
||||
if (gitProvider.hasPendingOperation) ...[
|
||||
_buildConflictBanner(context, theme, l10n, gitProvider),
|
||||
const SizedBox(height: 6),
|
||||
],
|
||||
// 与上方「分支」行完全一致的结构:左侧占满的选择条 + 右侧 32×32 图标按钮。
|
||||
// 这样三行(分支 / 远程 / 进度)视觉对齐,宽度也天然不会溢出。
|
||||
Row(
|
||||
@@ -177,6 +183,65 @@ class _GitSyncBarState extends State<GitSyncBar> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 冲突横幅:把用户直接引到冲突解决面板
|
||||
///
|
||||
/// 冲突时 push/pull 都无法推进,所以它必须排在远程行之前,
|
||||
/// 而不是和错误面板一起挤在下面。
|
||||
Widget _buildConflictBanner(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
GitProvider provider,
|
||||
) {
|
||||
final colorScheme = theme.colorScheme;
|
||||
final remaining = provider.conflictState.conflictCount;
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
key: const ValueKey('git_conflict_banner'),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
onTap: () => GitConflictPanel.show(context),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.errorContainer.withValues(alpha: 0.6),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(
|
||||
color: colorScheme.error.withValues(alpha: 0.5),
|
||||
width: 0.8,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.merge_type, size: 15, color: colorScheme.error),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
remaining > 0
|
||||
? l10n.gitConflictRemaining(remaining)
|
||||
: l10n.gitConflictAllResolved,
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colorScheme.onErrorContainer,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
size: 16,
|
||||
color: colorScheme.onErrorContainer,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 远程仓库选择条(样式与「分支」条保持一致,点击切换推送目标)
|
||||
Widget _buildRemoteSelectorBar(
|
||||
BuildContext context,
|
||||
|
||||
Reference in new issue
Block a user