one-way-git-sync 3.0.1 → 3.1.3
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 +59 -1
- package/package.json +43 -37
- package/dist/index.js +0 -202
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,4 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/semantic-release/semantic-release)
|
|
4
4
|
|
|
5
|
-
A tool for synchronizing git
|
|
5
|
+
:arrows_counterclockwise: A tool for synchronizing a destination git repository with a source git repository SAFELY.
|
|
6
|
+
|
|
7
|
+
It provides three features:
|
|
8
|
+
|
|
9
|
+
1. replace the files of a destination repository (`dest repo`) with those of a source repository (`src repo`),
|
|
10
|
+
2. add a replacement commit (`sync commit`) which whose message has the history of the included commits in the src repo and
|
|
11
|
+
3. detect a conflict when a dest repo has a commit which a src repo doesn't have.
|
|
12
|
+
|
|
13
|
+
## How to Use
|
|
14
|
+
|
|
15
|
+
### Initial Usage
|
|
16
|
+
|
|
17
|
+
Since `one-way-git-sync` finds a sync commit from the commit history of the dest repo,
|
|
18
|
+
you need to run `init` subcommand to add an initial sync commit
|
|
19
|
+
by replacing all the files of the dest repo with those of src repo at first.
|
|
20
|
+
The sample command is as follows:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
yarn one-way-git-sync init \
|
|
24
|
+
-d https://github.com/WillBooster/sample-of-one-way-git-sync \
|
|
25
|
+
-p https://github.com/WillBooster/one-way-git-sync/commits/
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Usual Usage
|
|
29
|
+
|
|
30
|
+
If the last commit in the dest repo is a sync commit,
|
|
31
|
+
`one-way-git-sync` safely synchronize the dest repo with the src repo.
|
|
32
|
+
The sample command is as follows:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
yarn one-way-git-sync \
|
|
36
|
+
-d https://github.com/WillBooster/sample-of-one-way-git-sync \
|
|
37
|
+
-p https://github.com/WillBooster/one-way-git-sync/commits/
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### How to Deal with Conflicts
|
|
41
|
+
|
|
42
|
+
If the last commit in the dest repo isn't a sync commit and if it is not first time,
|
|
43
|
+
the dest repo probably has some commits (`conflict commits`) which don't exist in the src repo.
|
|
44
|
+
You need to merge conflict commits in the src repo manually at first,
|
|
45
|
+
then, you need to force synchronizing the dest repo with the src repo.
|
|
46
|
+
The sample commands are as follows:
|
|
47
|
+
|
|
48
|
+
1. `yarn one-way-git-sync` fails then you notice there exist conflict commits
|
|
49
|
+
2. `cd one-way-git-sync`
|
|
50
|
+
3. `git remote add upstream https://github.com/WillBooster/sample-of-one-way-git-sync`
|
|
51
|
+
4. `git merge --allow-unrelated-histories upstream/main`
|
|
52
|
+
5. ```
|
|
53
|
+
yarn one-way-git-sync --force \
|
|
54
|
+
-d https://github.com/WillBooster/sample-of-one-way-git-sync \
|
|
55
|
+
-p https://github.com/WillBooster/one-way-git-sync/commits/
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Example Repository and Example GitHub Actions Workflows
|
|
59
|
+
|
|
60
|
+
- [sample-of-one-way-git-sync](https://github.com/WillBooster/sample-of-one-way-git-sync): an example synchronized repository.
|
|
61
|
+
- [release.yml](.github/workflows/release.yml): releases a new npm package and add a tag automatically in this repository using `semantic-release`.
|
|
62
|
+
- [sync.yml](.github/workflows/sync.yml): it synchronizes `sample-of-one-way-git-sync` repository using `one-way-git-sync` when a new version is released.
|
|
63
|
+
- [force-sync.yml](.github/workflows/sync-force.yml): we can manually trigger this workflow which forces synchronizing `sample-of-one-way-git-sync` repository.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "one-way-git-sync",
|
|
3
|
-
"description": "A tool for synchronizing git
|
|
3
|
+
"description": "A tool for synchronizing a destination git repository with a source git repository SAFELY.",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"git",
|
|
6
6
|
"sync"
|
|
@@ -18,66 +18,72 @@
|
|
|
18
18
|
"cleanup": "yarn format && yarn lint-fix",
|
|
19
19
|
"format": "sort-package-json && yarn prettify",
|
|
20
20
|
"_postinstall": "husky install",
|
|
21
|
-
"lint": "eslint --color \"./{src,__tests__}/**/*.{js,jsx,ts,tsx}\"",
|
|
21
|
+
"lint": "eslint --color \"./{src,__tests__}/**/*.{cjs,js,jsx,mjs,ts,tsx}\"",
|
|
22
22
|
"lint-fix": "yarn lint --fix",
|
|
23
23
|
"prepublishOnly": "pinst --disable",
|
|
24
|
-
"prettify": "prettier --color --write \"**/{.*/,}*.{css,htm,html,js,json,json5,jsx,md,scss,ts,tsx,vue,yaml,yml}\" \"!**/test-fixtures/**\"",
|
|
24
|
+
"prettify": "prettier --color --write \"**/{.*/,}*.{cjs,css,htm,html,js,json,json5,jsx,md,mjs,scss,ts,tsx,vue,yaml,yml}\" \"!**/test-fixtures/**\"",
|
|
25
25
|
"postpublish": "pinst --enable",
|
|
26
|
-
"start": "
|
|
27
|
-
"start-prod": "yarn
|
|
26
|
+
"start": "babel-node -x .js,.jsx,.es6,.es,.ts -- src/start.ts",
|
|
27
|
+
"start-prod": "yarn build && yarn one-way-git-sync",
|
|
28
28
|
"typecheck": "tsc --noEmit --Pretty"
|
|
29
29
|
},
|
|
30
30
|
"prettier": "@willbooster/prettier-config",
|
|
31
|
+
"resolutions": {
|
|
32
|
+
"npm/chalk": "^4.1.2"
|
|
33
|
+
},
|
|
31
34
|
"dependencies": {
|
|
32
35
|
"fs-extra": "10.0.0",
|
|
33
|
-
"simple-git": "2.
|
|
34
|
-
"
|
|
36
|
+
"simple-git": "2.48.0",
|
|
37
|
+
"winston": "3.5.1",
|
|
38
|
+
"yargs": "17.3.1"
|
|
35
39
|
},
|
|
36
40
|
"devDependencies": {
|
|
37
|
-
"@babel/core": "7.
|
|
38
|
-
"@babel/helper-plugin-utils": "7.
|
|
39
|
-
"@babel/node": "7.16.
|
|
40
|
-
"@babel/plugin-proposal-class-properties": "7.16.
|
|
41
|
-
"@babel/plugin-proposal-numeric-separator": "7.16.
|
|
42
|
-
"@babel/preset-env": "7.16.
|
|
43
|
-
"@babel/preset-typescript": "7.16.
|
|
41
|
+
"@babel/core": "7.17.2",
|
|
42
|
+
"@babel/helper-plugin-utils": "7.16.7",
|
|
43
|
+
"@babel/node": "7.16.8",
|
|
44
|
+
"@babel/plugin-proposal-class-properties": "7.16.7",
|
|
45
|
+
"@babel/plugin-proposal-numeric-separator": "7.16.7",
|
|
46
|
+
"@babel/preset-env": "7.16.11",
|
|
47
|
+
"@babel/preset-typescript": "7.16.7",
|
|
44
48
|
"@rollup/plugin-babel": "5.3.0",
|
|
45
49
|
"@rollup/plugin-commonjs": "21.0.1",
|
|
46
|
-
"@rollup/plugin-node-resolve": "13.
|
|
47
|
-
"@types/eslint": "
|
|
50
|
+
"@rollup/plugin-node-resolve": "13.1.3",
|
|
51
|
+
"@types/eslint": "8.4.1",
|
|
48
52
|
"@types/fs-extra": "9.0.13",
|
|
49
53
|
"@types/micromatch": "4.0.2",
|
|
50
|
-
"@types/semantic-release": "17.2.
|
|
51
|
-
"@types/yargs": "17.0.
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
53
|
-
"@typescript-eslint/parser": "5.
|
|
54
|
-
"@willbooster/eslint-config-ts": "
|
|
55
|
-
"@willbooster/prettier-config": "
|
|
56
|
-
"@willbooster/renovate-config": "
|
|
54
|
+
"@types/semantic-release": "17.2.3",
|
|
55
|
+
"@types/yargs": "17.0.8",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "5.12.0",
|
|
57
|
+
"@typescript-eslint/parser": "5.12.0",
|
|
58
|
+
"@willbooster/eslint-config-ts": "9.0.0",
|
|
59
|
+
"@willbooster/prettier-config": "9.0.0",
|
|
60
|
+
"@willbooster/renovate-config": "9.2.0",
|
|
57
61
|
"babel-plugin-transform-remove-console": "6.9.4",
|
|
58
62
|
"babel-plugin-unassert": "3.2.0",
|
|
59
63
|
"babel-preset-power-assert": "3.0.0",
|
|
60
|
-
"conventional-changelog-conventionalcommits": "4.6.
|
|
61
|
-
"core-js": "3.
|
|
62
|
-
"eslint": "8.
|
|
64
|
+
"conventional-changelog-conventionalcommits": "4.6.3",
|
|
65
|
+
"core-js": "3.21.0",
|
|
66
|
+
"eslint": "8.9.0",
|
|
63
67
|
"eslint-config-prettier": "8.3.0",
|
|
64
|
-
"eslint-import-resolver-
|
|
65
|
-
"eslint-plugin-import": "2.25.
|
|
68
|
+
"eslint-import-resolver-typescript": "2.5.0",
|
|
69
|
+
"eslint-plugin-import": "2.25.4",
|
|
70
|
+
"eslint-plugin-sort-class-members": "1.14.1",
|
|
71
|
+
"eslint-plugin-sort-destructure-keys": "1.4.0",
|
|
66
72
|
"husky": "7.0.4",
|
|
67
|
-
"lint-staged": "
|
|
73
|
+
"lint-staged": "12.3.4",
|
|
68
74
|
"micromatch": "4.0.4",
|
|
69
75
|
"pinst": "2.1.6",
|
|
70
76
|
"power-assert": "1.6.1",
|
|
71
|
-
"prettier": "2.
|
|
72
|
-
"rollup": "2.
|
|
73
|
-
"rollup-plugin-node-externals": "
|
|
74
|
-
"semantic-release": "18.0.
|
|
75
|
-
"sort-package-json": "1.
|
|
76
|
-
"typescript": "4.
|
|
77
|
+
"prettier": "2.5.1",
|
|
78
|
+
"rollup": "2.67.2",
|
|
79
|
+
"rollup-plugin-node-externals": "4.0.0",
|
|
80
|
+
"semantic-release": "18.0.1",
|
|
81
|
+
"sort-package-json": "1.54.0",
|
|
82
|
+
"typescript": "4.5.5"
|
|
77
83
|
},
|
|
78
84
|
"engines": {
|
|
79
85
|
"node": ">=14"
|
|
80
86
|
},
|
|
81
|
-
"packageManager": "yarn@3.0.
|
|
82
|
-
"version": "3.
|
|
87
|
+
"packageManager": "yarn@3.2.0-rc.15",
|
|
88
|
+
"version": "3.1.3"
|
|
83
89
|
}
|
package/dist/index.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var helpers = require('yargs/helpers');
|
|
6
|
-
var yargs = require('yargs/yargs');
|
|
7
|
-
var child_process = require('child_process');
|
|
8
|
-
var fsp = require('fs/promises');
|
|
9
|
-
var path = require('path');
|
|
10
|
-
var fse = require('fs-extra');
|
|
11
|
-
var simpleGit = require('simple-git');
|
|
12
|
-
|
|
13
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
-
|
|
15
|
-
var yargs__default = /*#__PURE__*/_interopDefaultLegacy(yargs);
|
|
16
|
-
var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
|
|
17
|
-
var fsp__default = /*#__PURE__*/_interopDefaultLegacy(fsp);
|
|
18
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
19
|
-
var fse__default = /*#__PURE__*/_interopDefaultLegacy(fse);
|
|
20
|
-
var simpleGit__default = /*#__PURE__*/_interopDefaultLegacy(simpleGit);
|
|
21
|
-
|
|
22
|
-
const yargsOptions = {
|
|
23
|
-
dest: {
|
|
24
|
-
type: 'string',
|
|
25
|
-
alias: 'd',
|
|
26
|
-
describe: 'A URL of a destination git repository.',
|
|
27
|
-
demand: true
|
|
28
|
-
},
|
|
29
|
-
prefix: {
|
|
30
|
-
type: 'string',
|
|
31
|
-
alias: 'p',
|
|
32
|
-
describe: `A prefix of a commit hash used to generate a commit message.
|
|
33
|
-
The typical value is like "https://github.com/WillBooster/one-way-git-sync/commits/"`
|
|
34
|
-
},
|
|
35
|
-
branch: {
|
|
36
|
-
type: 'string',
|
|
37
|
-
alias: 'b',
|
|
38
|
-
describe: 'Specify branch of destination repo.'
|
|
39
|
-
},
|
|
40
|
-
tag: {
|
|
41
|
-
type: 'string',
|
|
42
|
-
alias: 't',
|
|
43
|
-
describe: 'Specify tag created in destination repo.'
|
|
44
|
-
},
|
|
45
|
-
'tag-hash': {
|
|
46
|
-
type: 'boolean',
|
|
47
|
-
describe: 'Create version+hash tag (e.g. v1.31.5-2-gcdde507). It should be a unique tag.'
|
|
48
|
-
},
|
|
49
|
-
'tag-version': {
|
|
50
|
-
type: 'boolean',
|
|
51
|
-
describe: 'Create version tag (e.g. v1.31.5). It may be a non-unique tag.'
|
|
52
|
-
},
|
|
53
|
-
dry: {
|
|
54
|
-
type: 'boolean',
|
|
55
|
-
describe: 'Enable dry-run mode.'
|
|
56
|
-
},
|
|
57
|
-
force: {
|
|
58
|
-
type: 'boolean',
|
|
59
|
-
describe: 'Force to overwrite the destination git repository.'
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const SYNC_DIR_PATH = '../sync-git-repo';
|
|
64
|
-
const ignoreNames = ['.git', 'node_modules'];
|
|
65
|
-
async function main(opts) {
|
|
66
|
-
var _srcLog$latest;
|
|
67
|
-
|
|
68
|
-
const srcGit = simpleGit__default["default"]();
|
|
69
|
-
await fsp__default["default"].rm(SYNC_DIR_PATH, {
|
|
70
|
-
recursive: true,
|
|
71
|
-
force: true
|
|
72
|
-
});
|
|
73
|
-
await srcGit.clone(opts.dest, SYNC_DIR_PATH, opts.force ? undefined : {
|
|
74
|
-
'--depth': 1
|
|
75
|
-
});
|
|
76
|
-
const dstGit = simpleGit__default["default"](SYNC_DIR_PATH);
|
|
77
|
-
|
|
78
|
-
if (opts.branch) {
|
|
79
|
-
try {
|
|
80
|
-
await dstGit.checkout(opts.branch);
|
|
81
|
-
} catch (_) {
|
|
82
|
-
await dstGit.checkoutLocalBranch(opts.branch);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const dstLog = await dstGit.log();
|
|
87
|
-
const from = extractCommitHash(dstLog);
|
|
88
|
-
|
|
89
|
-
if (!from) {
|
|
90
|
-
console.error('No valid commit in destination repo.');
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let srcLog;
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
// '--first-parent' hides children commits of merge commits
|
|
98
|
-
srcLog = await srcGit.log({
|
|
99
|
-
from,
|
|
100
|
-
to: 'HEAD',
|
|
101
|
-
'--first-parent': undefined
|
|
102
|
-
});
|
|
103
|
-
} catch (e) {
|
|
104
|
-
console.error('Failed to get source commit history:', e);
|
|
105
|
-
process.exit(1);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const latestHash = (_srcLog$latest = srcLog.latest) === null || _srcLog$latest === void 0 ? void 0 : _srcLog$latest.hash;
|
|
109
|
-
|
|
110
|
-
if (!latestHash) {
|
|
111
|
-
process.exit(0);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
for (const name of await fsp__default["default"].readdir(SYNC_DIR_PATH)) {
|
|
115
|
-
if (ignoreNames.includes(name)) continue;
|
|
116
|
-
await fsp__default["default"].rm(path__default["default"].join(SYNC_DIR_PATH, name), {
|
|
117
|
-
recursive: true,
|
|
118
|
-
force: true
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
for (const name of await fsp__default["default"].readdir('.')) {
|
|
123
|
-
if (ignoreNames.includes(name)) continue;
|
|
124
|
-
fse__default["default"].copySync(name, path__default["default"].join(SYNC_DIR_PATH, name));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
await dstGit.add('-A');
|
|
128
|
-
let srcTag = '';
|
|
129
|
-
|
|
130
|
-
if (opts['tag-hash'] || opts['tag-version']) {
|
|
131
|
-
// e.g. `--abbrev=0` changes `v1.31.5-2-gcdde507` to `v1.31.5`
|
|
132
|
-
const describeCommand = `git describe --tags --always ${opts['tag-version'] ? '--abbrev=0' : ''}`;
|
|
133
|
-
srcTag = child_process__default["default"].execSync(describeCommand).toString().trim();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const link = `${opts.prefix || ''}${latestHash}`;
|
|
137
|
-
const title = srcTag ? `sync ${srcTag} (${link})` : `sync ${link}`;
|
|
138
|
-
const body = srcLog.all.map(l => `* ${l.message}`).join('\n\n');
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
await dstGit.commit(`${title}\n\n${body}`);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
console.error('Failed to commit changes:', e);
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const destTag = srcTag || opts.tag;
|
|
148
|
-
|
|
149
|
-
if (destTag) {
|
|
150
|
-
try {
|
|
151
|
-
await dstGit.addTag(destTag);
|
|
152
|
-
} catch (e) {
|
|
153
|
-
console.error('Failed to commit changes:', e);
|
|
154
|
-
process.exit(1);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (opts.dry) {
|
|
159
|
-
process.exit(0);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
await dstGit.push();
|
|
164
|
-
|
|
165
|
-
if (destTag) {
|
|
166
|
-
await dstGit.push({
|
|
167
|
-
'--tags': null
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
} catch (e) {
|
|
171
|
-
console.error('Failed to push a commit:', e);
|
|
172
|
-
process.exit(1);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
process.exit(0);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function extractCommitHash(logResult) {
|
|
179
|
-
if (logResult.all.length === 0) {
|
|
180
|
-
console.error('No commit history.');
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
for (const log of logResult.all) {
|
|
185
|
-
const [head, ...words] = log.message.replace(/[()]/g, '').split(/[\s/]/);
|
|
186
|
-
|
|
187
|
-
if (head === 'sync' && words.length) {
|
|
188
|
-
return words[words.length - 1];
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
console.error('No sync commit: ', logResult.all[0]);
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async function cli(argv) {
|
|
197
|
-
const parsed = await yargs__default["default"](helpers.hideBin(argv)).options(yargsOptions).argv;
|
|
198
|
-
await main(parsed);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
exports.cli = cli;
|
|
202
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/yargsOptions.ts","../src/index.ts","../src/cli.ts"],"sourcesContent":["export const yargsOptions = {\n dest: {\n type: 'string',\n alias: 'd',\n describe: 'A URL of a destination git repository.',\n demand: true,\n },\n prefix: {\n type: 'string',\n alias: 'p',\n describe: `A prefix of a commit hash used to generate a commit message.\n The typical value is like \"https://github.com/WillBooster/one-way-git-sync/commits/\"`,\n },\n branch: {\n type: 'string',\n alias: 'b',\n describe: 'Specify branch of destination repo.',\n },\n tag: {\n type: 'string',\n alias: 't',\n describe: 'Specify tag created in destination repo.',\n },\n 'tag-hash': {\n type: 'boolean',\n describe: 'Create version+hash tag (e.g. v1.31.5-2-gcdde507). It should be a unique tag.',\n },\n 'tag-version': {\n type: 'boolean',\n describe: 'Create version tag (e.g. v1.31.5). It may be a non-unique tag.',\n },\n dry: {\n type: 'boolean',\n describe: 'Enable dry-run mode.',\n },\n force: {\n type: 'boolean',\n describe: 'Force to overwrite the destination git repository.',\n },\n} as const;\n","import child_process from 'child_process';\nimport fsp from 'fs/promises';\nimport path from 'path';\n\nimport fse from 'fs-extra';\nimport simpleGit, { SimpleGit } from 'simple-git';\nimport type { LogResult } from 'simple-git/typings/response';\nimport { InferredOptionTypes } from 'yargs';\n\nimport { yargsOptions } from './yargsOptions';\n\nconst SYNC_DIR_PATH = '../sync-git-repo';\nconst ignoreNames = ['.git', 'node_modules'];\n\nexport async function main(opts: InferredOptionTypes<typeof yargsOptions>): Promise<void> {\n const srcGit: SimpleGit = simpleGit();\n\n await fsp.rm(SYNC_DIR_PATH, { recursive: true, force: true });\n await srcGit.clone(opts.dest, SYNC_DIR_PATH, opts.force ? undefined : { '--depth': 1 });\n console.log('Cloned a destination repo.');\n\n const dstGit: SimpleGit = simpleGit(SYNC_DIR_PATH);\n if (opts.branch) {\n try {\n await dstGit.checkout(opts.branch);\n } catch (_) {\n await dstGit.checkoutLocalBranch(opts.branch);\n }\n }\n const dstLog = await dstGit.log();\n\n const from = extractCommitHash(dstLog);\n if (!from) {\n console.error('No valid commit in destination repo.');\n process.exit(1);\n }\n console.log(`Extracted a valid commit: ${from}`);\n\n let srcLog: LogResult;\n try {\n // '--first-parent' hides children commits of merge commits\n srcLog = await srcGit.log({ from, to: 'HEAD', '--first-parent': undefined });\n } catch (e) {\n console.error('Failed to get source commit history:', e);\n process.exit(1);\n }\n\n const latestHash = srcLog.latest?.hash;\n if (!latestHash) {\n console.log('No synchronizable commit.');\n process.exit(0);\n }\n\n for (const name of await fsp.readdir(SYNC_DIR_PATH)) {\n if (ignoreNames.includes(name)) continue;\n await fsp.rm(path.join(SYNC_DIR_PATH, name), { recursive: true, force: true });\n }\n for (const name of await fsp.readdir('.')) {\n if (ignoreNames.includes(name)) continue;\n fse.copySync(name, path.join(SYNC_DIR_PATH, name));\n }\n await dstGit.add('-A');\n\n let srcTag = '';\n if (opts['tag-hash'] || opts['tag-version']) {\n // e.g. `--abbrev=0` changes `v1.31.5-2-gcdde507` to `v1.31.5`\n const describeCommand = `git describe --tags --always ${opts['tag-version'] ? '--abbrev=0' : ''}`;\n srcTag = child_process.execSync(describeCommand).toString().trim();\n }\n const link = `${opts.prefix || ''}${latestHash}`;\n const title = srcTag ? `sync ${srcTag} (${link})` : `sync ${link}`;\n const body = srcLog.all.map((l) => `* ${l.message}`).join('\\n\\n');\n try {\n await dstGit.commit(`${title}\\n\\n${body}`);\n console.log(`Created a commit: ${title}`);\n console.log(`${body}`);\n } catch (e) {\n console.error('Failed to commit changes:', e);\n process.exit(1);\n }\n\n const destTag = srcTag || opts.tag;\n if (destTag) {\n try {\n await dstGit.addTag(destTag);\n console.log(`Created a tag: ${destTag}`);\n } catch (e) {\n console.error('Failed to commit changes:', e);\n process.exit(1);\n }\n }\n\n if (opts.dry) {\n console.log('Finished dry run');\n process.exit(0);\n }\n\n try {\n await dstGit.push();\n if (destTag) {\n await dstGit.push({ '--tags': null });\n }\n } catch (e) {\n console.error('Failed to push a commit:', e);\n process.exit(1);\n }\n\n console.log('Pushed');\n process.exit(0);\n}\n\nfunction extractCommitHash(logResult: LogResult): string | null {\n if (logResult.all.length === 0) {\n console.error('No commit history.');\n return null;\n }\n\n for (const log of logResult.all) {\n const [head, ...words] = log.message.replace(/[()]/g, '').split(/[\\s/]/);\n if (head === 'sync' && words.length) {\n return words[words.length - 1];\n }\n }\n console.error('No sync commit: ', logResult.all[0]);\n return null;\n}\n","import { hideBin } from 'yargs/helpers';\nimport yargs from 'yargs/yargs';\n\nimport { yargsOptions } from './yargsOptions';\n\nimport { main } from './index';\n\nexport async function cli(argv: string[]): Promise<void> {\n const parsed = await yargs(hideBin(argv)).options(yargsOptions).argv;\n await main(parsed);\n}\n"],"names":["yargsOptions","dest","type","alias","describe","demand","prefix","branch","tag","dry","force","SYNC_DIR_PATH","ignoreNames","main","opts","srcGit","simpleGit","fsp","rm","recursive","clone","undefined","dstGit","checkout","_","checkoutLocalBranch","dstLog","log","from","extractCommitHash","console","error","process","exit","srcLog","to","e","latestHash","latest","hash","name","readdir","includes","path","join","fse","copySync","add","srcTag","describeCommand","child_process","execSync","toString","trim","link","title","body","all","map","l","message","commit","destTag","addTag","push","logResult","length","head","words","replace","split","cli","argv","parsed","yargs","hideBin","options"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAO,MAAMA,YAAY,GAAG;AAC1BC,EAAAA,IAAI,EAAE;AACJC,IAAAA,IAAI,EAAE,QADF;AAEJC,IAAAA,KAAK,EAAE,GAFH;AAGJC,IAAAA,QAAQ,EAAE,wCAHN;AAIJC,IAAAA,MAAM,EAAE;AAJJ,GADoB;AAO1BC,EAAAA,MAAM,EAAE;AACNJ,IAAAA,IA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