git-sync-js 0.4.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/src/clone.d.ts +13 -0
- package/dist/src/clone.d.ts.map +1 -0
- package/dist/src/clone.js +55 -0
- package/dist/src/clone.js.map +1 -0
- package/dist/src/commitAndSync.d.ts +21 -0
- package/dist/src/commitAndSync.d.ts.map +1 -0
- package/dist/src/commitAndSync.js +143 -0
- package/dist/src/commitAndSync.js.map +1 -0
- package/dist/{credential.d.ts → src/credential.d.ts} +3 -2
- package/dist/src/credential.d.ts.map +1 -0
- package/dist/{credential.js → src/credential.js} +7 -7
- package/dist/src/credential.js.map +1 -0
- package/dist/{defaultGitInfo.d.ts → src/defaultGitInfo.d.ts} +2 -0
- package/dist/src/defaultGitInfo.d.ts.map +1 -0
- package/dist/{defaultGitInfo.js → src/defaultGitInfo.js} +2 -0
- package/dist/src/defaultGitInfo.js.map +1 -0
- package/dist/{errors.d.ts → src/errors.d.ts} +5 -1
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/{errors.js → src/errors.js} +5 -5
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/init.d.ts +25 -0
- package/dist/src/init.d.ts.map +1 -0
- package/dist/src/init.js +22 -0
- package/dist/src/init.js.map +1 -0
- package/dist/src/initGit.d.ts +26 -0
- package/dist/src/initGit.d.ts.map +1 -0
- package/dist/src/initGit.js +40 -0
- package/dist/src/initGit.js.map +1 -0
- package/dist/{inspect.d.ts → src/inspect.d.ts} +20 -7
- package/dist/src/inspect.d.ts.map +1 -0
- package/dist/{inspect.js → src/inspect.js} +100 -49
- package/dist/src/inspect.js.map +1 -0
- package/dist/{interface.d.ts → src/interface.d.ts} +8 -1
- package/dist/src/interface.d.ts.map +1 -0
- package/dist/{interface.js → src/interface.js} +5 -0
- package/dist/src/interface.js.map +1 -0
- package/dist/{sync.d.ts → src/sync.d.ts} +18 -1
- package/dist/src/sync.d.ts.map +1 -0
- package/dist/{sync.js → src/sync.js} +57 -4
- package/dist/src/sync.js.map +1 -0
- package/dist/src/utils.d.ts +3 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +3 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/test/clone.test.d.ts +2 -0
- package/dist/test/clone.test.d.ts.map +1 -0
- package/dist/test/clone.test.js +42 -0
- package/dist/test/clone.test.js.map +1 -0
- package/dist/test/commitAndSync.test.d.ts +2 -0
- package/dist/test/commitAndSync.test.d.ts.map +1 -0
- package/dist/test/commitAndSync.test.js +27 -0
- package/dist/test/commitAndSync.test.js.map +1 -0
- package/dist/test/constants.d.ts +23 -0
- package/dist/test/constants.d.ts.map +1 -0
- package/dist/test/constants.js +51 -0
- package/dist/test/constants.js.map +1 -0
- package/dist/test/constants.test.d.ts +2 -0
- package/dist/test/constants.test.d.ts.map +1 -0
- package/dist/test/constants.test.js +7 -0
- package/dist/test/constants.test.js.map +1 -0
- package/dist/test/initGit.test.d.ts +2 -0
- package/dist/test/initGit.test.d.ts.map +1 -0
- package/dist/test/initGit.test.js +90 -0
- package/dist/test/initGit.test.js.map +1 -0
- package/dist/test/inspect.test.d.ts +2 -0
- package/dist/test/inspect.test.d.ts.map +1 -0
- package/dist/test/inspect.test.js +224 -0
- package/dist/test/inspect.test.js.map +1 -0
- package/dist/test/jest.setup.d.ts +2 -0
- package/dist/test/jest.setup.d.ts.map +1 -0
- package/dist/test/jest.setup.js +30 -0
- package/dist/test/jest.setup.js.map +1 -0
- package/dist/test/sync.test.d.ts +2 -0
- package/dist/test/sync.test.d.ts.map +1 -0
- package/dist/test/sync.test.js +75 -0
- package/dist/test/sync.test.js.map +1 -0
- package/dist/test/utils.d.ts +5 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +38 -0
- package/dist/test/utils.js.map +1 -0
- package/package.json +24 -17
- package/dist/credential.d.ts.map +0 -1
- package/dist/credential.js.map +0 -1
- package/dist/defaultGitInfo.d.ts.map +0 -1
- package/dist/defaultGitInfo.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts +0 -46
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -234
- package/dist/index.js.map +0 -1
- package/dist/inspect.d.ts.map +0 -1
- package/dist/inspect.js.map +0 -1
- package/dist/interface.d.ts.map +0 -1
- package/dist/interface.js.map +0 -1
- package/dist/sync.d.ts.map +0 -1
- package/dist/sync.js.map +0 -1
|
@@ -14,7 +14,7 @@ export declare function getModifiedFileList(wikiFolderPath: string): Promise<Mod
|
|
|
14
14
|
* @param dir wiki folder path, git folder to inspect
|
|
15
15
|
* @returns remote url, without `'.git'`
|
|
16
16
|
*/
|
|
17
|
-
export declare function getRemoteUrl(dir: string): Promise<string>;
|
|
17
|
+
export declare function getRemoteUrl(dir: string, remoteName: string): Promise<string>;
|
|
18
18
|
/**
|
|
19
19
|
* get the Github Repo Name, similar to "linonetwo/wiki", string after "https://github.com/"
|
|
20
20
|
* @param remoteUrl full github repository url or other repository url
|
|
@@ -28,17 +28,19 @@ export declare function getRemoteRepoName(remoteUrl: string): string | undefined
|
|
|
28
28
|
export declare function haveLocalChanges(wikiFolderPath: string): Promise<boolean>;
|
|
29
29
|
/**
|
|
30
30
|
* Get "master" or "main" from git repo
|
|
31
|
+
*
|
|
32
|
+
* https://github.com/simonthum/git-sync/blob/31cc140df2751e09fae2941054d5b61c34e8b649/git-sync#L228-L232
|
|
31
33
|
* @param wikiFolderPath
|
|
32
34
|
*/
|
|
33
|
-
export declare function getDefaultBranchName(wikiFolderPath: string): Promise<string>;
|
|
34
|
-
export declare type SyncState = '
|
|
35
|
+
export declare function getDefaultBranchName(wikiFolderPath: string): Promise<string | undefined>;
|
|
36
|
+
export declare type SyncState = 'noUpstreamOrBareUpstream' | 'equal' | 'ahead' | 'behind' | 'diverged';
|
|
35
37
|
/**
|
|
36
38
|
* determine sync state of repository, i.e. how the remote relates to our HEAD
|
|
37
39
|
* 'ahead' means our local state is ahead of remote, 'behind' means local state is behind of the remote
|
|
38
40
|
* @param dir repo path to test
|
|
39
41
|
*/
|
|
40
|
-
export declare function getSyncState(dir: string,
|
|
41
|
-
export declare function assumeSync(wikiFolderPath: string,
|
|
42
|
+
export declare function getSyncState(dir: string, defaultBranchName: string, remoteName: string, logger?: ILogger): Promise<SyncState>;
|
|
43
|
+
export declare function assumeSync(wikiFolderPath: string, defaultBranchName: string, remoteName: string, logger?: ILogger): Promise<void>;
|
|
42
44
|
/**
|
|
43
45
|
* get various repo state in string format
|
|
44
46
|
* @param wikiFolderPath repo path to check
|
|
@@ -51,6 +53,17 @@ export declare function getGitRepositoryState(wikiFolderPath: string, logger?: I
|
|
|
51
53
|
* @param dir repo path
|
|
52
54
|
*/
|
|
53
55
|
export declare function getGitDirectory(dir: string, logger?: ILogger): Promise<string>;
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Check if dir has `.git`.
|
|
58
|
+
* @param dir folder that may contains a git
|
|
59
|
+
* @param strict if is true, then dir should be the root of the git repo. Default is true
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
export declare function hasGit(dir: string, strict?: boolean): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* get things like "origin"
|
|
65
|
+
*
|
|
66
|
+
* https://github.com/simonthum/git-sync/blob/31cc140df2751e09fae2941054d5b61c34e8b649/git-sync#L238-L257
|
|
67
|
+
*/
|
|
68
|
+
export declare function getRemoteName(dir: string, branch: string): Promise<string>;
|
|
56
69
|
//# sourceMappingURL=inspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../../src/inspect.ts"],"names":[],"mappings":"AAQA,OAAO,EAAW,OAAO,E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;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBpF;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAYzE;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAchF"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
1
2
|
/* eslint-disable unicorn/prevent-abbreviations */
|
|
2
3
|
import fs from 'fs-extra';
|
|
3
4
|
import path from 'path';
|
|
4
|
-
import
|
|
5
|
+
import { listRemotes } from 'isomorphic-git';
|
|
5
6
|
import { compact } from 'lodash';
|
|
6
7
|
import { GitProcess } from 'dugite';
|
|
7
8
|
import url from 'url';
|
|
8
9
|
import { GitStep } from './interface';
|
|
9
10
|
import { AssumeSyncError, CantSyncGitNotInitializedError } from './errors';
|
|
11
|
+
const gitEscapeToEncodedUri = (str) => str.replace(/\\(\d{3})/g, (_, $1) => `%${Number.parseInt($1, 8).toString(16)}`);
|
|
12
|
+
const decodeGitEscape = (rawString) => decodeURIComponent(gitEscapeToEncodedUri(rawString));
|
|
10
13
|
/**
|
|
11
14
|
* Get modified files and modify type in a folder
|
|
12
15
|
* @param {string} wikiFolderPath location to scan git modify state
|
|
@@ -16,7 +19,8 @@ export async function getModifiedFileList(wikiFolderPath) {
|
|
|
16
19
|
const stdoutLines = stdout.split('\n');
|
|
17
20
|
const nonEmptyLines = compact(stdoutLines);
|
|
18
21
|
const statusMatrixLines = compact(nonEmptyLines.map((line) => /^\s?(\?\?|[ACMR]|[ACMR][DM])\s?(\S+.*\S+)$/.exec(line))).filter(([_, type, fileRelativePath]) => type !== undefined && fileRelativePath !== undefined);
|
|
19
|
-
return statusMatrixLines
|
|
22
|
+
return statusMatrixLines
|
|
23
|
+
.map(([_, type, rawFileRelativePath]) => {
|
|
20
24
|
/**
|
|
21
25
|
* If filename contains Chinese, it will becomes:
|
|
22
26
|
* ```js
|
|
@@ -30,29 +34,30 @@ export async function getModifiedFileList(wikiFolderPath) {
|
|
|
30
34
|
*
|
|
31
35
|
* So simply `decodeURIComponent(escape` will work on `tiddlers/\346\226\260\346\235\241\347\233\256.tid` (the logged string), but not on `tiddlers/\\346\\226\\260\\346\\235\\241\\347\\233\\256.tid` (the actual string).
|
|
32
36
|
* So how to transform actual string to logged string? Answer is `eval()` it. But we have to check is there any evil script use `;` or `,` mixed into the filename.
|
|
37
|
+
*
|
|
38
|
+
* But actually those 346 226 are in radix 8 , if we transform it to radix 16 and add prefix % we can make it uri component.
|
|
39
|
+
* And it should not be parsed in groups of three, because only the CJK between 0x0800 - 0xffff are encoded into three bytes; so we should just replace all the \\\d{3} with hexadecimal, and then give it to the decodeURIComponent to parse.
|
|
33
40
|
*/
|
|
34
41
|
const isSafeUtf8UnescapedString = rawFileRelativePath.startsWith('"') && rawFileRelativePath.endsWith('"') && !rawFileRelativePath.includes(';') && !rawFileRelativePath.includes(',');
|
|
35
|
-
|
|
36
|
-
return str.replace(/\\(\d{3})\\(\d{3})\\(\d{3})/g, (_, $1, $2, $3) => decodeURIComponent(`%${Number.parseInt($1, 8).toString(16)}%${Number.parseInt($2, 8).toString(16)}%${Number.parseInt($3, 8).toString(16)}`));
|
|
37
|
-
}
|
|
38
|
-
const fileRelativePath = isSafeUtf8UnescapedString ? decode(rawFileRelativePath).replace(/^"/, '').replace(/"$/, '') : rawFileRelativePath;
|
|
42
|
+
const fileRelativePath = isSafeUtf8UnescapedString ? decodeGitEscape(rawFileRelativePath).replace(/^"/, '').replace(/"$/, '') : rawFileRelativePath;
|
|
39
43
|
return {
|
|
40
44
|
type,
|
|
41
45
|
fileRelativePath,
|
|
42
46
|
filePath: path.join(wikiFolderPath, fileRelativePath),
|
|
43
47
|
};
|
|
44
|
-
})
|
|
48
|
+
})
|
|
49
|
+
.sort((item, item2) => item.fileRelativePath.localeCompare(item2.fileRelativePath, 'zh'));
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
47
52
|
* Inspect git's remote url from folder's .git config
|
|
48
53
|
* @param dir wiki folder path, git folder to inspect
|
|
49
54
|
* @returns remote url, without `'.git'`
|
|
50
55
|
*/
|
|
51
|
-
export async function getRemoteUrl(dir) {
|
|
52
|
-
const remotes = await
|
|
53
|
-
const githubRemote = remotes.find(({ remote }) => remote ===
|
|
56
|
+
export async function getRemoteUrl(dir, remoteName) {
|
|
57
|
+
const remotes = await listRemotes({ fs, dir });
|
|
58
|
+
const githubRemote = remotes.find(({ remote }) => remote === remoteName) ?? remotes[0];
|
|
54
59
|
if ((githubRemote?.url?.length ?? 0) > 0) {
|
|
55
|
-
return githubRemote.url
|
|
60
|
+
return githubRemote.url;
|
|
56
61
|
}
|
|
57
62
|
return '';
|
|
58
63
|
}
|
|
@@ -84,38 +89,49 @@ export async function haveLocalChanges(wikiFolderPath) {
|
|
|
84
89
|
}
|
|
85
90
|
/**
|
|
86
91
|
* Get "master" or "main" from git repo
|
|
92
|
+
*
|
|
93
|
+
* https://github.com/simonthum/git-sync/blob/31cc140df2751e09fae2941054d5b61c34e8b649/git-sync#L228-L232
|
|
87
94
|
* @param wikiFolderPath
|
|
88
95
|
*/
|
|
89
96
|
export async function getDefaultBranchName(wikiFolderPath) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
try {
|
|
98
|
+
const { stdout } = await GitProcess.exec(['rev-parse', '--abbrev-ref', 'HEAD'], wikiFolderPath);
|
|
99
|
+
const [branchName] = stdout.split('\n');
|
|
100
|
+
// don't return empty string, so we can use ?? syntax
|
|
101
|
+
if (branchName === '') {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
return branchName;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
/**
|
|
108
|
+
* Catch "Unable to find path to repository on disk."
|
|
109
|
+
at node_modules/dugite/lib/git-process.ts:226:29
|
|
110
|
+
*/
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
98
113
|
}
|
|
99
114
|
/**
|
|
100
115
|
* determine sync state of repository, i.e. how the remote relates to our HEAD
|
|
101
116
|
* 'ahead' means our local state is ahead of remote, 'behind' means local state is behind of the remote
|
|
102
117
|
* @param dir repo path to test
|
|
103
118
|
*/
|
|
104
|
-
export async function getSyncState(dir,
|
|
105
|
-
const logDebug = (message, step) => logger?.
|
|
119
|
+
export async function getSyncState(dir, defaultBranchName, remoteName, logger) {
|
|
120
|
+
const logDebug = (message, step) => logger?.debug?.(message, { functionName: 'getSyncState', step, dir });
|
|
106
121
|
const logProgress = (step) => logger?.info?.(step, {
|
|
107
122
|
functionName: 'getSyncState',
|
|
108
123
|
step,
|
|
109
124
|
dir,
|
|
110
125
|
});
|
|
111
|
-
if (defaultBranchName === undefined) {
|
|
112
|
-
defaultBranchName = await getDefaultBranchName(dir);
|
|
113
|
-
}
|
|
114
126
|
logProgress(GitStep.CheckingLocalSyncState);
|
|
115
|
-
|
|
127
|
+
remoteName = remoteName ?? (await getRemoteName(dir, defaultBranchName));
|
|
128
|
+
const { stdout, stderr } = await GitProcess.exec(['rev-list', '--count', '--left-right', `${remoteName}/${defaultBranchName}...HEAD`], dir);
|
|
116
129
|
logDebug(`Checking sync state with upstream, stdout:\n${stdout}\n(stdout end)`, GitStep.CheckingLocalSyncState);
|
|
130
|
+
if (stderr.length > 0) {
|
|
131
|
+
logDebug(`Have problem checking sync state with upstream,stderr:\n${stderr}\n(stderr end)`, GitStep.CheckingLocalSyncState);
|
|
132
|
+
}
|
|
117
133
|
if (stdout === '') {
|
|
118
|
-
return '
|
|
134
|
+
return 'noUpstreamOrBareUpstream';
|
|
119
135
|
}
|
|
120
136
|
if (/0\t0/.exec(stdout) !== null) {
|
|
121
137
|
return 'equal';
|
|
@@ -128,11 +144,12 @@ export async function getSyncState(dir, logger, defaultBranchName) {
|
|
|
128
144
|
}
|
|
129
145
|
return 'diverged';
|
|
130
146
|
}
|
|
131
|
-
export async function assumeSync(wikiFolderPath,
|
|
132
|
-
|
|
147
|
+
export async function assumeSync(wikiFolderPath, defaultBranchName, remoteName, logger) {
|
|
148
|
+
const syncState = await getSyncState(wikiFolderPath, defaultBranchName, remoteName, logger);
|
|
149
|
+
if (syncState === 'equal') {
|
|
133
150
|
return;
|
|
134
151
|
}
|
|
135
|
-
throw new AssumeSyncError();
|
|
152
|
+
throw new AssumeSyncError(syncState);
|
|
136
153
|
}
|
|
137
154
|
/**
|
|
138
155
|
* get various repo state in string format
|
|
@@ -141,18 +158,23 @@ export async function assumeSync(wikiFolderPath, logger, defaultBranchName) {
|
|
|
141
158
|
* // TODO: use template literal type to get exact type of git state
|
|
142
159
|
*/
|
|
143
160
|
export async function getGitRepositoryState(wikiFolderPath, logger) {
|
|
144
|
-
|
|
145
|
-
if (typeof gitDirectory !== 'string' || gitDirectory.length === 0) {
|
|
161
|
+
if (!(await hasGit(wikiFolderPath))) {
|
|
146
162
|
return 'NOGIT';
|
|
147
163
|
}
|
|
148
|
-
const
|
|
164
|
+
const gitDirectory = await getGitDirectory(wikiFolderPath, logger);
|
|
165
|
+
const [isRebaseI, isRebaseM, isAMRebase, isMerging, isCherryPicking, isBisecting] = await Promise.all([
|
|
166
|
+
// isRebaseI
|
|
149
167
|
(await fs.lstat(path.join(gitDirectory, 'rebase-merge', 'interactive')).catch(() => ({})))?.isFile?.(),
|
|
168
|
+
// isRebaseM
|
|
150
169
|
(await fs.lstat(path.join(gitDirectory, 'rebase-merge')).catch(() => ({})))?.isDirectory?.(),
|
|
170
|
+
// isAMRebase
|
|
151
171
|
(await fs.lstat(path.join(gitDirectory, 'rebase-apply')).catch(() => ({})))?.isDirectory?.(),
|
|
172
|
+
// isMerging
|
|
152
173
|
(await fs.lstat(path.join(gitDirectory, 'MERGE_HEAD')).catch(() => ({})))?.isFile?.(),
|
|
174
|
+
// isCherryPicking
|
|
153
175
|
(await fs.lstat(path.join(gitDirectory, 'CHERRY_PICK_HEAD')).catch(() => ({})))?.isFile?.(),
|
|
176
|
+
// isBisecting
|
|
154
177
|
(await fs.lstat(path.join(gitDirectory, 'BISECT_LOG')).catch(() => ({})))?.isFile?.(),
|
|
155
|
-
(await GitProcess.exec(['rev-parse', '--is-inside-git-dir', wikiFolderPath], wikiFolderPath))?.stdout?.startsWith('true'),
|
|
156
178
|
]);
|
|
157
179
|
let result = '';
|
|
158
180
|
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
|
@@ -176,17 +198,18 @@ export async function getGitRepositoryState(wikiFolderPath, logger) {
|
|
|
176
198
|
result += 'BISECTING';
|
|
177
199
|
}
|
|
178
200
|
}
|
|
179
|
-
|
|
180
|
-
|
|
201
|
+
result += (await GitProcess.exec(['rev-parse', '--is-bare-repository', wikiFolderPath], wikiFolderPath)).stdout.startsWith('true') ? '|BARE' : '';
|
|
202
|
+
/* if ((await GitProcess.exec(['rev-parse', '--is-inside-work-tree', wikiFolderPath], wikiFolderPath)).stdout.startsWith('true')) {
|
|
203
|
+
const { exitCode } = await GitProcess.exec(['diff', '--no-ext-diff', '--quiet', '--exit-code'], wikiFolderPath);
|
|
204
|
+
// 1 if there were differences and 0 means no differences.
|
|
205
|
+
if (exitCode !== 0) {
|
|
206
|
+
result += '|DIRTY';
|
|
207
|
+
}
|
|
208
|
+
} */
|
|
209
|
+
// previous above `git diff --no-ext-diff --quiet --exit-code` logic from git-sync script can only detect if an existed file changed, can't detect newly added file, so we use `haveLocalChanges` instead
|
|
210
|
+
if (await haveLocalChanges(wikiFolderPath)) {
|
|
211
|
+
result += '|DIRTY';
|
|
181
212
|
}
|
|
182
|
-
else if ((await GitProcess.exec(['rev-parse', '--is-inside-work-tree', wikiFolderPath], wikiFolderPath)).stdout.startsWith('true')) {
|
|
183
|
-
const { exitCode } = await GitProcess.exec(['diff', '--no-ext-diff', '--quiet', '--exit-code'], wikiFolderPath);
|
|
184
|
-
// 1 if there were differences and 0 means no differences.
|
|
185
|
-
if (exitCode !== 0) {
|
|
186
|
-
result += '|DIRTY';
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/* eslint-enable @typescript-eslint/strict-boolean-expressions */
|
|
190
213
|
return result;
|
|
191
214
|
}
|
|
192
215
|
/**
|
|
@@ -194,9 +217,9 @@ export async function getGitRepositoryState(wikiFolderPath, logger) {
|
|
|
194
217
|
* @param dir repo path
|
|
195
218
|
*/
|
|
196
219
|
export async function getGitDirectory(dir, logger) {
|
|
197
|
-
const logDebug = (message, step) => logger?.
|
|
220
|
+
const logDebug = (message, step) => logger?.debug?.(message, { functionName: 'getGitDirectory', step, dir });
|
|
198
221
|
const logProgress = (step) => logger?.info?.(step, {
|
|
199
|
-
functionName: '
|
|
222
|
+
functionName: 'getGitDirectory',
|
|
200
223
|
step,
|
|
201
224
|
dir,
|
|
202
225
|
});
|
|
@@ -210,15 +233,23 @@ export async function getGitDirectory(dir, logger) {
|
|
|
210
233
|
const { stdout: stdout2 } = await GitProcess.exec(['rev-parse', '--git-dir', dir], dir);
|
|
211
234
|
const [gitPath2, gitPath1] = compact(stdout2.split('\n'));
|
|
212
235
|
if (gitPath2 !== undefined && gitPath1 !== undefined) {
|
|
213
|
-
return path.resolve(
|
|
236
|
+
return path.resolve(gitPath1, gitPath2);
|
|
214
237
|
}
|
|
215
238
|
}
|
|
216
239
|
throw new CantSyncGitNotInitializedError(dir);
|
|
217
240
|
}
|
|
218
|
-
/**
|
|
219
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Check if dir has `.git`.
|
|
243
|
+
* @param dir folder that may contains a git
|
|
244
|
+
* @param strict if is true, then dir should be the root of the git repo. Default is true
|
|
245
|
+
* @returns
|
|
246
|
+
*/
|
|
247
|
+
export async function hasGit(dir, strict = true) {
|
|
220
248
|
try {
|
|
221
|
-
await getGitDirectory(dir);
|
|
249
|
+
const resultDir = await getGitDirectory(dir);
|
|
250
|
+
if (strict && path.dirname(resultDir) !== dir) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
222
253
|
}
|
|
223
254
|
catch (error) {
|
|
224
255
|
if (error instanceof CantSyncGitNotInitializedError) {
|
|
@@ -227,4 +258,24 @@ export async function hasGit(dir) {
|
|
|
227
258
|
}
|
|
228
259
|
return true;
|
|
229
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* get things like "origin"
|
|
263
|
+
*
|
|
264
|
+
* https://github.com/simonthum/git-sync/blob/31cc140df2751e09fae2941054d5b61c34e8b649/git-sync#L238-L257
|
|
265
|
+
*/
|
|
266
|
+
export async function getRemoteName(dir, branch) {
|
|
267
|
+
let { stdout } = await GitProcess.exec(['config', '--get', `branch.${branch}.pushRemote`], dir);
|
|
268
|
+
if (stdout.trim()) {
|
|
269
|
+
return stdout.trim();
|
|
270
|
+
}
|
|
271
|
+
({ stdout } = await GitProcess.exec(['config', '--get', `remote.pushDefault`], dir));
|
|
272
|
+
if (stdout.trim()) {
|
|
273
|
+
return stdout.trim();
|
|
274
|
+
}
|
|
275
|
+
({ stdout } = await GitProcess.exec(['config', '--get', `branch.${branch}.remote`], dir));
|
|
276
|
+
if (stdout.trim()) {
|
|
277
|
+
return stdout.trim();
|
|
278
|
+
}
|
|
279
|
+
return 'origin';
|
|
280
|
+
}
|
|
230
281
|
//# sourceMappingURL=inspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../src/inspect.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,kDAAkD;AAClD,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,QA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AAM,EAAE,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,oBAAoB,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACrF,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE;QACjB,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;KACtB;IACD,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,MAAM,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1F,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE;QACjB,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;KACtB;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -7,6 +7,7 @@ export interface IGitUserInfosWithoutToken {
|
|
|
7
7
|
email: string | null | undefined;
|
|
8
8
|
/** Github Login: username , this is also used to filter user's repo when searching repo */
|
|
9
9
|
gitUserName: string;
|
|
10
|
+
branch: string;
|
|
10
11
|
}
|
|
11
12
|
/** custom logger to report progress on each step
|
|
12
13
|
* we don't use logger to report error, we throw errors.
|
|
@@ -15,7 +16,7 @@ export interface ILogger {
|
|
|
15
16
|
/** used to report progress for human user to read */
|
|
16
17
|
info: (message: GitStep, context: ILoggerContext) => unknown;
|
|
17
18
|
/** used to report debug logs */
|
|
18
|
-
|
|
19
|
+
debug: (message: string, context: ILoggerContext) => unknown;
|
|
19
20
|
/** used to report failed optional progress */
|
|
20
21
|
warn: (message: string, context: ILoggerContext) => unknown;
|
|
21
22
|
}
|
|
@@ -25,6 +26,7 @@ export interface ILoggerContext {
|
|
|
25
26
|
step: GitStep;
|
|
26
27
|
dir?: string;
|
|
27
28
|
remoteUrl?: string;
|
|
29
|
+
branch?: string;
|
|
28
30
|
}
|
|
29
31
|
export declare enum GitStep {
|
|
30
32
|
StartGitInitialization = "StartGitInitialization",
|
|
@@ -40,6 +42,7 @@ export declare enum GitStep {
|
|
|
40
42
|
PreparingUserInfo = "PreparingUserInfo",
|
|
41
43
|
FetchingData = "FetchingData",
|
|
42
44
|
NoNeedToSync = "NoNeedToSync",
|
|
45
|
+
NoUpstreamCantPush = "NoUpstreamCantPush",
|
|
43
46
|
LocalAheadStartUpload = "LocalAheadStartUpload",
|
|
44
47
|
CheckingLocalSyncState = "CheckingLocalSyncState",
|
|
45
48
|
CheckingLocalGitRepoSanity = "CheckingLocalGitRepoSanity",
|
|
@@ -48,7 +51,11 @@ export declare enum GitStep {
|
|
|
48
51
|
RebaseResultChecking = "RebaseResultChecking",
|
|
49
52
|
RebaseConflictNeedsResolve = "RebaseConflictNeedsResolve",
|
|
50
53
|
RebaseSucceed = "RebaseSucceed",
|
|
54
|
+
GitPush = "GitPush",
|
|
55
|
+
GitMerge = "GitMerge",
|
|
51
56
|
GitPushFailed = "GitPushFailed",
|
|
57
|
+
GitPushComplete = "GitPushComplete",
|
|
58
|
+
GitMergeComplete = "GitMergeComplete",
|
|
52
59
|
GitMergeFailed = "GitMergeFailed",
|
|
53
60
|
/** this means our algorithm have some problems */
|
|
54
61
|
SyncFailedAlgorithmWrong = "SyncFailedAlgorithmWrong",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAc,SAAQ,yBAAyB;IAC9D,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,yBAAyB;IACxC,+BAA+B;IAC/B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACjC,2FAA2F;IAC3F,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,qDAAqD;IACrD,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAA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MAAM,gBAAgB,WAA8E,CAAC"}
|
|
@@ -13,6 +13,7 @@ export var GitStep;
|
|
|
13
13
|
GitStep["PreparingUserInfo"] = "PreparingUserInfo";
|
|
14
14
|
GitStep["FetchingData"] = "FetchingData";
|
|
15
15
|
GitStep["NoNeedToSync"] = "NoNeedToSync";
|
|
16
|
+
GitStep["NoUpstreamCantPush"] = "NoUpstreamCantPush";
|
|
16
17
|
GitStep["LocalAheadStartUpload"] = "LocalAheadStartUpload";
|
|
17
18
|
GitStep["CheckingLocalSyncState"] = "CheckingLocalSyncState";
|
|
18
19
|
GitStep["CheckingLocalGitRepoSanity"] = "CheckingLocalGitRepoSanity";
|
|
@@ -21,7 +22,11 @@ export var GitStep;
|
|
|
21
22
|
GitStep["RebaseResultChecking"] = "RebaseResultChecking";
|
|
22
23
|
GitStep["RebaseConflictNeedsResolve"] = "RebaseConflictNeedsResolve";
|
|
23
24
|
GitStep["RebaseSucceed"] = "RebaseSucceed";
|
|
25
|
+
GitStep["GitPush"] = "GitPush";
|
|
26
|
+
GitStep["GitMerge"] = "GitMerge";
|
|
24
27
|
GitStep["GitPushFailed"] = "GitPushFailed";
|
|
28
|
+
GitStep["GitPushComplete"] = "GitPushComplete";
|
|
29
|
+
GitStep["GitMergeComplete"] = "GitMergeComplete";
|
|
25
30
|
GitStep["GitMergeFailed"] = "GitMergeFailed";
|
|
26
31
|
/** this means our algorithm have some problems */
|
|
27
32
|
GitStep["SyncFailedAlgorithmWrong"] = "SyncFailedAlgorithmWrong";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":"AAiCA,MAAM,CAAN,IAAY,OAmCX;AAnCD,WAAY,OAAO;IACjB,4DAAiD,CAAA;IACjD,4DAAiD,CAAA;IACjD,oFAAyE,CAAA;IACzE,4FAAiF,CAAA;IACjF,4DAAiD,CAAA;IACjD,sCAA2B,CAAA;IAC3B,oDAAyC,CAAA;IACzC,sCAA2B,CAAA;IAC3B,sCAA2B,CAAA;IAC3B,4CAAiC,CAAA;IACjC,kDAAuC,CAAA;IACvC,wCAA6B,CAAA;IAC7B,wCAA6B,CAAA;IAC7B,oDAAyC,CAAA;IACzC,0DAA+C,CAAA;IAC/C,4DAAiD,CAAA;IACjD,oEAAyD,CAAA;IACzD,wDAA6C,CAAA;IAC7C,8DAAmD,CAAA;IACnD,wDAA6C,CAAA;IAC7C,oEAAyD,CAAA;IACzD,0CAA+B,CAAA;IAC/B,8BAAmB,CAAA;IACnB,gCAAqB,CAAA;IACrB,0CAA+B,CAAA;IAC/B,8CAAmC,CAAA;IACnC,gDAAqC,CAAA;IACrC,4CAAiC,CAAA;IACjC,kDAAkD;IAClD,gEAAqD,CAAA;IACrD,sGAA2F,CAAA;IAC3F,0DAA+C,CAAA;IAC/C,0EAA+D,CAAA;IAC/D,8FAAmF,CAAA;AACrF,CAAC,EAnCW,OAAO,KAAP,OAAO,QAmClB;AACD;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -7,7 +7,24 @@ import { ILogger } from './interface';
|
|
|
7
7
|
* @param email
|
|
8
8
|
* @param message
|
|
9
9
|
*/
|
|
10
|
-
export declare function commitFiles(dir: string, username: string, email: string, message?: string, logger?: ILogger): Promise<IGitResult>;
|
|
10
|
+
export declare function commitFiles(dir: string, username: string, email: string, message?: string, filesToIgnore?: string[], logger?: ILogger): Promise<IGitResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Git push -f origin master
|
|
13
|
+
* This does force push, to deal with `--allow-unrelated-histories` case
|
|
14
|
+
* @param dir
|
|
15
|
+
* @param username
|
|
16
|
+
* @param email
|
|
17
|
+
* @param message
|
|
18
|
+
*/
|
|
19
|
+
export declare function pushUpstream(dir: string, branch: string, remoteName: string, logger?: ILogger): Promise<IGitResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Git merge origin master
|
|
22
|
+
* @param dir
|
|
23
|
+
* @param username
|
|
24
|
+
* @param email
|
|
25
|
+
* @param message
|
|
26
|
+
*/
|
|
27
|
+
export declare function mergeUpstream(dir: string, branch: string, remoteName: string, logger?: ILogger): Promise<IGitResult>;
|
|
11
28
|
/**
|
|
12
29
|
* try to continue rebase, simply adding and committing all things, leave them to user to resolve in the TiddlyWiki later.
|
|
13
30
|
* @param dir
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/sync.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,UAAU,EAAE,MAAM,QAAQ,CAAC;AAMhD,OAAO,EAAW,OAAO,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,SAA4B,EACnC,aAAa,GAAE,MAAM,EAAO,EAC5B,MAAM,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,UAAU,CAAC,CAqBrB;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAgBzH;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAe1H;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,uBAAuB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAmCpJ"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable unicorn/prevent-abbreviations */
|
|
2
2
|
import { GitProcess } from 'dugite';
|
|
3
|
-
import
|
|
3
|
+
import { add, listFiles, remove } from 'isomorphic-git';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
|
-
import { CantSyncInSpecialGitStateAutoFixFailed, SyncScriptIsInDeadLoopError } from './errors';
|
|
5
|
+
import { CantSyncInSpecialGitStateAutoFixFailed, GitPullPushError, SyncScriptIsInDeadLoopError } from './errors';
|
|
6
6
|
import { getGitRepositoryState } from './inspect';
|
|
7
7
|
import { GitStep } from './interface';
|
|
8
8
|
/**
|
|
@@ -12,17 +12,70 @@ import { GitStep } from './interface';
|
|
|
12
12
|
* @param email
|
|
13
13
|
* @param message
|
|
14
14
|
*/
|
|
15
|
-
export async function commitFiles(dir, username, email, message = '
|
|
15
|
+
export async function commitFiles(dir, username, email, message = 'Commit with Git-Sync-JS', filesToIgnore = [], logger) {
|
|
16
16
|
const logProgress = (step) => logger?.info(step, {
|
|
17
17
|
functionName: 'commitFiles',
|
|
18
18
|
step,
|
|
19
19
|
dir,
|
|
20
20
|
});
|
|
21
21
|
logProgress(GitStep.AddingFiles);
|
|
22
|
-
await
|
|
22
|
+
await add({ dir, filepath: '.', fs });
|
|
23
|
+
// find and unStage files that are in the ignore list
|
|
24
|
+
const stagedFiles = await listFiles({ fs, dir });
|
|
25
|
+
if (filesToIgnore.length > 0) {
|
|
26
|
+
const stagedFilesToIgnore = filesToIgnore.filter((file) => stagedFiles.includes(file));
|
|
27
|
+
if (stagedFilesToIgnore.length > 0) {
|
|
28
|
+
await Promise.all(stagedFilesToIgnore.map(async (file) => await remove({ dir, filepath: file, fs })));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
23
31
|
logProgress(GitStep.AddComplete);
|
|
24
32
|
return await GitProcess.exec(['commit', '-m', message, `--author="${username} <${email}>"`], dir);
|
|
25
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Git push -f origin master
|
|
36
|
+
* This does force push, to deal with `--allow-unrelated-histories` case
|
|
37
|
+
* @param dir
|
|
38
|
+
* @param username
|
|
39
|
+
* @param email
|
|
40
|
+
* @param message
|
|
41
|
+
*/
|
|
42
|
+
export async function pushUpstream(dir, branch, remoteName, logger) {
|
|
43
|
+
const logProgress = (step) => logger?.info(step, {
|
|
44
|
+
functionName: 'pushUpstream',
|
|
45
|
+
step,
|
|
46
|
+
dir,
|
|
47
|
+
});
|
|
48
|
+
/** when push to remote, we need to specify the local branch name and remote branch name */
|
|
49
|
+
const branchMapping = `${branch}:${branch}`;
|
|
50
|
+
logProgress(GitStep.GitPush);
|
|
51
|
+
const pushResult = await GitProcess.exec(['push', remoteName, branchMapping], dir);
|
|
52
|
+
logProgress(GitStep.GitPushComplete);
|
|
53
|
+
if (pushResult.exitCode !== 0) {
|
|
54
|
+
throw new GitPullPushError({ dir, branch, remote: remoteName }, pushResult.stdout + pushResult.stderr);
|
|
55
|
+
}
|
|
56
|
+
return pushResult;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Git merge origin master
|
|
60
|
+
* @param dir
|
|
61
|
+
* @param username
|
|
62
|
+
* @param email
|
|
63
|
+
* @param message
|
|
64
|
+
*/
|
|
65
|
+
export async function mergeUpstream(dir, branch, remoteName, logger) {
|
|
66
|
+
const logProgress = (step) => logger?.info(step, {
|
|
67
|
+
functionName: 'mergeUpstream',
|
|
68
|
+
step,
|
|
69
|
+
dir,
|
|
70
|
+
});
|
|
71
|
+
logProgress(GitStep.GitMerge);
|
|
72
|
+
const mergeResult = await GitProcess.exec(['merge', '--ff', '--ff-only', `${remoteName}/${branch}`], dir);
|
|
73
|
+
logProgress(GitStep.GitMergeComplete);
|
|
74
|
+
if (mergeResult.exitCode !== 0) {
|
|
75
|
+
throw new GitPullPushError({ dir, branch, remote: remoteName }, mergeResult.stdout + mergeResult.stderr);
|
|
76
|
+
}
|
|
77
|
+
return mergeResult;
|
|
78
|
+
}
|
|
26
79
|
/**
|
|
27
80
|
* try to continue rebase, simply adding and committing all things, leave them to user to resolve in the TiddlyWiki later.
|
|
28
81
|
* @param dir
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,UAAU,EAAc,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B,OAAO,EAAE,sCAAsC,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AACjH,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,OAAO,EAAW,MAAM,aAAa,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAW,EACX,QAAgB,EAChB,KAAa,EACb,OAAO,GAAG,yBAAyB,EACnC,gBAA0B,EAAE,EAC5B,MAAgB;IAEhB,MAAM,WAAW,GAAG,CAAC,IAAa,EAAW,EAAE,CAC7C,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE;QACjB,YAAY,EAAE,aAAa;QAC3B,IAAI;QACJ,GAAG;KACJ,CAAC,CAAC;IAEL,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACjC,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IACtC,qDAAqD;IACrD,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACjD,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5B,MAAM,mBAAmB,GAAG,aAAa,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|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,QAAS,MAAM,KAAG,MAAsB,CAAC;AAC5E,eAAO,MAAM,yBAAyB,QAAS,MAAM,KAAG,MAAmC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC;AAC5E,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone.test.d.ts","sourceRoot":"","sources":["../../test/clone.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { getDefaultBranchName, getSyncState, hasGit, haveLocalChanges } from '../src/inspect';
|
|
4
|
+
import { defaultGitInfo } from '../src/defaultGitInfo';
|
|
5
|
+
import {
|
|
6
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
7
|
+
dir, exampleToken, gitDirectory,
|
|
8
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
9
|
+
upstreamDir, } from './constants';
|
|
10
|
+
import { clone } from '../src/clone';
|
|
11
|
+
import { addAndCommitUsingDugite, addSomeFiles } from './utils';
|
|
12
|
+
describe('clone', () => {
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
// remove dir's .git folder in this test suit, so we have a clean folder to clone
|
|
15
|
+
await fs.remove(gitDirectory);
|
|
16
|
+
});
|
|
17
|
+
describe('with upstream', () => {
|
|
18
|
+
test('equal to upstream after clone', async () => {
|
|
19
|
+
await clone({
|
|
20
|
+
dir,
|
|
21
|
+
userInfo: { ...defaultGitInfo, accessToken: exampleToken },
|
|
22
|
+
remoteUrl: upstreamDir,
|
|
23
|
+
});
|
|
24
|
+
expect(await hasGit(dir)).toBe(true);
|
|
25
|
+
expect(await haveLocalChanges(dir)).toBe(false);
|
|
26
|
+
expect(await getSyncState(dir, defaultGitInfo.branch, defaultGitInfo.remote)).toBe('equal');
|
|
27
|
+
expect(await getDefaultBranchName(dir)).toBe(defaultGitInfo.branch);
|
|
28
|
+
});
|
|
29
|
+
test('equal to committed upstream', async () => {
|
|
30
|
+
// modify upstream
|
|
31
|
+
await addSomeFiles(upstreamDir);
|
|
32
|
+
await addAndCommitUsingDugite(upstreamDir);
|
|
33
|
+
await clone({
|
|
34
|
+
dir,
|
|
35
|
+
userInfo: { ...defaultGitInfo, accessToken: exampleToken },
|
|
36
|
+
remoteUrl: upstreamDir,
|
|
37
|
+
});
|
|
38
|
+
expect(await getSyncState(dir, defaultGitInfo.branch, defaultGitInfo.remote)).toBe('equal');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=clone.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone.test.js","sourceRoot":"","sources":["../../test/clone.test.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAa,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO;AACL,yDAAyD;AACzD,GAAG,EACH,YAAY,EACZ,YAAY;AACZ,yDAAyD;AACzD,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAA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