git-push-time 1.0.3 → 1.1.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 +144 -63
- package/bin/index.js +199 -912
- package/lib/commands/edit-time.js +127 -0
- package/lib/commands/fix.js +105 -0
- package/lib/commands/github.js +436 -0
- package/lib/commands/pull.js +88 -0
- package/lib/commands/push.js +653 -0
- package/lib/config.js +210 -0
- package/lib/github.js +304 -0
- package/lib/prompt-helpers.js +62 -0
- package/lib/ui.js +186 -70
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { select } from '@inquirer/prompts';
|
|
3
|
+
import {
|
|
4
|
+
checkGitInstalled,
|
|
5
|
+
isGitRepo,
|
|
6
|
+
getCurrentBranch,
|
|
7
|
+
pullFromRemote,
|
|
8
|
+
pullRebaseFromRemote,
|
|
9
|
+
resolveTargetDir
|
|
10
|
+
} from '../git.js';
|
|
11
|
+
import {
|
|
12
|
+
printSection,
|
|
13
|
+
printTargetDir,
|
|
14
|
+
printGitMissing,
|
|
15
|
+
printErrorBox,
|
|
16
|
+
printFooter
|
|
17
|
+
} from '../ui.js';
|
|
18
|
+
|
|
19
|
+
export async function runPullCommand(remote = 'origin', branch, options = {}) {
|
|
20
|
+
const fromMenu = options.fromMenu === true;
|
|
21
|
+
|
|
22
|
+
if (!checkGitInstalled()) {
|
|
23
|
+
printGitMissing();
|
|
24
|
+
if (fromMenu) return;
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let targetDir = process.cwd();
|
|
29
|
+
if (options.dir) {
|
|
30
|
+
const r = resolveTargetDir(options.dir, process.cwd());
|
|
31
|
+
if (!r.ok) {
|
|
32
|
+
printErrorBox('THƯ MỤC KHÔNG HỢP LỆ', [r.error]);
|
|
33
|
+
if (fromMenu) return;
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
targetDir = r.fullPath;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!branch) branch = getCurrentBranch(targetDir);
|
|
40
|
+
|
|
41
|
+
if (!isGitRepo(targetDir)) {
|
|
42
|
+
printErrorBox('CHƯA PHẢI GIT REPOSITORY', [`Thư mục '${targetDir}' chưa phải Git repository.`]);
|
|
43
|
+
if (fromMenu) return;
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!branch) {
|
|
48
|
+
printErrorBox('KHÔNG XÁC ĐỊNH ĐƯỢC BRANCH', ['Đang ở detached HEAD nên không biết pull branch nào.'], 'Checkout về branch chính rồi chạy lại.');
|
|
49
|
+
if (fromMenu) return;
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const isInteractive = !options.yes;
|
|
54
|
+
try {
|
|
55
|
+
printSection(`PULL --ff-only ${remote}/${branch}`);
|
|
56
|
+
printTargetDir(targetDir);
|
|
57
|
+
const result = pullFromRemote(remote, branch, targetDir);
|
|
58
|
+
console.log(chalk.hex('#34D399')(` [OK] ${result || 'Repository đã cập nhật mới nhất (fast-forward).'}\n`));
|
|
59
|
+
if (!fromMenu) printFooter();
|
|
60
|
+
} catch (error) {
|
|
61
|
+
printErrorBox('PULL THẤT BẠI', [String(error.message).split('\n')[0]], 'Fast-forward thất bại khi lịch sử bị lệch. Có thể thử pull --rebase.');
|
|
62
|
+
if (!isInteractive) {
|
|
63
|
+
if (fromMenu) return;
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const choice = await select({
|
|
68
|
+
message: 'Pull fast-forward thất bại. Bạn muốn làm gì tiếp?',
|
|
69
|
+
choices: [
|
|
70
|
+
{ name: '» Thử kéo về bằng pull --rebase', value: 'rebase', description: `git pull --rebase ${remote} ${branch}` },
|
|
71
|
+
{ name: '« Quay lại', value: 'back', description: 'Về màn hình trước' },
|
|
72
|
+
{ name: 'x Thoát', value: 'exit', description: 'Không làm gì thêm' }
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (choice === 'rebase') {
|
|
77
|
+
try {
|
|
78
|
+
console.log(chalk.hex('#38BDF8')(`\n » Đang chạy: git pull --rebase ${remote} ${branch}...`));
|
|
79
|
+
const out = pullRebaseFromRemote(remote, branch, targetDir);
|
|
80
|
+
console.log(chalk.hex('#34D399')(` [OK] Pull --rebase thành công! ${String(out).split('\n')[0].slice(0, 100)}\n`));
|
|
81
|
+
if (!fromMenu) printFooter();
|
|
82
|
+
} catch (rebaseErr) {
|
|
83
|
+
printErrorBox('PULL --REBASE THẤT BẠI', [String(rebaseErr.message).split('\n')[0]], 'Có thể bị xung đột code (conflict). Mở git status để giải quyết.');
|
|
84
|
+
if (!fromMenu) process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|