mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
chore: upgrade git-sync
This commit is contained in:
parent
056bc2706c
commit
3a5532b8b9
5 changed files with 2335 additions and 810 deletions
3077
package-lock.json
generated
3077
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -26,7 +26,7 @@
|
|||
"author": "Lin Onetwo <linonetwo012@gmail.com>, Quang Lam <quang.lam2807@gmail.com>",
|
||||
"main": ".webpack/main",
|
||||
"dependencies": {
|
||||
"@tiddlygit/tiddlywiki": "5.2.2-prerelease-2021-12-10",
|
||||
"@tiddlygit/tiddlywiki": "5.2.2-prerelease-2022-01-28",
|
||||
"app-path": "^3.3.0",
|
||||
"best-effort-json-parser": "0.1.1",
|
||||
"bluebird": "3.7.2",
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
"electron-window-state": "5.0.3",
|
||||
"errio": "1.2.2",
|
||||
"fs-extra": "10.0.0",
|
||||
"git-sync-js": "^0.6.0",
|
||||
"git-sync-js": "1.0.1",
|
||||
"i18next": "21.3.3",
|
||||
"i18next-electron-fs-backend": "2.0.0",
|
||||
"i18next-fs-backend": "1.1.1",
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ export const defaultGitInfo = {
|
|||
email: 'tiddlygit@gmail.com',
|
||||
gitUserName: 'tidgi',
|
||||
branch: 'main',
|
||||
remote: 'origin',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,29 +2,55 @@
|
|||
import 'source-map-support/register';
|
||||
import { expose } from 'threads/worker';
|
||||
import { Observable } from 'rxjs';
|
||||
import { clone, commitAndSync, GitStep, ILoggerContext, initGit, getModifiedFileList, getRemoteUrl } from 'git-sync-js';
|
||||
import { clone, commitAndSync, GitStep, ILoggerContext, initGit, getModifiedFileList, getRemoteUrl, SyncParameterMissingError } from 'git-sync-js';
|
||||
import { IGitLogMessage, IGitUserInfos } from './interface';
|
||||
import { defaultGitInfo } from './defaultGitInfo';
|
||||
import { WikiChannel } from '@/constants/channels';
|
||||
|
||||
function initWikiGit(wikiFolderPath: string, syncImmediately?: boolean, remoteUrl?: string, userInfo?: IGitUserInfos): Observable<IGitLogMessage> {
|
||||
return new Observable<IGitLogMessage>((observer) => {
|
||||
void initGit({
|
||||
dir: wikiFolderPath,
|
||||
remoteUrl,
|
||||
syncImmediately,
|
||||
userInfo,
|
||||
defaultGitInfo,
|
||||
logger: {
|
||||
debug: (message: string, context: ILoggerContext): unknown =>
|
||||
observer.next({ message, level: 'debug', meta: { callerFunction: 'initWikiGit', ...context } }),
|
||||
warn: (message: string, context: ILoggerContext): unknown =>
|
||||
observer.next({ message, level: 'warn', meta: { callerFunction: 'initWikiGit', ...context } }),
|
||||
info: (message: GitStep, context: ILoggerContext): void => {
|
||||
observer.next({ message, level: 'notice', meta: { handler: WikiChannel.createProgress, callerFunction: 'initWikiGit', ...context } });
|
||||
let task: Promise<void>;
|
||||
if (syncImmediately) {
|
||||
if (remoteUrl === undefined) {
|
||||
throw new SyncParameterMissingError('remoteUrl');
|
||||
}
|
||||
if (userInfo === undefined) {
|
||||
throw new SyncParameterMissingError('userInfo');
|
||||
}
|
||||
task = initGit({
|
||||
dir: wikiFolderPath,
|
||||
remoteUrl,
|
||||
syncImmediately,
|
||||
userInfo,
|
||||
defaultGitInfo,
|
||||
logger: {
|
||||
debug: (message: string, context: ILoggerContext): unknown =>
|
||||
observer.next({ message, level: 'debug', meta: { callerFunction: 'initWikiGit', ...context } }),
|
||||
warn: (message: string, context: ILoggerContext): unknown =>
|
||||
observer.next({ message, level: 'warn', meta: { callerFunction: 'initWikiGit', ...context } }),
|
||||
info: (message: GitStep, context: ILoggerContext): void => {
|
||||
observer.next({ message, level: 'notice', meta: { handler: WikiChannel.createProgress, callerFunction: 'initWikiGit', ...context } });
|
||||
},
|
||||
},
|
||||
},
|
||||
}).then(
|
||||
});
|
||||
} else {
|
||||
task = initGit({
|
||||
dir: wikiFolderPath,
|
||||
syncImmediately,
|
||||
userInfo,
|
||||
defaultGitInfo,
|
||||
logger: {
|
||||
debug: (message: string, context: ILoggerContext): unknown =>
|
||||
observer.next({ message, level: 'debug', meta: { callerFunction: 'initWikiGit', ...context } }),
|
||||
warn: (message: string, context: ILoggerContext): unknown =>
|
||||
observer.next({ message, level: 'warn', meta: { callerFunction: 'initWikiGit', ...context } }),
|
||||
info: (message: GitStep, context: ILoggerContext): void => {
|
||||
observer.next({ message, level: 'notice', meta: { handler: WikiChannel.createProgress, callerFunction: 'initWikiGit', ...context } });
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
void task.then(
|
||||
() => observer.complete(),
|
||||
(error) => observer.error(error),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import { LOCAL_GIT_DIRECTORY } from '@/constants/appPaths';
|
|||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import { lazyInject } from '@services/container';
|
||||
import { githubDesktopUrl } from '@/constants/urls';
|
||||
import { defaultGitInfo } from './defaultGitInfo';
|
||||
|
||||
@injectable()
|
||||
export class Git implements IGitService {
|
||||
|
|
@ -60,7 +61,7 @@ export class Git implements IGitService {
|
|||
|
||||
public async getWorkspacesRemote(wikiFolderPath: string): Promise<string | undefined> {
|
||||
if (await hasGit(wikiFolderPath)) {
|
||||
return await this.gitWorker?.getRemoteUrl(wikiFolderPath);
|
||||
return await this.gitWorker?.getRemoteUrl(wikiFolderPath, defaultGitInfo.remote);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +197,7 @@ export class Git implements IGitService {
|
|||
if (error instanceof AssumeSyncError) {
|
||||
error.message = i18n.t('Log.SynchronizationFailed');
|
||||
} else if (error instanceof SyncParameterMissingError) {
|
||||
error.message = i18n.t('Log.GitTokenMissing') + error.parameterName;
|
||||
error.message = i18n.t('Log.GitTokenMissing') + (error as SyncParameterMissingError).parameterName;
|
||||
} else if (error instanceof GitPullPushError) {
|
||||
error.message = i18n.t('Log.SyncFailedSystemError');
|
||||
} else if (error instanceof CantSyncGitNotInitializedError) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue