git-push-time 1.1.2 → 1.1.4

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.
@@ -1,90 +1,90 @@
1
- import chalk from 'chalk';
2
- import { selectBox } from '../prompt-helpers.js';
3
- import {
4
- checkGitInstalled,
5
- isGitRepo,
6
- getCurrentBranchStrict,
7
- pullFromRemote,
8
- resolveTargetDir
9
- } from '../git.js';
10
- import {
11
- printSection,
12
- printTargetDir,
13
- printGitMissing,
14
- printErrorBox,
15
- printFooter
16
- } from '../ui.js';
17
-
18
- export async function runPullCommand(remote = 'origin', branch, options = {}) {
19
- const fromMenu = options.fromMenu === true;
20
-
21
- if (!checkGitInstalled()) {
22
- printGitMissing();
23
- if (fromMenu) return;
24
- process.exit(1);
25
- }
26
-
27
- let targetDir = process.cwd();
28
- if (options.dir) {
29
- const r = resolveTargetDir(options.dir, process.cwd());
30
- if (!r.ok) {
31
- printErrorBox('THƯ MỤC KHÔNG HỢP LỆ', [r.error]);
32
- if (fromMenu) return;
33
- process.exit(1);
34
- }
35
- targetDir = r.fullPath;
36
- }
37
-
38
- if (!isGitRepo(targetDir)) {
39
- printErrorBox('CHƯA PHẢI GIT REPOSITORY', [`Thư mục '${targetDir}' chưa phải Git repository.`]);
40
- if (fromMenu) return;
41
- process.exit(1);
42
- }
43
-
44
- if (!branch) {
45
- branch = getCurrentBranchStrict(targetDir);
46
- }
47
-
48
- if (!branch) {
49
- 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.');
50
- if (fromMenu) return;
51
- process.exit(1);
52
- }
53
-
54
- const isInteractive = !options.yes;
55
- try {
56
- printSection(`PULL --ff-only ${remote}/${branch}`);
57
- printTargetDir(targetDir);
58
- const result = pullFromRemote(remote, branch, targetDir);
59
- console.log(chalk.hex('#34D399')(` [OK] ${result || 'Repository đã cập nhật mới nhất (fast-forward).'}\n`));
60
- if (!fromMenu) printFooter();
61
- } catch (error) {
62
- 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.');
63
- if (!isInteractive) {
64
- if (fromMenu) return;
65
- process.exit(1);
66
- }
67
-
68
- const choice = await selectBox({
69
- message: 'Pull fast-forward thất bại. Bạn muốn làm gì tiếp?',
70
- hint: `git pull --rebase ${remote} ${branch}`,
71
- choices: [
72
- { name: 'Thử kéo về bằng pull --rebase', value: 'rebase', description: `git pull --rebase ${remote} ${branch}` },
73
- { name: 'Quay lại', value: 'back', description: 'Về màn hình trước' },
74
- { name: 'x Thoát', value: 'exit', description: 'Không làm gì thêm' }
75
- ]
76
- });
77
-
78
- if (choice === 'rebase') {
79
- try {
80
- console.log(chalk.hex('#38BDF8')(`\n » Đang chạy: git pull --rebase ${remote} ${branch}...`));
81
- const out = pullFromRemote(remote, branch, targetDir, { rebase: true });
82
- console.log(chalk.hex('#34D399')(` [OK] Pull --rebase thành công! ${String(out).split('\n')[0].slice(0, 100)}\n`));
83
- if (!fromMenu) printFooter();
84
- } catch (rebaseErr) {
85
- 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.');
86
- if (!fromMenu) process.exit(1);
87
- }
88
- }
89
- }
90
- }
1
+ import chalk from 'chalk';
2
+ import { selectBox } from '../prompt-helpers.js';
3
+ import {
4
+ checkGitInstalled,
5
+ isGitRepo,
6
+ getCurrentBranchStrict,
7
+ pullFromRemote,
8
+ resolveTargetDir
9
+ } from '../git.js';
10
+ import {
11
+ printSection,
12
+ printTargetDir,
13
+ printGitMissing,
14
+ printErrorBox,
15
+ printFooter
16
+ } from '../ui.js';
17
+
18
+ export async function runPullCommand(remote = 'origin', branch, options = {}) {
19
+ const fromMenu = options.fromMenu === true;
20
+
21
+ if (!checkGitInstalled()) {
22
+ printGitMissing();
23
+ if (fromMenu) return;
24
+ process.exit(1);
25
+ }
26
+
27
+ let targetDir = process.cwd();
28
+ if (options.dir) {
29
+ const r = resolveTargetDir(options.dir, process.cwd());
30
+ if (!r.ok) {
31
+ printErrorBox('INVALID DIRECTORY', [r.error]);
32
+ if (fromMenu) return;
33
+ process.exit(1);
34
+ }
35
+ targetDir = r.fullPath;
36
+ }
37
+
38
+ if (!isGitRepo(targetDir)) {
39
+ printErrorBox('NOT A GIT REPOSITORY', [`'${targetDir}' is not a Git repository.`]);
40
+ if (fromMenu) return;
41
+ process.exit(1);
42
+ }
43
+
44
+ if (!branch) {
45
+ branch = getCurrentBranchStrict(targetDir);
46
+ }
47
+
48
+ if (!branch) {
49
+ printErrorBox('CANNOT DETERMINE BRANCH', ['HEAD is detached, so the branch to pull is unknown.'], 'Check out a branch and try again.');
50
+ if (fromMenu) return;
51
+ process.exit(1);
52
+ }
53
+
54
+ const isInteractive = !options.yes;
55
+ try {
56
+ printSection(`PULL --FF-ONLY ${remote}/${branch}`);
57
+ printTargetDir(targetDir);
58
+ const result = pullFromRemote(remote, branch, targetDir);
59
+ console.log(chalk.hex('#34D399')(` [OK] ${result || 'Repository is up to date (fast-forward).'}\n`));
60
+ if (!fromMenu) printFooter();
61
+ } catch (error) {
62
+ printErrorBox('PULL FAILED', [String(error.message).split('\n')[0]], 'Fast-forward failed because the histories diverged. You can try pull --rebase.');
63
+ if (!isInteractive) {
64
+ if (fromMenu) return;
65
+ process.exit(1);
66
+ }
67
+
68
+ const choice = await selectBox({
69
+ message: 'Fast-forward pull failed. What would you like to do?',
70
+ hint: `git pull --rebase ${remote} ${branch}`,
71
+ choices: [
72
+ { name: 'Try pulling with rebase', value: 'rebase', description: `git pull --rebase ${remote} ${branch}` },
73
+ { name: 'Go back', value: 'back', description: 'Return to the previous screen' },
74
+ { name: 'Exit', value: 'exit', description: 'Stop here' }
75
+ ]
76
+ });
77
+
78
+ if (choice === 'rebase') {
79
+ try {
80
+ console.log(chalk.hex('#38BDF8')(`\n » Running: git pull --rebase ${remote} ${branch}...`));
81
+ const out = pullFromRemote(remote, branch, targetDir, { rebase: true });
82
+ console.log(chalk.hex('#34D399')(` [OK] Pull --rebase succeeded. ${String(out).split('\n')[0].slice(0, 100)}\n`));
83
+ if (!fromMenu) printFooter();
84
+ } catch (rebaseErr) {
85
+ printErrorBox('PULL --REBASE FAILED', [String(rebaseErr.message).split('\n')[0]], 'There may be merge conflicts. Run git status to review them.');
86
+ if (!fromMenu) process.exit(1);
87
+ }
88
+ }
89
+ }
90
+ }