clawt 3.8.5 → 3.8.6
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/dist/index.js +8 -5
- package/docs/merge.md +1 -1
- package/docs/sync.md +1 -1
- package/package.json +1 -1
- package/src/commands/merge.ts +2 -2
- package/src/commands/sync.ts +6 -4
- package/src/constants/git.ts +1 -1
- package/src/constants/index.ts +1 -1
- package/src/utils/git-core.ts +11 -1
- package/src/utils/index.ts +1 -0
- package/tests/unit/commands/merge.test.ts +1 -1
- package/tests/unit/commands/sync.test.ts +7 -2
- package/tests/unit/constants/git.test.ts +7 -7
- package/tests/unit/utils/git.test.ts +18 -0
package/dist/index.js
CHANGED
|
@@ -796,7 +796,7 @@ var PROJECT_DEFAULT_CONFIG = deriveDefaultConfig2(PROJECT_CONFIG_DEFINITIONS);
|
|
|
796
796
|
var PROJECT_CONFIG_DESCRIPTIONS = deriveConfigDescriptions2(PROJECT_CONFIG_DEFINITIONS);
|
|
797
797
|
|
|
798
798
|
// src/constants/git.ts
|
|
799
|
-
var
|
|
799
|
+
var AUTO_SAVE_COMMIT_MESSAGE_PREFIX = "clawt: auto-save before merging";
|
|
800
800
|
var EXEC_MAX_BUFFER = 200 * 1024 * 1024;
|
|
801
801
|
|
|
802
802
|
// src/constants/logger.ts
|
|
@@ -1290,6 +1290,9 @@ function gitAddFiles(files, cwd) {
|
|
|
1290
1290
|
function gitMergeContinue(cwd) {
|
|
1291
1291
|
execCommand("GIT_EDITOR=true git merge --continue", { cwd });
|
|
1292
1292
|
}
|
|
1293
|
+
function buildAutoSaveCommitMessage(mainBranch, branch) {
|
|
1294
|
+
return `${AUTO_SAVE_COMMIT_MESSAGE_PREFIX} ${mainBranch} into ${branch}`;
|
|
1295
|
+
}
|
|
1293
1296
|
|
|
1294
1297
|
// src/utils/git-branch.ts
|
|
1295
1298
|
function checkBranchExists(branchName, cwd) {
|
|
@@ -4812,9 +4815,9 @@ var SYNC_RESOLVE_MESSAGES = {
|
|
|
4812
4815
|
multipleMatches: MESSAGES.SYNC_MULTIPLE_MATCHES,
|
|
4813
4816
|
noMatch: MESSAGES.SYNC_NO_MATCH
|
|
4814
4817
|
};
|
|
4815
|
-
function autoSaveChanges(worktreePath, branch) {
|
|
4818
|
+
function autoSaveChanges(worktreePath, branch, mainBranch) {
|
|
4816
4819
|
gitAddAll(worktreePath);
|
|
4817
|
-
gitCommit(
|
|
4820
|
+
gitCommit(buildAutoSaveCommitMessage(mainBranch, branch), worktreePath);
|
|
4818
4821
|
printInfo(MESSAGES.SYNC_AUTO_COMMITTED(branch));
|
|
4819
4822
|
logger.info(`\u5DF2\u81EA\u52A8\u4FDD\u5B58 ${branch} \u5206\u652F\u7684\u672A\u63D0\u4EA4\u53D8\u66F4`);
|
|
4820
4823
|
}
|
|
@@ -4833,7 +4836,7 @@ async function executeSyncForBranch(targetWorktreePath, branch) {
|
|
|
4833
4836
|
const mainWorktreePath = getGitTopLevel();
|
|
4834
4837
|
const mainBranch = getMainWorkBranch();
|
|
4835
4838
|
if (!isWorkingDirClean(targetWorktreePath)) {
|
|
4836
|
-
autoSaveChanges(targetWorktreePath, branch);
|
|
4839
|
+
autoSaveChanges(targetWorktreePath, branch, mainBranch);
|
|
4837
4840
|
}
|
|
4838
4841
|
printInfo(MESSAGES.SYNC_MERGING(branch, mainBranch));
|
|
4839
4842
|
const hasConflict = mergeMainBranch(targetWorktreePath, mainBranch);
|
|
@@ -5083,7 +5086,7 @@ function commitSquash(message, worktreePath, branchName) {
|
|
|
5083
5086
|
printSuccess(MESSAGES.MERGE_SQUASH_COMMITTED(branchName));
|
|
5084
5087
|
}
|
|
5085
5088
|
async function handleSquashIfNeeded(targetWorktreePath, mainWorktreePath, branchName, commitMessage) {
|
|
5086
|
-
if (!hasCommitWithMessage(branchName,
|
|
5089
|
+
if (!hasCommitWithMessage(branchName, AUTO_SAVE_COMMIT_MESSAGE_PREFIX, mainWorktreePath)) {
|
|
5087
5090
|
return false;
|
|
5088
5091
|
}
|
|
5089
5092
|
const shouldSquash = await confirmAction(MESSAGES.MERGE_SQUASH_PROMPT, false);
|
package/docs/merge.md
CHANGED
|
@@ -42,7 +42,7 @@ clawt merge [-m <commitMessage>]
|
|
|
42
42
|
- 提示 `主 worktree 有未提交的更改,请先处理`,退出
|
|
43
43
|
- 无更改 → 继续
|
|
44
44
|
6. **Squash 检测与执行(auto-save 临时提交压缩)**
|
|
45
|
-
- 通过 `git log HEAD..<branchName> --format=%s` 检查目标分支是否存在以 `
|
|
45
|
+
- 通过 `git log HEAD..<branchName> --format=%s` 检查目标分支是否存在以 `AUTO_SAVE_COMMIT_MESSAGE_PREFIX`(`clawt: auto-save before merging`)为前缀的 commit
|
|
46
46
|
- **不存在** → 跳过,进入步骤 7
|
|
47
47
|
- **存在** → 提示用户是否将所有提交压缩为一个:
|
|
48
48
|
```
|
package/docs/sync.md
CHANGED
|
@@ -61,7 +61,7 @@ export interface SyncResult {
|
|
|
61
61
|
|
|
62
62
|
1. **获取主 worktree 路径和主分支名**:通过 `getGitTopLevel()` 获取主 worktree 路径(后续传给 `rebuildValidateBranch`),通过项目级配置 `clawtMainWorkBranch` 获取主工作分支名(不再通过 `getCurrentBranch` 动态获取,因为在新架构下主 worktree 可能处于验证分支上)
|
|
63
63
|
2. **自动保存未提交变更**:检查目标 worktree 是否有未提交修改
|
|
64
|
-
- 有修改 → 自动执行 `git add . && git commit -m "<
|
|
64
|
+
- 有修改 → 自动执行 `git add . && git commit -m "<message>"` 保存变更(commit message 由 `buildAutoSaveCommitMessage(mainBranch, branch)` 函数动态生成,格式为 `clawt: auto-save before merging {mainBranch} into {branch}`,前缀部分由常量 `AUTO_SAVE_COMMIT_MESSAGE_PREFIX` 定义,值为 `clawt: auto-save before merging`,同时用于 merge 命令的 squash 检测)
|
|
65
65
|
- 无修改 → 跳过
|
|
66
66
|
3. **在目标 worktree 中合并主分支**:
|
|
67
67
|
```bash
|
package/package.json
CHANGED
package/src/commands/merge.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
2
|
import { logger } from '../logger/index.js';
|
|
3
3
|
import { ClawtError } from '../errors/index.js';
|
|
4
|
-
import { MESSAGES,
|
|
4
|
+
import { MESSAGES, AUTO_SAVE_COMMIT_MESSAGE_PREFIX } from '../constants/index.js';
|
|
5
5
|
import type { MergeOptions } from '../types/index.js';
|
|
6
6
|
import { PRE_CHECK_MERGE } from '../constants/index.js';
|
|
7
7
|
import {
|
|
@@ -92,7 +92,7 @@ async function handleSquashIfNeeded(
|
|
|
92
92
|
commitMessage?: string,
|
|
93
93
|
): Promise<boolean> {
|
|
94
94
|
// 检查目标分支是否存在 auto-save commit
|
|
95
|
-
if (!hasCommitWithMessage(branchName,
|
|
95
|
+
if (!hasCommitWithMessage(branchName, AUTO_SAVE_COMMIT_MESSAGE_PREFIX, mainWorktreePath)) {
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
98
|
|
package/src/commands/sync.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
2
|
import { logger } from '../logger/index.js';
|
|
3
3
|
import { ClawtError } from '../errors/index.js';
|
|
4
|
-
import { MESSAGES
|
|
4
|
+
import { MESSAGES } from '../constants/index.js';
|
|
5
5
|
import type { SyncOptions } from '../types/index.js';
|
|
6
6
|
import { PRE_CHECK_SYNC } from '../constants/index.js';
|
|
7
7
|
import {
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
getMainWorkBranch,
|
|
21
21
|
rebuildValidateBranch,
|
|
22
22
|
getValidateBranchName,
|
|
23
|
+
buildAutoSaveCommitMessage,
|
|
23
24
|
} from '../utils/index.js';
|
|
24
25
|
import type { WorktreeResolveMessages } from '../utils/index.js';
|
|
25
26
|
|
|
@@ -49,10 +50,11 @@ const SYNC_RESOLVE_MESSAGES: WorktreeResolveMessages = {
|
|
|
49
50
|
* 自动保存目标 worktree 中的未提交变更
|
|
50
51
|
* @param {string} worktreePath - 目标 worktree 路径
|
|
51
52
|
* @param {string} branch - 分支名
|
|
53
|
+
* @param {string} mainBranch - 主分支名
|
|
52
54
|
*/
|
|
53
|
-
function autoSaveChanges(worktreePath: string, branch: string): void {
|
|
55
|
+
function autoSaveChanges(worktreePath: string, branch: string, mainBranch: string): void {
|
|
54
56
|
gitAddAll(worktreePath);
|
|
55
|
-
gitCommit(
|
|
57
|
+
gitCommit(buildAutoSaveCommitMessage(mainBranch, branch), worktreePath);
|
|
56
58
|
printInfo(MESSAGES.SYNC_AUTO_COMMITTED(branch));
|
|
57
59
|
logger.info(`已自动保存 ${branch} 分支的未提交变更`);
|
|
58
60
|
}
|
|
@@ -99,7 +101,7 @@ export async function executeSyncForBranch(targetWorktreePath: string, branch: s
|
|
|
99
101
|
|
|
100
102
|
// 检查目标 worktree 是否有未提交变更,有则自动保存
|
|
101
103
|
if (!isWorkingDirClean(targetWorktreePath)) {
|
|
102
|
-
autoSaveChanges(targetWorktreePath, branch);
|
|
104
|
+
autoSaveChanges(targetWorktreePath, branch, mainBranch);
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
// 在目标 worktree 中合并主分支
|
package/src/constants/git.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** sync 自动保存的 commit message 前缀,用于检测 auto-save 提交 */
|
|
2
|
-
export const
|
|
2
|
+
export const AUTO_SAVE_COMMIT_MESSAGE_PREFIX = 'clawt: auto-save before merging';
|
|
3
3
|
|
|
4
4
|
/** execSync 最大缓冲区大小(200MB),防止大分支 diff 时触发 ENOBUFS 错误 */
|
|
5
5
|
export const EXEC_MAX_BUFFER = 200 * 1024 * 1024;
|
package/src/constants/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { EXIT_CODES } from './exitCodes.js';
|
|
|
7
7
|
export { ENABLE_BRACKETED_PASTE, DISABLE_BRACKETED_PASTE, PASTE_THRESHOLD_MS, VALID_TERMINAL_APPS, ITERM2_APP_PATH } from './terminal.js';
|
|
8
8
|
export { DEFAULT_CONFIG, CONFIG_DESCRIPTIONS, CONFIG_DEFINITIONS, APPEND_SYSTEM_PROMPT } from './config.js';
|
|
9
9
|
export { PROJECT_CONFIG_DEFINITIONS, PROJECT_DEFAULT_CONFIG, PROJECT_CONFIG_DESCRIPTIONS } from './project-config.js';
|
|
10
|
-
export {
|
|
10
|
+
export { AUTO_SAVE_COMMIT_MESSAGE_PREFIX } from './git.js';
|
|
11
11
|
export { DEBUG_LOG_PREFIX, DEBUG_TIMESTAMP_FORMAT } from './logger.js';
|
|
12
12
|
export { UPDATE_CHECK_INTERVAL_MS, NPM_REGISTRY_URL, NPM_REGISTRY_TIMEOUT_MS, PACKAGE_NAME } from './update.js';
|
|
13
13
|
export {
|
package/src/utils/git-core.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { basename } from 'node:path';
|
|
|
2
2
|
import { execSync, execFileSync } from 'node:child_process';
|
|
3
3
|
import { execCommand, execCommandWithInput } from './shell.js';
|
|
4
4
|
import { logger } from '../logger/index.js';
|
|
5
|
-
import { EXEC_MAX_BUFFER } from '../constants/git.js';
|
|
5
|
+
import { EXEC_MAX_BUFFER, AUTO_SAVE_COMMIT_MESSAGE_PREFIX } from '../constants/git.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 获取 git common dir(用于判断是否为主 worktree)
|
|
@@ -459,3 +459,13 @@ export function gitMergeContinue(cwd?: string): void {
|
|
|
459
459
|
export function gitMergeAbort(cwd?: string): void {
|
|
460
460
|
execCommand('git merge --abort', { cwd });
|
|
461
461
|
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* 生成完整的 auto-save commit message
|
|
465
|
+
* @param {string} mainBranch - 主分支名(被合并的源分支)
|
|
466
|
+
* @param {string} branch - 目标分支名(合并到的分支)
|
|
467
|
+
* @returns {string} 完整的 commit message
|
|
468
|
+
*/
|
|
469
|
+
export function buildAutoSaveCommitMessage(mainBranch: string, branch: string): string {
|
|
470
|
+
return `${AUTO_SAVE_COMMIT_MESSAGE_PREFIX} ${mainBranch} into ${branch}`;
|
|
471
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -56,6 +56,7 @@ export {
|
|
|
56
56
|
gitAddFiles,
|
|
57
57
|
gitMergeContinue,
|
|
58
58
|
gitMergeAbort,
|
|
59
|
+
buildAutoSaveCommitMessage,
|
|
59
60
|
} from './git.js';
|
|
60
61
|
export { sanitizeBranchName, generateBranchNames, validateBranchesNotExist } from './branch.js';
|
|
61
62
|
export { validateMainWorktree, validateGitInstalled, validateClaudeCodeInstalled, validateHeadExists, validateWorkingDirClean, runPreChecks } from './validation.js';
|
|
@@ -41,7 +41,7 @@ vi.mock('../../../src/constants/index.js', async (importOriginal) => {
|
|
|
41
41
|
MERGE_SUCCESS_NO_MESSAGE: (branch: string, autoPullPush: boolean) => `合并成功: ${branch}`,
|
|
42
42
|
WORKTREE_CLEANED: (branch: string) => `已清理: ${branch}`,
|
|
43
43
|
},
|
|
44
|
-
|
|
44
|
+
AUTO_SAVE_COMMIT_MESSAGE_PREFIX: 'clawt: auto-save before merging',
|
|
45
45
|
};
|
|
46
46
|
});
|
|
47
47
|
|
|
@@ -30,7 +30,7 @@ vi.mock('../../../src/constants/index.js', async (importOriginal) => {
|
|
|
30
30
|
SYNC_SUCCESS: (branch: string, mainBranch: string) => `✓ 已将 ${mainBranch} 同步到 ${branch}`,
|
|
31
31
|
SYNC_VALIDATE_BRANCH_REBUILT: (validateBranch: string) => `验证分支 ${validateBranch} 已重建`,
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
AUTO_SAVE_COMMIT_MESSAGE_PREFIX: 'clawt: auto-save before merging',
|
|
34
34
|
};
|
|
35
35
|
});
|
|
36
36
|
|
|
@@ -54,6 +54,8 @@ vi.mock('../../../src/utils/index.js', () => ({
|
|
|
54
54
|
getValidateBranchName: vi.fn((name: string) => `clawt-validate-${name}`),
|
|
55
55
|
guardMainWorkBranch: vi.fn().mockResolvedValue(undefined),
|
|
56
56
|
guardMainWorkBranchExists: vi.fn(),
|
|
57
|
+
buildAutoSaveCommitMessage: (mainBranch: string, branch: string) =>
|
|
58
|
+
`clawt: auto-save before merging ${mainBranch} into ${branch}`,
|
|
57
59
|
}));
|
|
58
60
|
|
|
59
61
|
import { registerSyncCommand } from '../../../src/commands/sync.js';
|
|
@@ -135,7 +137,10 @@ describe('handleSync', () => {
|
|
|
135
137
|
await program.parseAsync(['sync', '-b', 'feature'], { from: 'user' });
|
|
136
138
|
|
|
137
139
|
expect(mockedGitAddAll).toHaveBeenCalledWith('/path/feature');
|
|
138
|
-
expect(mockedGitCommit).toHaveBeenCalledWith(
|
|
140
|
+
expect(mockedGitCommit).toHaveBeenCalledWith(
|
|
141
|
+
'clawt: auto-save before merging main into feature',
|
|
142
|
+
'/path/feature',
|
|
143
|
+
);
|
|
139
144
|
expect(mockedGitMerge).toHaveBeenCalled();
|
|
140
145
|
});
|
|
141
146
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { AUTO_SAVE_COMMIT_MESSAGE_PREFIX } from '../../../src/constants/git.js';
|
|
3
3
|
|
|
4
|
-
describe('
|
|
5
|
-
it('
|
|
6
|
-
expect(
|
|
4
|
+
describe('AUTO_SAVE_COMMIT_MESSAGE_PREFIX', () => {
|
|
5
|
+
it('值为预期的前缀', () => {
|
|
6
|
+
expect(AUTO_SAVE_COMMIT_MESSAGE_PREFIX).toBe('clawt: auto-save before merging');
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
it('是非空字符串', () => {
|
|
10
|
-
expect(typeof
|
|
11
|
-
expect(
|
|
10
|
+
expect(typeof AUTO_SAVE_COMMIT_MESSAGE_PREFIX).toBe('string');
|
|
11
|
+
expect(AUTO_SAVE_COMMIT_MESSAGE_PREFIX.length).toBeGreaterThan(0);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it('符合 conventional commit 格式', () => {
|
|
15
|
-
expect(
|
|
15
|
+
expect(AUTO_SAVE_COMMIT_MESSAGE_PREFIX).toMatch(/^[a-z]+:\s.+$/);
|
|
16
16
|
});
|
|
17
17
|
});
|
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
gitDiffTree,
|
|
65
65
|
gitApplyCachedCheck,
|
|
66
66
|
getBranchCreatedAt,
|
|
67
|
+
buildAutoSaveCommitMessage,
|
|
67
68
|
} from '../../../src/utils/git.js';
|
|
68
69
|
|
|
69
70
|
const mockedExecCommand = vi.mocked(execCommand);
|
|
@@ -610,3 +611,20 @@ describe('getBranchCreatedAt', () => {
|
|
|
610
611
|
);
|
|
611
612
|
});
|
|
612
613
|
});
|
|
614
|
+
|
|
615
|
+
describe('buildAutoSaveCommitMessage', () => {
|
|
616
|
+
it('生成包含分支信息的完整 commit message', () => {
|
|
617
|
+
const result = buildAutoSaveCommitMessage('main', 'feature/login');
|
|
618
|
+
expect(result).toBe('clawt: auto-save before merging main into feature/login');
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it('生成的 message 以前缀常量开头', () => {
|
|
622
|
+
const result = buildAutoSaveCommitMessage('main', 'feat-xyz');
|
|
623
|
+
expect(result.startsWith('clawt: auto-save before merging')).toBe(true);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('符合 conventional commit 格式', () => {
|
|
627
|
+
const result = buildAutoSaveCommitMessage('develop', 'hotfix');
|
|
628
|
+
expect(result).toMatch(/^[a-z]+:\s.+$/);
|
|
629
|
+
});
|
|
630
|
+
});
|